PDA

View Full Version : need help with gluBuild2DMipmaps...



Lexx
04-21-2005, 02:11 PM
Platform: Win32
Environment: C++ Builder 6

i use gluBuild2DMipmaps function to load textures.
And in some cases (using some textures) i've got "floating point division by zero" exception (in that function). can anybody help me?
//----------
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, w, h, GL_RGB, GL_UNSIGNED_BYTE, data);
//----------
And when I use 4 as second parameter and GL_RGBA as 5th - it works! what is wrong?

PIXELFORMATDESCRIPTOR was defined as:

PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | DOUBLEBUFFER,
PFD_TYPE_RGBA,
24,
0,0,0,0,0,0,
0,0,
0,0,0,0,0,
32,
0,
0,
PFD_MAIN_PLANE,
0,
0,0,
};

uruk
04-21-2005, 08:21 PM
Maybe because the image stored in "data" is RGBA not RGB?

Lexx
04-21-2005, 09:18 PM
no, that is the problem - it's in RGB format!
using GL_RGBA there are no access violations!
but GL_RGB doesn't work! :(

so if i use:

unsigned char data[24];
for(int i = 0; i < 24; i += 3)
{
data[i] = red;
data[i+1] = green;
data[i+2] = blue;
}

it fails too...

uruk
04-21-2005, 11:06 PM
That's strange... Maybe it's some data alignment problem...
Try using GL_SGIS_generate_mipmap extension instead of gluBuild2DMipmaps...

V-man
04-23-2005, 02:11 PM
This call is wrong

gluBuild2DMipmaps(GL_TEXTURE_2D, 3, w, h, GL_RGB, GL_UNSIGNED_BYTE, data);

The second parameter should be the internal format in modern GL. You can put GL_RGB8 for example.

If you have an access violation, it's probably because your data uses an alignment of 1. GL's default is 4.
Call glPixelStorei(GL_UNPACK_ALIGNMENT, 1)

Hope that helps

Lexx
04-24-2005, 02:34 AM
Thanks!
I've already rewritten all gluBuild2DMipmaps calls to GL_RGBA parameter. But in future i'll use your advice.