View Full Version : Displaying Image Files using Texture mapping

06-01-2008, 04:51 AM
I am trying to display image files seamlessly and without any effects. I am using code from this OpenGL Tutorial (http://www.astahost.com/info.php/programming-glut-lesson-5_t14196.html).
The image comes in two pieces (Two Triangles) one triangle fills and another starts to fill the rest of the slot. I have images which I need to display them one after another quickly without distraction.
Anyone has any ideas what should I change in this code?
Thanks in advance.

06-01-2008, 02:37 PM
So, what is your problem?

06-02-2008, 05:52 AM
Sorry not to be more descriptive.
I am displaying images every 100msec (10 frame/sec) and when each image is loading it comes in two triangles instead of coming in one quad shape and it is sort of slow and distracting. Which part of the code should I move to Init section? How can I get rid of this effect in
This Sample Tutorial (http://www.astahost.com/info.php/programming-glut-lesson-5_t14196.html) ?

06-02-2008, 05:58 AM
You can try double buffering.
Replace GLUT_SINGLE with GLUT_DOUBLE as argument to glutInitDisplayMode and replace glFlush() with glutSwapBuffers() in the display function.

06-02-2008, 06:12 AM
Thanks Nico you are a star! It worked ..
One more question: there are some black images which I don't want to display do you know how I can check if an image is black?

06-02-2008, 06:24 AM
Maybe, you can generate mipmaps for all pictures and check if the last mipmap level is a black pixel. If your pictures dimension are not power of two, you can render the picture in a power of two texture using a fbo and then generate mipmap...
I don't know if it is a good solution, it is just a suggestion.

Notice that you will need bilinear filtering to make it work with this method.

06-02-2008, 07:14 AM
The Image Dimensions are 320x240. How should I check the mipmap level is a black pixel? Any recommended tutorials?
Thanks for the Reply.

06-02-2008, 04:36 PM
http://www.sdltutorials.com if you get it to work please let me know as i am having compile problems

06-03-2008, 02:34 AM
I have never tried myself that, but what I suggest you is to load your images in texture rectangle since your pictures are rectangles. You can do that with the extension GL_ARB_texture_rectangle.
But you can't generate mipmap levels with a texture rectangle since mipmaping divide texture size by 2 until a one pixel sized texture.
So what you can do is to use framebuffer object to render this texture to another which size is a power of 2 (you will need another extension: GL_EXT_framebuffer_object). And finally you can generate mipmaps, render it on the framebuffer which size is 1x1 and call the glReadPixels function to read pixel on the screen. I know it is a very long shot and I assume there some libraries more specialized on this kind of computations...

You can find more information here:

tutorial on rendering to texture with fbo: