Results 1 to 3 of 3

Thread: Trying to print text after I have finished drawing a cube...

  1. #1
    Guest

    Trying to print text after I have finished drawing a cube...

    All right i'm trying to figure out what I'm doing wrong. I took one of nehe's tutorials and want to see if i could add a fps counter. The fps counter works in another simple opengl app i wrote, so i know the fps routines are right.
    The simple app i wrote had glPushMatrix and popmatrix, etc.
    This one however is using glBegin and glEnd. Anway without confusing my self anymore and confusing you guys here is a sample of my code.
    Code :
    glEnable(GL_TEXTURE_2D);
    	glBindTexture(GL_TEXTURE_2D, texture[filter]);
     
    	glBegin(GL_QUADS);
    		// Front Face
    		glNormal3f( 0.0f, 0.0f, 1.0f);
    		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);
    		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);
    		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);
    		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);
    		// Back Face
    		glNormal3f( 0.0f, 0.0f,-1.0f);
    		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
    		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);
    		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);
    		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
    		// Top Face
    		glNormal3f( 0.0f, 1.0f, 0.0f);
    		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);
    		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  1.0f);
    		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  1.0f);
    		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);
    		// Bottom Face
    		glNormal3f( 0.0f,-1.0f, 0.0f);
    		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
    		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
    		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);
    		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);
    		// Right face
    		glNormal3f( 1.0f, 0.0f, 0.0f);
    		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
    		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);
    		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);
    		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);
    		// Left Face
    		glNormal3f(-1.0f, 0.0f, 0.0f);
    		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
    		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);
    		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);
    		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);
    	glEnd();
     
    	//-----print fps on screen--------
    	glDisable(GL_TEXTURE_2D);
    	glLoadIdentity();
    	glColor3f(1.0, 1.0, 1.0);		
    	glRasterPos2f(-0.5, -0.5);							// Position The Text On The Screen
     	glNormal3f( 0.0f, 0.0f, 1.0f);
     	glPrint("%1.2f fps", t); //passes to glPrint function
    Portions of the code come from many different other programs. I'm just learning here.

    I could email the code if you need more details to see what i'm doing wrong. I'm assuming i'm messing up with the matrix mode and the re-sets.
    Any help would be great.

    Cheers

  2. #2
    Guest

    Re: Trying to print text after I have finished drawing a cube...

    Oops never mind, i know what i did wrong, i forgot to add buildfont(); in the initgl() function.

    Just another quick question. Can the pro's check this part of the code and see if i'm doing anything wrong please?

    Code :
    GLvoid InitGL(GLvoid)
    {
     
    	LoadGLTextures();							// Load The Texture(s) ( NEW )
    	//glEnable(GL_TEXTURE_2D);					// Enable Texture Mapping ( NEW )
     
    	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);		// This Will Clear The Background Color To Black
    	glClearDepth(1.0);							// Enables Clearing Of The Depth Buffer
    	glDepthFunc(GL_LESS);						// The Type Of Depth Test To Do
    	glEnable(GL_DEPTH_TEST);					// Enables Depth Testing 
    	glShadeModel(GL_SMOOTH);					// Enables Smooth Color Shading
     
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();							// Reset The Projection Matrix
     
    	gluPerspective(45.0f, (GLfloat) kWindowWidth / (GLfloat) kWindowHeight, 0.1f, 100.0f);	
     
     
    												// Calculate The Aspect Ratio Of The Window
     
    	glMatrixMode(GL_MODELVIEW);
     
    	glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
    	glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);
    	glLightfv(GL_LIGHT1, GL_POSITION, LightPosition);
     
    	glEnable(GL_LIGHT1);
     
    	glBlendFunc(GL_SRC_ALPHA, GL_ONE);			// Set The Blending Function For Translucency
    	glColor4f(1.0f, 1.0f, 1.0f, 0.5);
    	//-------font--------
    	glDisable(GL_TEXTURE_2D);
    	glLoadIdentity();
     
    	glMatrixMode(GL_MODELVIEW);
     
    	BuildFont();
    	glLoadIdentity();
    	//---font----
    }
    Am i using being redundant with glLoadIdentity and glmatrixMode?

    Thanks

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: Trying to print text after I have finished drawing a cube...

    Yeah, your last calls to glMatrixMode and glLoadIdentity are redundant... other than that I don't see anything wrong with your code. Once you set the matrix mode, it will stay in that mode until you change it with another call to glMatrixMode. If you do glLoadIdentity, that matrix will stay as the identity matrix until you call something that will change it, (ie. glLoadMatrix, glMultMatrix, glRotate, glScale, glRotate, glTranslate, glFrustum, glOrtho, gluPerspective, gluOrtho2D)
    Deiussum
    Software Engineer and OpenGL enthusiast

Similar Threads

  1. how to print text in GLES
    By dungdm in forum OpenGL ES
    Replies: 2
    Last Post: 01-22-2008, 02:40 AM
  2. drawing text on a face of a cube
    By presoftdev in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 09-30-2005, 12:15 PM
  3. how to print text using glutBitmapCharacter() on SGI-Irix
    By saurabh_shrivastava in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 05-11-2003, 11:53 PM
  4. how to print a text in a specified portion of a screen
    By jowins in forum OpenGL: Advanced Coding
    Replies: 9
    Last Post: 01-14-2003, 12:49 AM
  5. Drawing text on a cube
    By Libby in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 05-06-2002, 05:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean