PDA

View Full Version : OpenGL Draw text alongside objects



recover_relax
04-23-2013, 08:24 PM
I have this render function that is working:


void RenderFunction(void)
{
++FrameCount;

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

drawGraph();
drawAxis();

glutSwapBuffers();
glutPostRedisplay();
}

Which is rendering me a point graph. I want to be able to display a small text.


void RenderFunction(void)
{
++FrameCount;

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glLoadIdentity();
drawBitmapText("Osama Hosam's OpenGL Tutorials",200,200,0);

drawGraph();
drawAxis();

glutSwapBuffers();
glutPostRedisplay();
}

The renderFunction is called inside `glutDisplayFunc(RenderFunction);`

Any idea on this. I would like any suggestions because it is not showing anything.

UPDATE:


void drawGraph(){
glBindVertexArray(VaoId);
glEnable(GL_LINE_SMOOTH);
glLineWidth(0);
glDrawElements(GL_LINES, 48, GL_UNSIGNED_BYTE, (GLvoid*)0);
glPointSize(10);
glDrawElements(GL_POINTS, 48, GL_UNSIGNED_BYTE, (GLvoid*)0);
}

void drawAxis(){
glDisable(GL_LINE_SMOOTH);
glBindVertexArray(VaoIdAxis);
glDrawElements(GL_LINES, 4, GL_UNSIGNED_BYTE, (GLvoid*)0);
}
void drawBitmapText(char *string,float x,float y,float z)
{
char *c;
glRasterPos3f(x, y,z);
for (c=string; *c != '\0'; c++)
{
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *c);
}
}