Hi everyone,
I’m an SDL newbie and pretty much a graphics programming newbiw
altogether.
what’s the fastest way to place pixels on a surface that isn’t the
screen surface? The put_pixel function in the doc’s is pretty slow and
cumbersome if you’re going to be placing 40,000 more pixels in one run.
I’ve been trying something along this line:
?
Uint32 *p = (Uint32 )surface->pixels;
Uint32 color = SDL_MapRGB(/stuff/);
int x, y, width=surface->w;
int offset = x * y?+ width;
?
for(i=0; i<a_bunch_of_pixels; i++)
{
??? p[offset]? = some_color;
??? // go on to alter the values of x and y
??? offset = xy+width;
}
If you really want speed, you should remove the multiply from the inner
loop.
You’ll probably instead want to do something like this, breaking out the
x and y:
int y_offset = 0;
for ( y = 0 ; y < image.height ; x++)
{
for ( x = 0 ; x < image.width ; x++)
{
// process pixel x,y
image[ y_offset + x ] = theNewPixelColor;
}
y_offset += image.width; // rather than (y_offset = y * image.width)
}
So instead of a multiply and an add for every pixel, you instead are
doing an add per pixel and another add per row… this ends up being
hella faster than the alternate.
I have a lot of stuff I’ve explained out with relations to 2-d engines
at this site:
http://www.cis.rit.edu/~jerry/Software/demo/
It’s not focused at SDL, but rather, It’s about basic graphics concepts
and effects.
In my paint program, 4p
http://www.cis.rit.edu/~jerry/Software/4p
I actually do the case that you’re talking about (from a non-sdl surface
to a sdl surface).
Look in the file “src/jsui/gfx_base.c”, you’ll see this process in
there. (warning: i haven’t cleaned up the source or commented it very
well yet… sorry about that.)
Also, if you look in “src/jsui/page.c”, in the function
"Page_Blit_Image", there is sample code there
that blits between two non-SDL surfaces, possibly different sizes, etc…
Hope this helps!
-jOn Sunday, October 21, 2001, at 02:30 AM, Chip Collier wrote:
–
Scott “Jerry” Lawrence
@Scott_Jerry_Lawrence
For all of your Cheese Weasel needs… http://www.cheeseweasel.com