Hello,
I am trying to render text with FreeType and also render Textured .Obj files.
I can get both of these things working in isolation, but when I try to render both text and textured .obj’s, all I see is the text (correct) and an all white background, no textured object at all.
This is my text rendering code:
static void renderinfoline1(int string1, int string2, int string3 ){
glPushAttrib(GL_ALL_ATTRIB_BITS);
if(time <=0)
return;
glColor3f(1,0.75,0.75);
string textstring;
std::stringstream ss;
textstring.append("String 1: ");
ss << string1;
textstring.append(ss.str());
textstring.append(" String2: ");
ss.str("");
ss << string2;
textstring.append(ss.str());
textstring.append(" String3: ");
ss.str("");
ss.clear();
ss << string3;
textstring.append(ss.str());
float x = -1 - charwidth;
float y = 0.95; //-0.75
ss << time;
string text = textstring;//ss.str();
int currcharnum = 0;
int currrow;
for ( int n = 0; n < text.size(); n++ )
{
FT_Load_Char(face, text[n], FT_LOAD_RENDER);
currcharnum++;
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
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);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glEnable (GL_TEXTURE_2D);
glTexImage2D( GL_TEXTURE_2D,
0,
GL_RGB,
face->glyph->bitmap.width,
face->glyph->bitmap.rows,
0,
GL_LUMINANCE,
GL_UNSIGNED_BYTE,
face->glyph->bitmap.buffer
);
x+=charwidth;
glBegin(GL_QUADS);
glTexCoord2i(0, 1); glVertex2f(x, y);
glTexCoord2i(1, 1); glVertex2f(x+charwidth, y);
glTexCoord2i(1, 0); glVertex2f(x+charwidth, y+charheight);
glTexCoord2i(0, 0); glVertex2f(x, y+charheight);
glEnd();
glDisable(GL_TEXTURE_2D);
}
glPopAttrib();
}
And this is my Obj rendering code:
pMesh = &g_model.getMesh(i);
pMaterial = pMesh->pMaterial;
pVertices = g_model.getVertexBuffer();
// pMaterial = &g_model.m_materials[2];
// Render mesh.
//glGenTextures(1, &m_texname);
//glBindTexture(GL_TEXTURE_2D, m_texname);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, pMaterial->ambient);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pMaterial->diffuse);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, pMaterial->specular);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, pMaterial->shininess * 128.0f);
glDisable(GL_BLEND);
glDisable(GL_LIGHTING);
bool g_enableTextures = true;
if (g_enableTextures)
{
iter = g_model.g_modelTextures.find("C:\\Torque\\PhoenixEngine(P155)\\PhoenixEngine(P155-MS1)\\PhoenixEngine(P155-MS1)\\Debug\\brick.bmp");
if (iter == g_model.g_modelTextures.end())
{
glDisable(GL_TEXTURE_2D);
}
else
{
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, iter->second);
}
}
else
{
glDisable(GL_TEXTURE_2D);
}
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
if (g_model.hasPositions())
{
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, g_model.getVertexSize(),
g_model.getVertexBuffer()->position);
}
if (g_model.hasTextureCoords())
{
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, g_model.getVertexSize(),
g_model.getVertexBuffer()->texCoord);
}
if (g_model.hasNormals())
{
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, g_model.getVertexSize(),
g_model.getVertexBuffer()->normal);
}
glDrawElements(GL_TRIANGLES, (pMesh->triangleCount * 3), GL_UNSIGNED_INT, g_model.getIndexBuffer() + pMesh->startIndex);
if (g_model.hasNormals())
glDisableClientState(GL_NORMAL_ARRAY);
if (g_model.hasTextureCoords())
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
if (g_model.hasPositions())
glDisableClientState(GL_VERTEX_ARRAY);
I suspect that it is something to do with the state being changed for the text rendering, and not properly changed back?
Thanks for any advice!