View Full Version : glTexImage2D or gluBuild2DMipmaps?

06-29-2000, 05:55 PM
Hi All,
I just want to simply draw a .bmp image in a 2D space.
Which one should I use?
Which one will be faster in rendering?


06-29-2000, 10:26 PM
I have found if your camera and textured object are going to be stationary then glTexImage2D is faster. If however your viewport or object is going to move then you are better off to build your mipmaps.

06-30-2000, 02:03 AM
Are you sure it's 2D? If you are limiting it to 2D and will not be drawing the pic in the distance, don't worry about mipmaps for it.

06-30-2000, 06:38 AM
A rule of thumb: If you want to improve something, you have to offer something else, speed in most cases.

Mipmapping looks better that "ordinary" textures. Got it? http://www.opengl.org/discussion_boards/ubb/tongue.gif

06-30-2000, 07:08 AM
But you get no benefit from mipmaps if the image is only drawn at a fixed depth. No benefit other than a waste of memory that is.

06-30-2000, 05:07 PM
Thanks for all the advice.
I also found that glTexImage2D is faster in my 2-D application.
It seems that the image is clearer using glTexImage2D than mipmapping.

07-01-2000, 05:40 AM
Clearer huh?

It depends on what magnification-/minification-filter you are using. GL_LINEAR can look more blury that GL_NEAREST_MIPMAP_NEAREST. So that has nothing to do with it. http://www.opengl.org/discussion_boards/ubb/rolleyes.gif

07-01-2000, 05:43 AM
How to set the parameters will make the clearest image? No bluring and no zig-zag edge...

07-01-2000, 07:31 AM
Set your mipmap level to 0 for the highest resolution image. This is an unmodified version of your source texture. Using another mipmap level will give you a filtered image.

Hope this helps.

07-02-2000, 05:30 PM
I already used level 0 in glTexImage2D.
Is it that there should be no effect on how I set the filter?

07-02-2000, 06:00 PM
How about these two image?

1) using glDrawPixels http://www.cs.ust.hk/~yvonne/gl/orig.jpg
2) using gluBuild2DMipmaps http://www.cs.ust.hk/~yvonne/gl/mipmap.jpg

Any comment that I can make (2) as clear as (1) ?

[This message has been edited by pigpig (edited 07-02-2000).]

07-03-2000, 03:32 AM
I think you should try moving the camera distance from your mipmapped image see if that will make your mipmap clearer.
you may also want to build your own mipmaps instead of using the gluBuild2DMipmaps.

glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 64, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, image1);
glTexImage2D(GL_TEXTURE_2D, 3, GL_RGBA, 32, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, image2);
glTexImage2D(GL_TEXTURE_2D, 4, GL_RGBA, 16, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, image3);
glTexImage2D(GL_TEXTURE_2D, 5, GL_RGBA, 8, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, image4);

This is from the Redbook and sets the base and maximum mipmap levels to 2 and 5 respectively.

gluBuild2DMipmaps will do all this itself and i think it will also set MIN_LOD and MAX_LOD itself in a common way. Maybe this is not what you need.

so try the above code and you can set MIN_LOD and MAX_LOD with

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, 2.5); // change val 2.5
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 4.5); // change val 4.5

Its hard to go in-depth discussion about why this is happening, do you have the RedBook? read it as it will definately help. There is an online version you can read Im assuming it is as Addison Wesleys web site.

Having another look at your two images it seems that you may have lost color depth somwhere in your conversion. Check that your bit format stays as it is meant to be. Sorry if thats confusing but the first image looks like it may be 24bit and the second only 16bit.

[This message has been edited by dans (edited 07-03-2000).]

07-03-2000, 04:10 AM
Have you tried glTexImage2D using GL_NEAREST for minification and magnification? Without using any mipmap levels (other than 0). That should be just about equivalent to glDrawPixels. It will look ugly if drawn some distance away however.

07-03-2000, 05:17 PM
I don't have the Redbook...
Would you mind telling me the URL of the online edition?
Also, I have set both to GL_RGB, both 3 components...
The depth I have set for them is the same:
gluPerspective(45.0f, 1.0f, 3.0f, 7.0f);
as my drawing is only 2D.

07-05-2000, 06:56 AM

Serge K
07-05-2000, 09:45 PM
It is obvious that image #2 has 16bit color resolution.

In gluBuild2DMipmaps( target, components, ... ) the number of "components" is used not only for resampling, but also for glTexImage2D.

If you use glTexImage with internal_format without explicit precision ( ==1..4,GL_RGB,GL_RGBA,etc..), the driver is free to use any precision.
Many 3D cards use 16bit for 3 & 4 components (or GL_RGB & GL_RGBA).

You may try GLU 1.3 - it allows "internalformat" in gluBuild?DMipmaps (same as glTexImage) instead of "components".

or forget about gluBuild2DMipmaps, and use glTexImage2D(, GL_RGB8, ..).

07-06-2000, 11:23 PM
I succeed by doing this:

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);