The ‘pixels’ value in the SDL_Surface struct is of type void*, which is
what it’s complaining about. When you have something of type void*, it
means that you want it to point to some piece of data, only you don’t
know in advance what kind of data that is. C/C++ need to know the size
of the data it’s pointing to, so when you do operations like addition on
the pointer (such as what you have in your code), the program can add
the correct amount of bytes to the pointer. The reason it is used in
SDL here is because your surfaces can have many formats, for example
RGB, RGBA, or indexed, etc. All of these are different data of
different sizes.
Generally what you want is when you add 1 to the pixels pointer, you
would be at the next pixel (as opposed to a different color component in
the same pixel). So if you have 8bpp indexed data, you would typecast it
to Uint8*. Or if you had 8bpp RGBA data (32 bits total), you would
typecast it to Uint32*. Though you can just add up the bytes yourself,
which is what it looks like you’re trying to do. One way you could do
this is convert ‘pixels’ to type Uint8* (single byte pointer), and then
add in your x coordinate times the BytesPerPixel (not BitsPerPixel,
which bpp usually means). For example:
((Uint8 *)datasurf->pixels + datasurf->format->BytesPerPixel * fromx);
I’m not sure if this would get what you want, since it’s tough to tell
what you’re trying to do exactly from your code snippet. However, (I
think) it would get rid of your compilation error, so you could mess
with it to get what you want from there. Note also that you should lock
the surface (SDL_LockSurface) before accessing the ‘pixels’ data. (Or is
that only for writing operations? Anyone know?) And one last thing, if
you decide to add a ‘y’ coordinate to access your pixels, make sure you
take into account the pitch value in the Surface struct.
Well, I hope you were able to make some sense of this and hopefully fix
your program. If anyone notices any errors, please correct me!
-MikeOn Thu, 2003-06-26 at 13:08, Florian Hufsky wrote:
hi!
i tried to compile glSDL with MSVC++ 6, but i get these two errors:
in line 1702 and 1727: (datasurf->pixels + bpp * fromx); )
void * unknown size
could someone help me?
also: the author should mention to include #define inline __inline, when using MSVC++…
thanks in advance, florian hufsky