PDA

View Full Version : Display text in window



mrmodest
12-08-2013, 01:51 PM
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:




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_DEP TH);
glutInitWindowSize(640,480);
glutInitWindowPosition(100,100);
glutCreateWindow("Oil Plot");


glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMouseFunc(Mouse);
glutMotionFunc(Motion);

Init();

glutMainLoop();
}






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!

tonyo_au
12-08-2013, 07:18 PM
Have a look at http://www.freetype.org/

Carmine
12-09-2013, 10:45 AM
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