PDA

View Full Version : mipmapping questions???



bmcclint
08-24-2001, 08:26 AM
OK...I'm new to mip mapping and not sure what is wrong...and what method to use...

1) I have a 565 16bit texture pre-made and in a file. It has 256x256 to 8x8, basically six levels.

1a) I setup a function to adjust the RGB for each level as it goes back so I can see the mips change...

2) I have a polygon starting at the viewer extending deep into the screen so I can test the mipmapping.

3) I manually install each mip level with glTexImage2D and set the filters as so...

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);

This creates a white polygon(no texuring)...Changing the MIN filter to GL_NEAREST produces the texture but no mipmapping.

If I comment out all the manual entries and use gluBuild2DMipmaps it appears to work but I am assuming it creates the mips for me so I do not get the RGB changes...Hard to tell if it is actually mipmapping...

So...Questions...

1) I have read some where that one needs to create mipmaps all the way to 1x1. Is this true? Is this why I don't see anything when I manually define the mips to 8x8?

2) I guess I would prefer to define my maps, but is there an advantage to using gluBuild2DMipmaps?

2a) Which brings up an interesting question...How does one manage texture memory. At this point I don't have enough textures yet to be an issue but I'm sure it will arise. I had to do it manually for Glide(3DFX) but not sure about OpenGL. Is there a technique for this in GL? Is it even required? Will the GL driver load and unlaod from the card? Examples?

Basically when I gave up on mine...I went to mipmap.c from RedBook and altered it...

---The Code to install the texture---
void init(MIPTEXTURE_t *mipTexture)
{

glEnable(GL_DEPTH_TEST);
glShadeModel(GL_FLAT);

glTranslatef(0.0, 0.0, 0.0);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);

gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB5, mipTexture->width, mipTexture->height, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, mipTexture->mipdata[0].data);
// glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB5, 256, 256, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, mipTexture->mipdata[0].data);
// glTexImage2D(GL_TEXTURE_2D, 1, GL_RGB5, 128, 128, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, mipTexture->mipdata[1].data);
// glTexImage2D(GL_TEXTURE_2D, 2, GL_RGB5, 64, 64, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, mipTexture->mipdata[2].data);
// glTexImage2D(GL_TEXTURE_2D, 3, GL_RGB5, 32, 32, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, mipTexture->mipdata[3].data);
// glTexImage2D(GL_TEXTURE_2D, 4, GL_RGB5, 16, 16, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, mipTexture->mipdata[4].data);
// glTexImage2D(GL_TEXTURE_2D, 5, GL_RGB5, 8, 8, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, mipTexture->mipdata[5].data);

glMatrixMode(GL_TEXTURE);
glScalef(1.0/mipTexture->width, 1.0/mipTexture->height, 1.0);

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glEnable(GL_TEXTURE_2D);
}

Thanks...

bmcclint
08-24-2001, 11:28 AM
Got part of it...

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, GL_ZERO);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, (mipTexture->levels - 1));

Still not sure about which method is faster/better.

MarsuGL
08-24-2001, 02:25 PM
for me, mip maping works well, but i have a question too,

the texture switching makes a nasty visual effect in some cases,
the color of the texture is a little darker.
it's happens on a brick textures, when i move backwards from the wall to see the differents levels of mipmaps.
Marsu

Dodger
08-26-2001, 08:14 AM
Originally posted by MarsuGL:
the color of the texture is a little darker. it's happens on a brick textures, when i move backwards from the wall to see the differents levels of mipmaps.


Use GL_LINEAR_MIPMAP_LINEAR texture filter to get rid of this effect. Depending on the texture, it can get darker or brighter when creating mipmaps. The above filtering mode linearly interpolates between different mipmap levels, so the effect you describe should disappear.

zed
08-26-2001, 02:28 PM
it does say in the spec u must provide textures all the way down to 1x1

ffish
08-26-2001, 11:18 PM
I agree with zed (or rather, the red book does). Also, look into SGIS_generate_mipmap on nVidia hardware - it's supposed to be better for performance than gluBuildiDMipmaps.

Hope that helps.

DFrey
08-27-2001, 04:05 AM
You only have to have the complete mipmap chain for OpenGL 1.1 and below. For 1.2 and above you do not have to if you specify what the maximum mipmap level is. But for compatibilities sake, I personally would just create the 3 remaining textures in the chain and take it to 1x1.

ffish
08-27-2001, 04:30 AM
Not that I doubt you, DFrey, but I read that in the red book 3rd edition (for OpenGL 1.2). They don't mention you can get away without all the mipmaps in 1.2, although that was what I thought (just like you say) before I read it in the book.

DaViper
08-27-2001, 05:31 AM
As far as i read the spec, you have to either to specify the level of mip-mapping with GL_TEXTURE_MAX_LEVEL or you have to go down to 1x1. If you don't do it spec says it is like Texturing is disabled.

Chris

DFrey
08-27-2001, 05:34 AM
The section on mipmapping in 3.8 is kind of confusing ffish, as it says the following:


Level-of-detail numbers proceed from TEXTURE_BASE_LEVEL for the original texture array
through p = max{n, m, l} + TEXTURE_BASE_LEVEL with each unit increase
indicating an array of half the dimensions of the previous one as already
described. If texturing is enabled (and TEXTURE_MIN_FILTER is one that re-
quires a mipmap) at the time a primitive is rasterized and if the set of
arrays TEXTURE_BASE_LEVEL through q = min{p, TEXTURE_MAX_LEVEL} is incom-
plete, then it is as if texture mapping were disabled.
In the first part of that paragraph it sounds like they are suggesting that the chain is complete only if it goes to 1x1. But then later only say texture mapping is disabled when the chain is incomplete (taking TEXTURE_MAX_LEVEL into account). In a previous paragraph in a footnote they made an assumption that TEXTURE_BASE_LEVEL was 0 and TEXTURE_MAX_LEVEL was 1000. Obviously those limits would tend to include the entire chain from n X m X l to 1 X 1 X 1 and I'm wondering if that same assumption was being made at the first part of this paragraph that I have quoted. I would not think so.

[This message has been edited by DFrey (edited 08-27-2001).]

DaViper
08-27-2001, 07:35 AM
Originally posted by DFrey:

Level-of-detail numbers proceed from TEXTURE_BASE_LEVEL for the original texture array
through p = max{n, m, l} + TEXTURE_BASE_LEVEL with each unit increase
indicating an array of half the dimensions of the previous one as already
described. If texturing is enabled (and TEXTURE_MIN_FILTER is one that re-
quires a mipmap) at the time a primitive is rasterized and if the set of
arrays TEXTURE_BASE_LEVEL through q = min{p, TEXTURE_MAX_LEVEL} is incom-
plete, then it is as if texture mapping were disabled.

I think it is stated rather clearly here. You take the smaller one of either the complete chain (p) or TEXTURE_MAX_LEVEL.
Since TEXTURE_MAX_LEVEL=1000, its obvious that that you have to use the complete chain, if you are not setting another value for TEXTURE_MAX_LEVEL.

Chris



[This message has been edited by DaViper (edited 08-27-2001).]