Advertisement

Font works, but polygons don't

Started by June 13, 2002 10:32 PM
4 comments, last by Erunama 22 years, 8 months ago
I am working on the NeHeGL II basecode, but I am having a little problem. I am attempting to display a square, and then write text to the screen. The text shows up, but the square does not. Here is my drawing code:
  
void Draw (void)
{
	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);		// Clear Screen And Depth Buffer

	glLoadIdentity();									// Reset The View

	
	glTranslatef(0.0f,0.0f,-6.0f);
	glRotatef(angle,0.0f,1.0f,0.0f);
    glColor3f(1.0f,1.0f,1.0f);
	glBegin(GL_QUADS);
		glVertex3f(-1.0f,-1.0f,0.0f);
		glVertex3f(-1.0f,1.0f,0.0f);
		glVertex3f(1.0f,1.0f,0.0f);
        glVertex3f(1.0f,-1.0f,0.0f);
	glEnd();

	glLoadIdentity();
	glColor3f(0.0f,0.3f,1.0f);
	fEru.SetBase(32);											// Adjust Base Start Pos (First Set of Fonts)

	fEru.Print(20,30,"Dan Carroll Presents:");			// Print GL Text To The Screen

	glColor3f(1.0f,1.0f,0.0f);
	fEru.SetBase(32 - 128);									// Adjust Base Start Pos (Second Set of Fonts)

	fEru.Print(20,50,"Eru3D Test");			// Print GL Text To The Screen

	glColor3f(1.0f,1.0f,1.0f);
	fEru.SetBase(32);
	fEru.Print(20,70,"FPS: %5.1f",frames);

	glFlush ();													// Flush The GL Rendering Pipeline

}
  
And the font print code:
  
GLvoid GLFont::Print(GLint x, GLint y, char *string, ...)	// Where The Printing Happens

{
	char	text[256];
	va_list	ap;

	if(string == NULL)
		return;

	va_start(ap, string);
		vsprintf(text, string, ap);
	va_end(ap);

	glBindTexture(GL_TEXTURE_2D, fTexture[0]);			// Select Our Font Texture

	glDisable(GL_DEPTH_TEST);							// Disables Depth Testing

	glMatrixMode(GL_PROJECTION);						// Select The Projection Matrix

	glPushMatrix();										// Store The Projection Matrix

	glLoadIdentity();									// Reset The Projection Matrix

	glOrtho(0,fdWidth,0,fdHeight,-1,1);							// Set Up An Ortho Screen

	glMatrixMode(GL_MODELVIEW);							// Select The Modelview Matrix

	glPushMatrix();										// Store The Modelview Matrix

	glLoadIdentity();									// Reset The Modelview Matrix

	glTranslated(x,fdHeight - y,0);								// Position The Text (0,0 - Bottom Left)

	glListBase(fBase - fStartPos);						// Choose The Font Set (0 or 1)

	glCallLists(strlen(text),GL_BYTE, text);			// Write The Text To The Screen

	glMatrixMode(GL_PROJECTION);						// Select The Projection Matrix

	glPopMatrix();										// Restore The Old Projection Matrix

	glMatrixMode(GL_MODELVIEW);							// Select The Modelview Matrix

	glPopMatrix();										// Restore The Old Projection Matrix

	glEnable(GL_DEPTH_TEST);							// Enables Depth Testing

}
  
Any ideas on what the problem is? If you want more code, just ask. And I did try moving the square code after the font code, but it still didn''t work.
You could try throwing:
glDisable(GL_CULL_FACE);
before the square drawing code.
Aside from that, I don''t really see what could be causing the problem.

------------
aud.vze.com - The Audacious Engine <-- It''s not much, yet. But it''s mine... my own... my preciousssss...
MSN: nmaster42@hotmail.com, AIM: LockePick42, ICQ: 74128155
_______________________________________Pixelante Game Studios - Fowl Language
Advertisement
Hmmm, this is really weird. I tried what you said, and it still does not work. I even commented out the text drawing code and still, no square. I''ll try a few more things, but if anyone has some suggestions, they would be appreciated.
Try to disable texturing

Try to disable lighting
Thanks vincoof! I disabled texturing and the square appeared. Now, what should I do to display both text and polygons (the font is texture mapped from a bitmap image, like Lesson 17, I believe). Should I disable GL_TEXTURE_2D, draw everything that is not textured, then enable it and draw all of the textured stuff (like text)?
Yes, only have texturing enabled when drawing items that have textures. Otherwise the untextured things will use the last texture and texture coordinates you have set.


Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions

This topic is closed to new replies.

Advertisement