Mipmapping in OpenGL.

Started by
3 comments, last by Esap1 23 years, 9 months ago
I want to use Mip-Mapping in my OpenGL App. Do I use glTexImage2D()? If I do, how do I use it. Could someone show me a simple example of building Mip-Maps in Code. Thanks alot PS: A demo is comming soon
Advertisement
Hi,

You can do it in two ways:

1) You create your mipmaps yourself, then you set your texture filters appropriately(GL_NEAREST_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR or GL_LINEAR_MIPMAP_LINEAR), and then call one glTexImage2D for each mipmap, with the appropriate level (0 for the normal image, 1 for the next mipmap, and so on).
like this:

    glBindTexture(GL_TEXTURE_2D, Tex);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, Image);MakeMipmap(Image);glTexImage2D(GL_TEXTURE_2D, 1, GL_RGB, width/2, height/2, 0, GL_RGB, GL_UNSIGNED_BYTE, Image);// and so on 



But don't forget that you must indicate ALL the mipmap's sizes, otherwise it will act as if GL_TEXTURE_2D is disabled.


2) You can let GLU create the mipmaps for you. Just call gluBuild2DMipMaps:

glBindTexture(GL_TEXTURE_2D, Tex);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, width, height, GL_RGB, GL_UNSIGNED_BYTE, Image); 



Hope that helps,

Nicodemus.

----
"When everything goes well, something will go wrong." - Murphy


Edited by - Nicodemus on July 16, 2000 12:39:13 AM
Nicodemus.----"When everything goes well, something will go wrong." - Murphy
I have it using Mip-Mapping but I have a question. Its VERY Apparent where each Mip-map is in use(Theres like three Lines). Doesnt Tri-linear Mip-Mapping cover this up, by blending the MipMaps togather. Is there a way to use TriLinear MipMapping, or is there another way to cover up the lines between each MipMap Level?

Edited by - Esap1 on July 17, 2000 1:38:06 AM
Screw up your eyes so that everything goes blurry
GL_LINEAR_MIPMAP_LINEAR is what you want for tri-linear mip mapping. I think what you have is GL_LINEAR_MIPMAP_NEAREST

-K

This topic is closed to new replies.

Advertisement