Advertisement

Building textures

Started by September 28, 2003 12:11 PM
9 comments, last by Ruudje 21 years, 5 months ago
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, texture->width, texture->height, GL_RGB, GL_UNSIGNED_BYTE, texture->data); glTexImage2D(GL_TEXTURE_2D, 0, 3, texture->width, texture->height, 0, GL_RGB, GL_UNSIGNED_BYTE, texture->data); The first line, with the mipmaps, works good, but when I use the 2nd way, I dont get to see a texture... why on earth not??
If the images sizes aren''t powers of 2 the second won''t work...
Advertisement
You need to have textures be of width and height of 2^n. This is 4, 8, 16, 32, 64, 128...

gluBuild2DMipmaps does the exact same thing as glTexImage2D except first it rescales the image to fit the size requirements. This adds to the overhead of loading.

If your worried about loading time use glTexImage2D and make sure your images follow the 2^n rule. If not use gluBuild2DMipmaps. I use gluBuild2DMipmaps and make sure my images are 2^n, so if i wana quickly try a texture i can.

For future refrence http://msdn.microsoft.com/ is a great place for a explination of ogl functions.
quote:
Original post by skow
gluBuild2DMipmaps does the exact same thing as glTexImage2D except first it rescales the image to fit the size requirements. This adds to the overhead of loading.


There''s another important difference other than that gluBuild2DMipmaps rescales the image. It will also build a full set of mipmaps and upload those, while glTexImage2D won''t (assuming automatic mipmap generation is off). This is an important difference since the default minification filter requires a full set of mipmaps in order to make it a valid texture. So if you use glTexImage2D instead, without manually uploading a full mipmap set, you must also make sure you set the minification filter to a non-mipmap filter. If it''s not the power of two thing, this is generally the problem instead.
Is this the way that Nehe mentioned to get around the square texture limitation?
Marathon Redux: MY mega project.http://marathonredux.forerunners.org
There are also extentions NV_* and ATI_* arn''t good to use if hope to have your software usable on a wide range of video cards.

Those extentions can use non 2^n textures, I really haven''t worked with them, just reguritating what I''ve heard/
Advertisement
Im not using extentions, and the texture is 128x128
In that case, post some more of your code.

bool CModel::CreateTexture(void){        #ifdef opengl                // Texture creation is currently making                // mipmaps. This can be altered                glEnable(GL_TEXTURE_2D);                glGenTextures(1, &tex[0]);                glBindTexture(GL_TEXTURE_2D, tex[0]);                glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);                glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);                // Mipmapping                gluBuild2DMipmaps(GL_TEXTURE_2D, 3, texture->width, texture->height, GL_RGB, GL_UNSIGNED_BYTE, texture->data);                // Done with the texture data                delete [] texture->data;                texture->data = NULL;                delete texture;                texture = NULL;        #endif        #ifdef directx                // Directx not implemented        #endif                return true;} 
If you''re simply replacing glBuild2DMipmaps with glTexImage2D (as in your first post), then it won''t work. See my reply above for a hint on why it''s not working.

This topic is closed to new replies.

Advertisement