I NEED HELP BAD!!!
Alright, I have a very weird texture problem.
I build up the font characters for my GL print function. Each character is a little OpenGL list. Inside the list is the quad, and the texture bound to the quad. It's nice and compiled.
Now when I print a string, everything works fine, every thing that is, except anything after the print function!
For some reason, every polygon I render after the print function has the texture of the last character, no matter what I do (glDisable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2d); glBind(MY_BLOODY_TEXTURE_THAT_IS_NOT_THE_LAST_CHARACTER);).
Also, calling glDeleteTextures on my glGenTextures list causes a SEGV at the end of the program.
I got allot of code, so I just want to ask if you guys have any ideas before I start posting it.
Quote:Original post by The_Nerd
For some reason, every polygon I render after the print function has the texture of the last character, no matter what I do (glDisable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2d); glBind(MY_BLOODY_TEXTURE_THAT_IS_NOT_THE_LAST_CHARACTER);).
Yep, we're going to need to see some code before we can determine the problem. Could be a number of things. :)
Quote:Also, calling glDeleteTextures on my glGenTextures list causes a SEGV at the end of the program.
I don't think glDeleteTextures is safe to call inside of a display list.
Quote:I got allot of code, so I just want to ask if you guys have any ideas before I start posting it.
*braces self* Alright! Make sure you only post the relevant stuff, of course. :)
Function to build a font character:
Ner3DImage::Bind() and Ner3DImage::New function:
Print function:
Misc classes:
Anything else??? Don't say I didn't warn you! :)
[Edited by - The_Nerd on November 11, 2004 12:57:25 PM]
bool make_dlist (FT_Face Face, uint16 Ch, Ner3DFont *Fnt){ static Ner3DImage *TempImage=VID_NewImage(); if (!TempImage) return false; if(FT_Load_Glyph(Face, FT_Get_Char_Index(Face, Ch), FT_LOAD_DEFAULT)) return false; //Move the face's glyph into a Glyph object. FT_Glyph Glyph; if(FT_Get_Glyph(Face->glyph, &Glyph)) return false; //Convert the glyph to a bitmap. FT_Glyph_To_Bitmap(&Glyph, FT_RENDER_MODE_NORMAL, 0, 1 ); FT_BitmapGlyph Bitmap_Glyph = (FT_BitmapGlyph)Glyph; //This reference will make accessing the bitmap easier FT_Bitmap& Bitmap=Bitmap_Glyph->bitmap; //Use our helper function to get the widths of //the bitmap data that we will need in order to create //our texture. int16 uiWidth = next_p2(Bitmap.width); int16 uiHeight = next_p2(Bitmap.rows); //Allocate memory for the texture data. GLubyte* Expanded_Data = new GLubyte[ 2 * uiWidth * uiHeight]; //Here we fill in the data for the expanded bitmap. //Notice that we are using two channel bitmap (one for //luminocity and one for alpha), but we assign //both luminocity and alpha to the value that we //find in the FreeType bitmap. //We use the ?: operator so that value which we use //will be 0 if we are in the padding zone, and whatever //is the the Freetype bitmap otherwise. for(uint16 uiJ=0;uiJ<uiHeight;uiJ++) for(uint16 uiJJ=0;uiJJ<uiWidth;uiJJ++) memset(&Expanded_Data[2*(uiJJ+uiJ*uiWidth)], (uiJJ>=Bitmap.width||uiJ>=Bitmap.rows)?0:Bitmap.buffer[uiJJ+Bitmap.width*uiJ], 2); TempImage->New(uiWidth, uiHeight, 32); memcpy(TempImage->Buffer, Expanded_Data, uiWidth*uiHeight*4); TempImage->uiFlags=NER3D_IMG_CLAMPX|NER3D_IMG_CLAMPY; TempImage->Bind(GL_RGBA, GL_LUMINANCE_ALPHA);//With the texture created, we don't need to expanded data anymore delete [] Expanded_Data; //So now we can create the display list glNewList(Fnt->uiListBase+Ch,GL_COMPILE); //glBindTexture(GL_TEXTURE_2D,Fnt->uiTextureBase[Ch]); VID_BindGLTexture(TempImage->iGLIndex); TempImage->Free(); //first we need to move over a little so that //the character has the right amount of space //between it and the one before it. glTranslatef(Bitmap_Glyph->left,0,0); //Now we move down a little in the case that the //bitmap extends past the bottom of the line //(this is only true for characters like 'g' or 'y'. glPushMatrix(); glTranslatef(0,(0-Bitmap_Glyph->top)+DEFAULT_CHAR_WIDTH,0); //n3dDebug("%c = %d/%d", Ch, Bitmap_Glyph->top, Bitmap.rows); //Now we need to account for the fact that many of //our textures are filled with empty padding space. //We figure what portion of the texture is used by //the actual character and store that information in //the x and y variables, then when we draw the //quad, we will only reference the parts of the texture //that we contain the character itself. float32 fX=(float32)Bitmap.width/(float32)uiWidth, fY=(float32)Bitmap.rows/(float32)uiHeight; //Here we draw the texturemaped quads. //The bitmap that we got from FreeType was not //oriented quite like we would like it to be, //so we need to link the texture to the quad //so that the result will be properly aligned. glBegin(GL_QUADS); glTexCoord2d(0,0); glVertex2f(0,0); glTexCoord2d(0,fY); glVertex2f(0,Bitmap.rows); glTexCoord2d(fX,fY); glVertex2f(Bitmap.width,Bitmap.rows); glTexCoord2d(fX,0); glVertex2f(Bitmap.width,0); glEnd(); glPopMatrix(); glTranslatef(Face->glyph->advance.x >> 6 ,0,0); //increment the raster position as if we were a bitmap font. //(only needed if you want to calculate text length) //glBitmap(0,0,0,0,face->glyph->advance.x >> 6,0,NULL); //Finnish the display list glEndList();}/*------------------------------------------------------------------------------------------------------------------*/
Ner3DImage::Bind() and Ner3DImage::New function:
GLuint uiGlobalTextureObject[IMG_MAX_TEXTURES];static uint16 uiCurrentBoundTexture=0, uiTotalBoundTextures=0, uiBoundTextureIndex=0;static list<Ner3DImage *> gImages;FallBackTexture FallBackTex;int16 iCurrentlyBoundTexture=-1;/*------------------------------------------------------------------------------------------------------------------*/bool Ner3DImage::Bind(GLint IFormat, GLint Format){ if (Buffer==NULL) return false; if (this->iGLIndex!=-1) { uiCurrentBoundTexture=this->iGLIndex; return true; //Already bound... just return } glBindTexture(GL_TEXTURE_2D, uiGlobalTextureObject[uiBoundTextureIndex]); uiBoundTextureIndex++; glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, (uiFlags&NER3D_IMG_CLAMPX)?GL_CLAMP:GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, (uiFlags&NER3D_IMG_CLAMPY)?GL_CLAMP:GL_REPEAT); if (uiFlags&NER3D_IMG_MIPMAPPED) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); gluBuild2DMipmaps(GL_TEXTURE_2D, IFormat, (unsigned int)uiWidth, (unsigned int)uiHeight, Format, GL_UNSIGNED_BYTE, Buffer); } else { glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, IFormat, (unsigned int)uiWidth, (unsigned int)uiHeight, 0, Format, GL_UNSIGNED_BYTE, Buffer); } iGLIndex=uiGlobalTextureObject[uiBoundTextureIndex-1]-1; uiCurrentBoundTexture=uiGlobalTextureObject[uiBoundTextureIndex-1]; uiTotalBoundTextures++;return true;}/*------------------------------------------------------------------------------------------------------------------*//*------------------------------------------------------------------------------------------------------------------*/bool Ner3DImage::New(uint16 uiWidth, uint16 uiHeight, uint16 uiBpp){ Free(); if (uiWidth>0&&uiHeight>0&&uiBpp>0) { Buffer=(RGBA_ARRAY *)realloc(Buffer, ((uiWidth*uiHeight)*uiBpp)*sizeof(RGBA_ARRAY)); if (Buffer==NULL) return false; } this->uiWidth=uiWidth; this->uiHeight=uiHeight; this->uiBpp=uiBpp;return true;}/*------------------------------------------------------------------------------------------------------------------*/
Print function:
/*------------------------------------------------------------------------------------------------------------------*/void VID_FontPrint(Ner3DFontInfo *Info, uchar8 *ucpStr){ if (Info->uiFont>=uiGFontCount) return; Ner3DFont *CurrentFont=&tpFonts[Info->uiFont]; uint16 uiI, uiII, uiTab=0, uiJ, uiLayerCount; float32 fCharWidth=(float32)DEFAULT_CHAR_SPACING*Info->Size.fX; uchar8 *ucpPt, ucpTag[128]={0}, ucpValue[128]={0}; list<Ner3DMaterialLayer *>::iterator TempItr=NULL; Ner3DImage *Char; glDisable(GL_DEPTH_TEST); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); //Info->Position.fX-=fCharWidth; glPushMatrix(); glLoadIdentity(); glTranslatef(Info->Position.fX, Info->Position.fY, 0); for (;ucpStr[0]!=0;uiTab++, ucpStr++) { if ((Info->uiFlags&FONT_FLAG_IGNORETAGS)==0) { if (ucpStr[0]=='[') { //ucpStr++; if (ucpStr[1]!='['&&ucpStr[1]!=0) { for (ucpPt=&ucpStr[1], uiII=0;ucpPt[0]!=(uchar8)' '&&ucpPt[0]!=0;uiII++, ++ucpPt) { ucpTag[uiII]=ucpPt[0]; ucpTag[uiII+1]=0; } for (uiII=0;ucpPt[0]!=']'&&ucpPt[0]!=0;uiII++, ++ucpPt) { ucpValue[uiII]=ucpPt[0]; ucpValue[uiII+1]=0; } //n3dMessage("Tag %s value %s", ucpTag, ucpValue); if (ucpPt[0]==']') { STR_SWITCH((char *)ucpTag) { STR_CASE("color") { sscanf((char *)ucpValue, "%f, %f, %f, %f", &Info->Color.fR, &Info->Color.fG, &Info->Color.fB, &Info->Color.fA); break; } STR_CASE("tabwidth") { //sscanf((char *)ucpValue, "%d, %d, %d", &ucRed, &ucGreen, &ucBlue); Info->uiTabWidth=atoi((char *)ucpValue); break; } STR_CASE("i") { //sscanf((char *)ucpValue, "%d, %d, %d", &ucRed, &ucGreen, &ucBlue); Info->uiFlags=(atoi((char *)ucpValue))?FONT_FLAG_ITALIC:0; break; } STR_CASE("size") { //sscanf((char *)ucpValue, "%d, %d, %d", &ucRed, &ucGreen, &ucBlue); Info->Size.fX=atof((char *)ucpValue); Info->Size.fY=Info->Size.fX; fCharWidth=DEFAULT_CHAR_SPACING*Info->Size.fX; glScalef(Info->Size.fX, Info->Size.fY, 1); break; } STR_CASE("sizex") { //sscanf((char *)ucpValue, "%d, %d, %d", &ucRed, &ucGreen, &ucBlue); Info->Size.fX=atof((char *)ucpValue); fCharWidth=DEFAULT_CHAR_SPACING*Info->Size.fX; glScalef(Info->Size.fX, Info->Size.fY, 1); break; } STR_CASE("sizey") { //sscanf((char *)ucpValue, "%d, %d, %d", &ucRed, &ucGreen, &ucBlue); Info->Size.fY=atof((char *)ucpValue); glScalef(Info->Size.fX, Info->Size.fY, 1); break; } STR_CASE("xpos") { //sscanf((char *)ucpValue, "%d, %d, %d", &ucRed, &ucGreen, &ucBlue); Info->Position.fX=(float32)atoi((char *)ucpValue); glTranslatef(Info->Position.fX, 0, 0); break; } STR_CASE("ypos") { //sscanf((char *)ucpValue, "%d, %d, %d", &ucRed, &ucGreen, &ucBlue); Info->Position.fY=(float32)atoi((char *)ucpValue); glTranslatef(0, Info->Position.fY, 0); break; } STR_CASE("rotate") { //sscanf((char *)ucpValue, "%d, %d, %d", &ucRed, &ucGreen, &ucBlue); Info->Rotation.fAngleZ=atof((char *)ucpValue); break; } STR_CASE("rot") { //sscanf((char *)ucpValue, "%d, %d, %d", &ucRed, &ucGreen, &ucBlue); Info->CRotation.fAngleZ=atof((char *)ucpValue); break; } STR_CASE("font") { //sscanf((char *)ucpValue, "%d, %d, %d", &ucRed, &ucGreen, &ucBlue); Info->uiFont=atoi((char *)ucpValue); if (Info->uiFont>=uiGFontCount) Info->uiFont=uiGFontCount-1; CurrentFont=&tpFonts[Info->uiFont]; break; } break; } ucpStr=ucpPt; continue; } } } } glColor4f(Info->Color.fR, Info->Color.fG, Info->Color.fB, Info->Color.fA); glCallList(CurrentFont->uiListBase+ucpStr[0]); } glPopMatrix(); glColor3ub(255, 255, 255);}/*------------------------------------------------------------------------------------------------------------------*/
Misc classes:
class Ner3DFont{ public: uint16 uiListBase;};class Ner3DFontInfo{ public: Ner3DPoint2D Position; Ner3DPoint2D Size; Ner3DNormal Rotation; Ner3DNormal CRotation; Ner3DColor Color; uint16 uiFlags, uiFont, uiTabWidth; Ner3DFontInfo() { Reset(); } void Reset(){ Position.fX=0.0; Position.fY=0.0; Size.fX=1.0; Size.fY=1.0; Rotation.fAngleZ=0.0; CRotation.fAngleZ=0.0; Color.fR=1.0; Color.fG=1.0; Color.fB=1.0; Color.fA=1.0; uiFlags=0; uiFont=0; uiTabWidth=4; }};
Anything else??? Don't say I didn't warn you! :)
[Edited by - The_Nerd on November 11, 2004 12:57:25 PM]
if you put that into a set of
[source ] [/srource] tags, you may get more willing customers.
>>For some reason, every polygon I render after the print function has the texture of the last character, no matter what I do (glDisable(GL_TEXTURE_2D);<<
did u disable ALL the texture units
did u disable ALL the texture units
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement