[SDL] faster putpixel

Adam Gates adam at preston.net
Sun Feb 17 18:31:01 PST 2002


How about using this kind of an idea:

As an example here is a function which draws a vertical line:
( This code is untested but should show the general idea. )

void DrawVertLine(surface* s, int x, int y, int length, int color)
{
	while(length--)
	{
		int* pixel = s->pixel + y * s->pitch + x;
		*pixel = color;
		++y;
	]
}

A small improvement would be:

void DrawVertLine(surface* s, int x, int y, int length, int color)
{
	int* pixel = s->pixel + y * s->pitch + x;
	while(length--)
	{
		*pixel = color;
		pixel += s->pitch;
	}
}

The general idea is to use relative movement of a pixel cursor rather
than reverting back to the multiplication.

Christopher Thielen wrote:
> 
> Hello,
>         I found the putpixel() function in the SDL documentation and I've been
> using it to render a simple radar. putpixel() is remarkably slow and
> it's not noticeable yet (since the radar only draws five or six pixels
> right now), but in the future it could be much more than that. Does
> anyone have a recommendation for a faster way to draw pixels onto a
> surface?
> --
> - Chris
> Epiar Administrator/Programmer
> http://epiar.sourceforge.net/



More information about the SDL mailing list