Archived

This topic is now archived and is closed to further replies.

Dunge

glTexImage2D Unhandled exception

Recommended Posts

I''m trying to modify the CFont class from the "OpenGL Game Programming" book to load .bmp texture with font (like the NeHe tutorial 17 doing this) and I tough it would get it working when it compilled, but now I get an Unhandled exception.. VC++.net don''t tell me where it happen (say no source code available for current location) but by putting breakpoints I found it stop at the glTexImage2D line.. Here is a bit of code
  
void CGUI::SetupFontTex()
{
	fontTex->LoadTexture("font.bmp");
	glGenTextures(1, &fontTex->texID);
	glBindTexture(GL_TEXTURE_2D, fontTex->texID);

	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_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
	glTexImage2D(GL_TEXTURE_2D, 0, 4, fontTex->width, fontTex->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, fontTex->data);
	gluBuild2DMipmaps(GL_TEXTURE_2D, 4, fontTex->width, fontTex->height, GL_RGBA, GL_UNSIGNED_BYTE, fontTex->data);
	font->SetTex(fontTex->texID);
}
  
yes, fontTex->width contain the bitmap width (256) same with fontTex->height, fontTex->texID (contain 1), and fontTex->data contain some data.. what could be a cause of Unhandled exception in this code?

Share this post


Link to post
Share on other sites
I presume your LoadTexture() function is creating an alpha channel for the bitmap, and then creating/adding it to the data buffer.

If not, your asking GL and then GLU to try and read in a buffer with GL_RGBA which would be reading passed your data buffer which is only RGB

Share this post


Link to post
Share on other sites
You really shouldn''t call gluBuild2DMipmaps after glTexImage2D, call one or the other, not both.

The crash problem is probably caused by glTexImage2D reading past the bounds of your data buffer.

Share this post


Link to post
Share on other sites
You're both right,. my BMP loading function only use RGB and I don't need both gluBuild2DMipmaps and glTexImage2D.. so I erased glTexImage2D and modified gluBuild2DMipmaps to

gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, fontTex->width, fontTex->height, GL_RGB, GL_UNSIGNED_BYTE, fontTex->data);

but it don't change anything.. can it be because my bitmap is grayscale?

EDIT: nah I tried with a 24bits one and I still get the error..

[edited by - Dunge on January 19, 2003 5:19:40 PM]

Share this post


Link to post
Share on other sites
Hum don''t know why but I tried with a 24bits bitmap from the cd of OpenGL Game Programmign and it worked... but not theses from NeHe... anyway dunno why but now it work fine

Share this post


Link to post
Share on other sites