C++ Language Error? Pixel Drawing - SDL

Started by
13 comments, last by Unidentified 20 years, 3 months ago
There another error, when in the line with *pxp = color. I guess there is something wrong with either the equation or the value I convert it to or possibly the color.
Advertisement
Uint32* pxp = (Uint32*)screen->pixels + y * screen->pitch + x * bpp;

should be

Uint32* pxp = (Uint32*)screen->pixels + y * screen->pitch + x;
I had to put

bufp = (Uint32 *)screen->pixels + y * screen->pitch/4 + x;

Which is the one from the Cone3D tutoiral. I don't get why you have to dived screen->pitch by the number of bytes per pixel The one from the SDL Doc Project didn't work which was the one I was using, it multiplied the bytes per pixel by x.



[edited by - Unidentified on January 4, 2004 6:16:57 PM]
Screen->pixels points to 0,0.
To get to the right Y coordinate you mutliply y * the number of pixels per line. screen->pitch was the number of BYTES per line. Since you were using 32 bit graphics that meant divide by 4 to get the number of pixels. Then you simply add on the x and you''re there.

Does that answer your question?
quote:Original post by stro
Screen->pixels points to 0,0.
To get to the right Y coordinate you mutliply y * the number of pixels per line. screen->pitch was the number of BYTES per line. Since you were using 32 bit graphics that meant divide by 4 to get the number of pixels. Then you simply add on the x and you''re there.

Does that answer your question?


Ok. I understand it now.

This topic is closed to new replies.

Advertisement