Jump to content
  • Advertisement
Sign in to follow this  
XY_Meng

What is the fastest way to draw an image in OpenGL?

This topic is 3148 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

What is the fastest way to draw an image in OpenGL? Use DrawPixels or use textures? I just want to draw a background image and its size is not the power of 2. I have to redraw in every frame. Now I first just draw the image in an aux buffer and then use glCopyPixels to copy it into GL_BACK. But it only works on Mac but not on Windows, and it's not that fast... In addition, if I want to save part of the rendered image and reuse it, what is the fastest way?

Share this post


Link to post
Share on other sites
Advertisement
Disclaimer: I don't actually use Open GL at all at present, but I do have my own software 3D engine.

It shouldn't matter that your texture size isn't a power of two unless you wanted to tile it. Simply draw it into a texture that is a power of two in size and use a quad covering the whole screen, where the texture coordinates of the quad only go up to the actual height and width of your image.

Share this post


Link to post
Share on other sites
Sorry, could you explain more about how to draw an image that does not have the size of power 2 to a texture that has a size of power two?

Share this post


Link to post
Share on other sites
"Drawing" means if you have a pow2 texture, you can send a smaller subimage to the texture, and you don't care about the rest of the texture (it will be black, but I'm not sure, maybe undefined?).

You can specify the texture coordinates anyway you want:
You can have s<1.0, or t<1.0 coordinates, but I say: work it out with a pen and a piece of paper (it's so easy!). (I should include that in my signature.)

Share this post


Link to post
Share on other sites
I too would go for rendering the texture onto a pow2 quad as described above, then rendering a subsection of the quad to fill the screen. This should be PLENTY fast compared to some of the scary stuff we end up doing on a multiple-passes-per-pixel basis with shaders.

Share this post


Link to post
Share on other sites
glDrawPixels is the most slowest way compared to any other way how to get image to screen using OpenGL textures.

Share this post


Link to post
Share on other sites
Quote:
From OpenGL 2.0 specification
I.3 Non-Power-Of-Two Textures
The restriction of textures to power-of-two dimensions has been relaxed for all texture targets, so that non-power-of-two textures may be specified without generating errors. Non-power-of-two textures was promoted from the ARB_texture_non_power_of_two extension.


Unless you want to support very old hardware there is no power of two restriction. Non power of two textures also don't require any extensions since OpenGL 2.0, simply create a texture as big as the backbuffer.

Share this post


Link to post
Share on other sites
Quote:
Original post by Kambiz
Quote:
From OpenGL 2.0 specification
I.3 Non-Power-Of-Two Textures
The restriction of textures to power-of-two dimensions has been relaxed for all texture targets, so that non-power-of-two textures may be specified without generating errors. Non-power-of-two textures was promoted from the ARB_texture_non_power_of_two extension.


Unless you want to support very old hardware there is no power of two restriction. Non power of two textures also don't require any extensions since OpenGL 2.0, simply create a texture as big as the backbuffer.

I'm making an educated guess here, but I suspect that a power of two sized texture would be marginally faster, considering the work required for indexing into the texture in each case. A non-power of two texture size requires an extra divide per pixel in a software renderer at least. Might not even be a measureable difference though I guess.

Share this post


Link to post
Share on other sites
Quote:
Original post by iMalc
A non-power of two texture size requires an extra divide per pixel in a software renderer at least. Might not even be a measureable difference though I guess.


Just take the inverse and it becomes a multiplication. So only one or two divs per texture.

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!