Texture mapped fonts appear as white blocks
I'm trying to track down the bug but no luck so far. My code is based off NeHe's lesson 17.
Anyone have similar problems before or know what could cause this kind of glitch?
Thanks
Hmmm maybe you might post code, that would make it easier to help you...
Make sure blending and texture are enabled.
Make sure blending and texture are enabled.
SaM3d!, a cross-platform API for 3d based on SDL and OpenGL.The trouble is that things never get better, they just stay the same, only more so. -- (Terry Pratchett, Eric)
This is where I build it...
This is where I print it...
GLvoid glApp::BuildTexFont(GLvoid){ //character coordinates GLfloat cx, cy; //generate display lists, base will point to first, base+1 second, etc. base = glGenLists(256); glBindTexture(GL_TEXTURE_2D, textures[0]); for (int i=0; i<256; i++) { cx=float(i%16)/16.0f; //x position of current character cy=float(i/16)/16.0f; //y position of current character glNewList(base+i,GL_COMPILE); glBegin(GL_QUADS); glTexCoord2f(cx,1-cy-0.0625f); //bottom left uv glVertex2i(0,0); //bottom left xy glTexCoord2f(cx+0.0625f,1-cy-0.0625f); //bottom right uv glVertex2i(16,0); //bottom right xy glTexCoord2f(cx+0.0625f,1-cy); //top right uv glVertex2i(16,16); //top right xy glTexCoord2f(cx,1-cy); //top left uv glVertex2i(0,16); //top left xy glEnd(); //move to the right of the character to avoid overdraw glTranslated(10,0,0); glEndList(); }}
This is where I print it...
GLvoid glApp::glPrintTex(GLuint x, GLuint y, int set, const char *fmt, ...){ char text[256]; va_list args; if (fmt == NULL) return; va_start(args, fmt); vsprintf(text,fmt,args); va_end(args); if (set > 1) set=1; //SET UP ORTHO VIEW glBindTexture(GL_TEXTURE_2D, textures[0]); //select font texture glDisable(GL_DEPTH_TEST); //disable depth test glMatrixMode(GL_PROJECTION); //select projection matrix glPushMatrix(); //store it on stack glLoadIdentity(); //reset projection matrix glOrtho(0,width,0,height,-1,1); //set up ortho screen glMatrixMode(GL_MODELVIEW); //select modelview matrix glPushMatrix(); //store it on stack glLoadIdentity(); //reset modelview matrix glTranslated(x,y,0); glListBase(base-32+(128*set)); //select style (regular or italic) //RENDERING glCallLists((GLsizei)strlen(text),GL_UNSIGNED_BYTE, text); //UNDO CHANGES glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glEnable(GL_DEPTH_TEST);}
Just to be sure...
Have you enable texturing using glEnable(GL_TEXTURE_2D) ?
Chman
Have you enable texturing using glEnable(GL_TEXTURE_2D) ?
Chman
- Artist on the web -- Lwjgl Ressources & blog -
Yes. Blending is also enabled.
Also, to clarify the topic title, it's each individual character that's showing up as a separate white block.
Also, to clarify the topic title, it's each individual character that's showing up as a separate white block.
Hum that's pretty strange, because your code seems correct...
Are you sure your texture is correctly loaded ?
Else the texture ID will be 0 (0 = blank texture).
Chman
Are you sure your texture is correctly loaded ?
Else the texture ID will be 0 (0 = blank texture).
Chman
- Artist on the web -- Lwjgl Ressources & blog -
Try glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) if you havent already just before you bind the texture inside the draw func
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) didn't help.
I was looking over my texture loading code and I'm pretty sure the old way I was doing it could have been the problem. I have another rather silly problem now (look at comment in caps):
The lines just before the loop cause a "expected constant expression" error on compile. Is there another way of loading the textures that would avoid this problem?
Also, tell me if there's anything in there that could be causing my original problem (texture mapped fonts not appearing correctly).
Thanks
I was looking over my texture loading code and I'm pretty sure the old way I was doing it could have been the problem. I have another rather silly problem now (look at comment in caps):
int glApp::LoadGLTextures(unsigned char filter){ int Status=FALSE; //open the texture file FILE* texf = fopen("tex.txt","r"); if(!texf) { KillGLWindow(); MessageBox(NULL, "Can't open texture index (tex.txt).", "Error", MB_OK | MB_ICONEXCLAMATION); return FALSE; } char line[1024]; //a line in tex.txt unsigned int temp=0; //how many textures in txt.txt while (fgets(line,1024,texf)) temp++; const unsigned int size = temp; fclose(texf); texf = fopen("tex.txt","r"); if (!texf) MessageBox(0, "Error opening texture.", "Error", MB_OK | MB_ICONEXCLAMATION); textures = new unsigned int[size]; //allocate the texture array glGenTextures(size, &textures[0]); //generate texture names char tex[32]; //texture name //LINE BELOW CAUSES "EXPECTED CONSTANT EXPRESSION" ERROR AUX_RGBImageRec *TextureImage[size]; // Create Storage Space For The Textures memset(TextureImage,0,sizeof(void *)*size); // Set The Pointer To NULL unsigned int count=0; while (fgets(line,1024,texf)!=NULL) { sscanf(line,"%s",tex); if (TextureImage[count]=LoadBMP(tex)) { Status=TRUE; //bind named texture to texture target glBindTexture(GL_TEXTURE_2D, textures[count]); switch (filter) { case 0: { glTexImage2D(GL_TEXTURE_2D,0,3,TextureImage[0]->sizeX,TextureImage[0]->sizeY,0,GL_RGB,GL_UNSIGNED_BYTE,TextureImage[0]->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); break; } case 1: { glTexImage2D(GL_TEXTURE_2D,0,3,TextureImage[0]->sizeX,TextureImage[0]->sizeY,0,GL_RGB,GL_UNSIGNED_BYTE,TextureImage[0]->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); break; } case 2: { glTexImage2D(GL_TEXTURE_2D,0,3,TextureImage[0]->sizeX,TextureImage[0]->sizeY,0,GL_RGB,GL_UNSIGNED_BYTE,TextureImage[0]->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); break; } case 3: { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data); break; } } } count++; } for (unsigned int loop=0; loop<size; loop++) { if (TextureImage[loop]) // If Texture Exists { if (TextureImage[loop]->data) // If Texture Image Exists { free(TextureImage[loop]->data); // Free The Texture Image Memory } free(TextureImage[loop]); // Free The Image Structure } } return Status;}
The lines just before the loop cause a "expected constant expression" error on compile. Is there another way of loading the textures that would avoid this problem?
Also, tell me if there's anything in there that could be causing my original problem (texture mapped fonts not appearing correctly).
Thanks
A stack allocated array must have a size that can be detetmined at compile time. You should use a dynamically allocated array (using operator new[]) or, better still, use one of the standard library containers like std::vector.
As to your original problem. Usually this is the result of invalid textures. Make sure your textures are power-of-two sized and that you obtain a valid OpenGL rendering context before loading the textures. The other common cause of white textures is using mipmapping without specifying mipmaps, but your mipmap code looks fine.
Hope that helps,
Enigma
As to your original problem. Usually this is the result of invalid textures. Make sure your textures are power-of-two sized and that you obtain a valid OpenGL rendering context before loading the textures. The other common cause of white textures is using mipmapping without specifying mipmaps, but your mipmap code looks fine.
Hope that helps,
Enigma
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement