Faster putpixel

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?–

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?

Do it by hand. Touch the framebuffer directly.

–ryan.

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?

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

Everything you ever wanted to know about drawing lines in a linear framebuffer:
http://icculus.org/~icculus/abrash_black_book/gpbb35.pdf
http://icculus.org/~icculus/abrash_black_book/gpbb36.pdf
http://icculus.org/~icculus/abrash_black_book/gpbb37.pdf

…and here’s anti-aliased lines, for good measure:
http://icculus.org/~icculus/abrash_black_book/gpbb42.pdf

–ryan.

My point wasn’t about drawing lines. I was trying to demonstrate a
method of speeding up the use of putpixel by not actually using it and
instead using relative movement of the pixel “cursor”.

“Ryan C. Gordon” wrote:>

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

Everything you ever wanted to know about drawing lines in a linear framebuffer:
http://icculus.org/~icculus/abrash_black_book/gpbb35.pdf
http://icculus.org/~icculus/abrash_black_book/gpbb36.pdf
http://icculus.org/~icculus/abrash_black_book/gpbb37.pdf

…and here’s anti-aliased lines, for good measure:
http://icculus.org/~icculus/abrash_black_book/gpbb42.pdf

–ryan.

Alright, thanks Adam and Ryan, I’ll use your suggestions when I go back
and redo the radar code. Thanks again!–

On Mon, 2002-02-18 at 14:04, Adam Gates wrote:

My point wasn’t about drawing lines. I was trying to demonstrate a
method of speeding up the use of putpixel by not actually using it and
instead using relative movement of the pixel “cursor”.

“Ryan C. Gordon” wrote:

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

Everything you ever wanted to know about drawing lines in a linear framebuffer:
http://icculus.org/~icculus/abrash_black_book/gpbb35.pdf
http://icculus.org/~icculus/abrash_black_book/gpbb36.pdf
http://icculus.org/~icculus/abrash_black_book/gpbb37.pdf

…and here’s anti-aliased lines, for good measure:
http://icculus.org/~icculus/abrash_black_book/gpbb42.pdf

–ryan.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Just a thought… 1x1 Rectangles?

Then Fill em, or have a bitmap file.

-Bryan Arant> ----- Original Message -----

From: sdl-admin@libsdl.org [mailto:sdl-admin at libsdl.org]On Behalf Of
Christopher Thielen
Sent: Monday, February 18, 2002 2:42 PM
To: sdl at libsdl.org
Subject: Re: [SDL] faster putpixel

Alright, thanks Adam and Ryan, I’ll use your suggestions when I go back
and redo the radar code. Thanks again!

On Mon, 2002-02-18 at 14:04, Adam Gates wrote:

My point wasn’t about drawing lines. I was trying to demonstrate a
method of speeding up the use of putpixel by not actually using it and
instead using relative movement of the pixel “cursor”.

“Ryan C. Gordon” wrote:

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

Everything you ever wanted to know about drawing lines in a linear
framebuffer:

http://icculus.org/~icculus/abrash_black_book/gpbb35.pdf
http://icculus.org/~icculus/abrash_black_book/gpbb36.pdf
http://icculus.org/~icculus/abrash_black_book/gpbb37.pdf

…and here’s anti-aliased lines, for good measure:
http://icculus.org/~icculus/abrash_black_book/gpbb42.pdf

–ryan.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Just a thought… 1x1 Rectangles?

Then Fill em, or have a bitmap file.

Dear lord no.

If you need to touch a pixel in the framebuffer, touch the darn pixel. You
don’t need a function for it. You probably don’t even need a macro. You
are never going to accelerate single pixels on any hardware, so just touch
the framebuffer directly.

–ryan.

Well if your a retard like me, you won’t know how to do that! >:)

-Bryan Arant> ----- Original Message -----

From: sdl-admin@libsdl.org [mailto:sdl-admin at libsdl.org]On Behalf Of
Ryan C. Gordon
Sent: Monday, February 18, 2002 11:52 PM
To: sdl at libsdl.org
Subject: RE: [SDL] faster putpixel

Just a thought… 1x1 Rectangles?

Then Fill em, or have a bitmap file.

Dear lord no.

If you need to touch a pixel in the framebuffer, touch the darn pixel. You
don’t need a function for it. You probably don’t even need a macro. You
are never going to accelerate single pixels on any hardware, so just touch
the framebuffer directly.

–ryan.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

I should add that on any video card, under OpenGL using putpixels is
slow, it bypasses virtually all the benefits of hardware acceleration
just to put pixels in the frame buffer. What you should be doing is
writing a quad or two triangles and copying your image into that and
placing it where you want it. If you are trying to do text, look at the
ftgl library. But don’t try using putpixels as a replacement for
blitting. Store the image in the video cards texture memory and then you
can just copy it to the screen at will, no loading time.

However you are stuck with 256x256 and power of 2 image dimensions
unless the video card supports otherwise (non-3DFX cards support
1024x1024, Radeon/Geforce cards support 2048x2048 (16MB video memory
needed JUST for one 2048x2048 texture.)> ----- Original Message -----

From: sdl-admin@libsdl.org [mailto:sdl-admin at libsdl.org] On Behalf Of
Bryan Arant
Sent: Tuesday, February 19, 2002 12:19 AM
To: sdl at libsdl.org
Subject: RE: [SDL] faster putpixel

Well if your a retard like me, you won’t know how to do that! >:)

-Bryan Arant

-----Original Message-----
From: sdl-admin@libsdl.org [mailto:sdl-admin at libsdl.org]On Behalf Of
Ryan C. Gordon
Sent: Monday, February 18, 2002 11:52 PM
To: sdl at libsdl.org
Subject: RE: [SDL] faster putpixel

Just a thought… 1x1 Rectangles?

Then Fill em, or have a bitmap file.

Dear lord no.

If you need to touch a pixel in the framebuffer, touch the darn pixel.
You
don’t need a function for it. You probably don’t even need a macro. You
are never going to accelerate single pixels on any hardware, so just
touch
the framebuffer directly.

–ryan.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl