Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Display text in window

  1. #1
    Newbie Newbie
    Join Date
    Dec 2013
    Posts
    1

    Display text in window

    I have this openGL code below using glut. I need to be able to display the x,y,z labels on my 3 dimensional graph. I posted some of the code just so you can run it if you wanted to try something. Let me know if anyone has any suggestions. I have tried a good bit of things but text never shows up.

    below is my main and display function:


    Code :
    int main(int argc, char** argv)
    {
    	int k;
     
    	create_linear_grids();
    	for(k=0; k<total_points;k++)
    	{
    		create_grid_z(k);
    	}
     
    	glutInit(&argc,argv);
    	glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH);
    	glutInitWindowSize(640,480);
    	glutInitWindowPosition(100,100);
    	glutCreateWindow("Oil Plot");
     
     
    	glutDisplayFunc(display);
    	glutReshapeFunc(reshape);
    	glutMouseFunc(Mouse);
    	glutMotionFunc(Motion);
     
    	Init();
     
    	glutMainLoop();
    }



    Code :
    void display()
    {
    	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    	glLoadIdentity();
    	glTranslatef(-5,0,-zoom); 
    	glTranslatef(tx,ty,0);
    	glRotatef(rotx,1,0,0);
    	glRotatef(roty,0,1,0);		
     
    	glBegin(GL_LINES);
     
    	glColor3f(0.0f, 1.0f, 0.0f);
    	for(int i=0; i<=segments; i++)
    	{
    		glVertex3f(i,0,0);
    		glVertex3f(i,0,segments);
    		glVertex3f(0,0,i);
    		glVertex3f(segments,0,i);
     
    		glVertex3f(0,i,0);
    		glVertex3f(0,i,segments);
    		glVertex3f(0,0,i);
    		glVertex3f(0,segments,i);
     
    		glVertex3f(i,0,0);
    		glVertex3f(i,segments,0);
    		glVertex3f(0,i,0);
    		glVertex3f(segments,i,0);		
    	}
    	glEnd();
     
    	glBegin(GL_QUADS);
    		glColor3f(0.0f, 1.0f, 1.0f);
    		glVertex3f(grid_x[0]/10,2,grid_y[0]/10);
    		glVertex3f(grid_x[1]/10,2,grid_y[1]/10);
    		glVertex3f(grid_x[7]/10,2,grid_y[7]/10);
    		glVertex3f(grid_x[6]/10,2,grid_y[6]/10);
    	glEnd();
     
    	glBegin(GL_QUADS);
    		glColor3f(0.0f, 1.0f, 1.0f);
    		glVertex3f(grid_x[1]/10,2,grid_y[1]/10);
    		glVertex3f(grid_x[2]/10,2,grid_y[2]/10);
    		glVertex3f(grid_x[8]/10,2,grid_y[8]/10);
    		glVertex3f(grid_x[7]/10,2,grid_y[7]/10);
    	glEnd();
     
    	glBegin(GL_QUADS);
    		glColor3f(0.0f, 1.0f, 1.0f);
    		glVertex3f(grid_x[6]/10, 2,grid_y[6]/10);
    		glVertex3f(grid_x[7]/10,2,grid_y[7]/10);
    		glVertex3f(grid_x[13]/10,3,grid_y[13]/10);
    		glVertex3f(grid_x[12]/10,3,grid_y[12]/10);
    	glEnd();
     
    	glBegin(GL_QUADS);
    		glColor3f(0.0f, 1.0f, 1.0f);
    		glVertex3f(grid_x[7]/10,2,grid_y[7]/10);
    		glVertex3f(grid_x[8]/10,2,grid_y[8]/10);
    		glVertex3f(grid_x[14]/10,3,grid_y[14]/10);
    		glVertex3f(grid_x[13]/10,3,grid_y[13]/10);
    	glEnd();
     
    	glutSwapBuffers();
    }

    Thanks in advance!

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,097
    Have a look at http://www.freetype.org/

  3. #3
    Junior Member Regular Contributor
    Join Date
    Apr 2012
    Posts
    164
    Quote Originally Posted by mrmodest View Post
    I have this openGL code below using glut. I need to be able to display the x,y,z labels on my 3 dimensional graph. I posted some of the code just so you can run it if you wanted to try something. Let me know if anyone has any suggestions. I have tried a good bit of things but text never shows up.
    Look at -

    http://openglut.sourceforge.net/group__bitmapfont.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •