Wiki Page Content

Differences between revisions 10 and 11
Revision 10 as of 2015-04-26 19:11:18
Size: 2158
Comment: Sorted related functions, see SGFunctions.
Revision 11 as of 2015-05-17 12:45:30
Size: 2173
Editor: urkle
Comment: corrected example
Deletions are marked like this. Additions are marked like this.
Line 43: Line 43:
int buffer[10];
SDL_RWread(rwop, buffer, sizeof(buffer), 4);
Uint32 buffer[10];
SDL_RWread(rwop, buffer, sizeof(Uint32), 10);
Line 46: Line 46:
This will read 40 bytes of data, and put it into 'buffer', which is intended to hold 32-bit integers. Each int is 4 bytes, or 32-bits. This will read 40 bytes of data, and put it into 'buffer', which is intended to hold 32-bit integers. Each Uint32 is 4 bytes, or 32-bits.
Line 51: Line 51:
long buffer[10];
SDL_RWread(rwop, buffer, sizeof(buffer), 8);
Uint64 buffer[10];
SDL_RWread(rwop, buffer, sizeof(Uint64), 10);
Line 54: Line 54:
This will read 80 bytes of data, and place them into 'buffer', which is now designed for 64-bit integers (long values). Each int (long) is 8 bytes, and we are reading 10 of them (as shown by buffer[10] when we make it). This will read 80 bytes of data, and place them into 'buffer', which is now designed for 64-bit integers (Uint64 values). Each Uint64 (long) is 8 bytes, and we are reading 10 of them (as shown by buffer[10] when we make it).

SDL_RWread

Use this function to read from a data source.

Syntax

size_t SDL_RWread(struct SDL_RWops* context,
                  void*             ptr,
                  size_t            size,
                  size_t            maxnum)

Function Parameters

context

a pointer to an SDL_RWops structure

ptr

a pointer to a buffer to read data into

size

the size of each object to read, in bytes

maxnum

the maximum number of objects to be read

Return Value

Returns the number of objects read, or 0 at error or end of file; call SDL_GetError() for more information.

Code Examples

SDL_RWops *rw = SDL_RWFromFile("test.bin","r");
if (rw != NULL) {
  extern Uint8 buf[256];
  SDL_RWread(rw, buf, sizeof (buf), 1);
  SDL_RWclose(rw);
}

Remarks

This function reads up to maxnum objects each of size size from the data source to the area pointed at by ptr. This function may read less objects than requested. It will return zero when there has been an error or the data stream is completely read.

SDL_RWread is actually a macro that calls the SDL_RWops's read method appropriately, to simplify application development.

More Examples

Uint32 buffer[10];
SDL_RWread(rwop, buffer, sizeof(Uint32), 10);

This will read 40 bytes of data, and put it into 'buffer', which is intended to hold 32-bit integers. Each Uint32 is 4 bytes, or 32-bits.

Uint64 buffer[10];
SDL_RWread(rwop, buffer, sizeof(Uint64), 10);

This will read 80 bytes of data, and place them into 'buffer', which is now designed for 64-bit integers (Uint64 values). Each Uint64 (long) is 8 bytes, and we are reading 10 of them (as shown by buffer[10] when we make it).


CategoryAPI, CategoryIO

None: SDL_RWread (last edited 2015-09-17 21:55:16 by PhilippWiesemann)

(Page Info.)
Feedback
Please include your contact information if you'd like to receive a reply.
Submit