Jump to content
  • Advertisement
Sign in to follow this  
mrlocus

OpenGL How to quickly draw just an 2d image

This topic is 3751 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I need just to draw an image generated(computed) my own way(raytracing). And I want to redraw it fast - every time user moves a slider(it changes parameters of illuminating model - illusion of realtime raytracing). The way I'm doing it now is to simply draw the pixels as points(in GL_POINTS mode) in ortho projection with the same z coord. But it is slow, for each pixel one glVertex3f call. How to do it faster? I tried to use glDrawPixels, but that was incredibly slow. Would glTexImage2D faster? But if it would, it accepts(according OpenGL ref) only power-of-two sized textures, and I need arbitrary sized images(user can resize the graphics window). There is SetDIBitsToDevice function(Win32), could this one be fast? Thanks for your help. I'm an OpenGL beginner, please respect it in your asnwers.

Share this post


Link to post
Share on other sites
Advertisement
One thing is not clear to me : is your image already stored in a bitmap, or do you output each pixel from your raytracing ? In the first case, the fastest way is to render a single quad filling your window and textured with your bitmap. POwer-of-2 textures are no more mandatory from openGL 2.0 on. if you still need them, increase your texture dimensions to the nearest power of 2 and use only the usefull part by playing with the texture coordinates.
In the second case, you could write your pixel data (color) straight to the array used by the glTexImage2D command and proceed as above.

Remember GPU's are optimized for one thing : render as many polygons as possible in the shortest time, so always prefer rendering polygons to another solution (when it's possible)

Share this post


Link to post
Share on other sites
Quote:
One thing is not clear to me : is your image already stored in a bitmap, or do you output each pixel from your raytracing ?


Well, it actually doesn't matter if I process each pixel immediately or if I store them in a bitmap.

What concerns OpenGL 2, I'm not sure how it is supported in older graphics cards(for example, at this computer I'm running GeForce MX 440 ;-) ), but the trick with increasing dimensions is fine.

YanPL:
And vertex arrays may be also good, it does what I need exactly - get rid of many calls of glVertex3f.


Thank you guys!

Share this post


Link to post
Share on other sites
Quote:
Original post by mrlocus
Quote:
One thing is not clear to me : is your image already stored in a bitmap, or do you output each pixel from your raytracing ?


Well, it actually doesn't matter if I process each pixel immediately or if I store them in a bitmap.

I assume Farfadet means whether each pixel is transferred by its own to OpenGL, or else is transferred in a bulk (i.e. a bitmap with more than 1x1 pixel). Bulk transfers have a better benefit-to-cost ratio, since the (more or less same) overhead is used to transfer more pixels.

Quote:
Original post by mrlocus
What concerns OpenGL 2, I'm not sure how it is supported in older graphics cards(for example, at this computer I'm running GeForce MX 440 ;-) ), but the trick with increasing dimensions is fine.

Long before OpenGL 2, there is an extension to support non-power-of-2 textures: GL_ARB_texture_rectangle or GL_EXT_texture_rectangle, resp. However, they may suffer from the fact not being power-of-2 sized in the one or other way.

Share this post


Link to post
Share on other sites
Hi,
I solved it finally.

First I tried the vertex arrays, but the speed didn't change at all.

Now I draw a big Quad and set its texture. The speed increased in a big way, my old method(glVertex3f for each pixel) took about 60ms, now it takes 15ms!

As I have a very old card in my home comp(Riva TNT2! ;) ), I couldn't debug my program using an extension there, for example Riva doesn't have *_texture_rectangle extension. Hopefully, glTexSubImage2D accepts non-power-of-2 sizes. And, furthermore, it is faster than glTexImage2D.

So I first create a bigger power-of-2 texture (glTexImage2D), "render"(evaluate my equations) into part of it and set that useful part to the quad by glTexSubImage2D.

Similar topic is covered in Nehe's 35th tutorial - playing AVI video in OpenGl.

Thank you!

Share this post


Link to post
Share on other sites
just use a power of 2 sized image eg 2048x2048 + only update the top 1280x720 (or whatever) part of the texture
with glTexSubImage2d( .... );
if done this before with a raytracer, the benifits of doing this instead of drawpixels, maybe faster but more importantly u can draw to a small image eg 320x240 + then display it fullscreen with some semi-nice bilinear filtering

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!