Skip to main content
GameDev.net gamedev.net
🔒 Locked

glDrawPixels

Started by bigwiger Mar 18, 2005 at 8:54 PM 4 replies 2.1k views
Original Post
bigwiger
bigwiger
Does anyone else find that the glDrawPixels function is slow? I've got no depth testing, 16-Bit resolution, 800x600 and I'm displaying three relatively small images and it still runs at like 1 fps, it's rediculous. Is there anyway to speed the method up or any other methods that display a 2D image that our faster?
Disgruntled designers are always the best ones
kaysik
kaysik
OpenGL isn't not meant to give access to the frame buffer - drawing pixles like that is will definatly be a really bad idea. What you want todo is create an openGL texture, then render a textured quad to the screen. Drawing the pixles yourself isn't something OpenGL was setup for - its a 3D graphics lib, if you want to muck round with the actual pixles yourself try something like Allegro.
pammatt
pammatt
Yes, glDrawPixels is slow, but it shouldn't be that slow. I've had to use glDrawPixels for some specific needs and was able to get satisfactory performance when having to draw the entire screen at 1280x1024 resolution. What are your images sizes and how many calls to draw pixels are you doing?

Make sure you don't have zooming enabled, and that the format of the framebuffer matches the format of the images so no conversions are required.

If you can, post your setup/drawing code and some more details.
bigwiger
bigwiger
Quote:
Original post by pammatt
Make sure you don't have zooming enabled, and that the format of the framebuffer matches the format of the images so no conversions are required.


Unless zooming is enabled automatically, it shouldn't be enabled for me. How do I know my framebuffer format?

Quote:
Original post by pammattIf you can, post your setup/drawing code and some more details.


Besides basic windows stuff, this is my openGL setup:

glClearColor(0.0, 0.0, 0.0, 0.0);
//glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

And here's my drawing method:

//Displays the image
void G_Image::displayImage(int x,int y)
{
if(!hasImage)
return;

glRasterPos2i(x,y);
if(hasAlpha)
glDrawPixels(i_width,i_height,GL_BGRA,GL_UNSIGNED_SHORT_5_5_5_1,imageData);
else
glDrawPixels(i_width,i_height,GL_BGR,GL_UNSIGNED_SHORT_5_6_5,imageData);
}

Nothing too outrageous here it would seem to me
Disgruntled designers are always the best ones
pammatt
pammatt
Whats the width and height of what you are drawing, and how many times are you calling the draw method. (You said three, but what is the change in performance if you increase or decrease that number). If you are making many calls to glDrawPixels and only drawing a small area, you are going to see performance hit bottom. Each call incurs a great deal of setup cost. For example, it would take longer to drawpixels and area of 300x300 pixels if you drew it using 4 calls to drawpixels vs. one call.

Couple other quick notes. Check out glPixelTransfer. And, if you feel like it, (I'm kinda curious) try a 32-bit framebuffer with 32-bit alpha images and 24-bit non-alpha images.

I see you have blending enabled. Disable it and see what happens. If in fact you need this behavior, check out glAlphaTest, or better yet really, use the texturing and quad method as the other post suggested.
bigwiger
bigwiger
Thanks all y'all for your help. I still don't know why it was slow. Probably because it was truning my 16-bit information into 32-bit, which I just found out a little while ago. Anyway - I decided to just display them as quads, and it is much, MUCH faster.
Disgruntled designers are always the best ones

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.