at the moment i am trying to learn opengl and have build quite a few functions, but I have come across a bit of an annoying problem, Im trying to move text horizontally by trying to increase x value by 1(first approach) within the drawText function, then I tried looping, eg:
for (; x< 100; x++) {
drawText(x, y, other value, string);
}
but here is the code sniped of drawText:
void drawText(int x, int y, int space, char *s) {
char *e;
//set font
void *f = GLUT_BITMAP_TIMES_ROMAN_24;
// inisilize matrix mode and ortho2D coord
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0.0, GLUT_WINDOW_WIDTH, 0.0, GLUT_WINDOW_HEIGHT);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
//set colour to values set to 2d array colors
glColor3f(colors[colorFrame][0], colors[colorFrame][1], colors[colorFrame][2]);
//set text position to x and y values to x, y arguments
glRasterPos2i(x, y);
int xpos = x;
for (e = s; *e != '\0'; e++)
{
glutBitmapCharacter(f, *e);
xpos = xpos + glutBitmapWidth(f, *e) + space;
}
std::string count = std::to_string(xpos);
printf("%s
", count.c_str());
// return matrix to previous state
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
}
at the moment, I am still a newby, so please if you see anything wrong, do let me know.
any suggestions?