Why doesnt this work??? bitmap fonts

Recommended Posts

3dnewbie    100
I'm desperately trying to but a xy coordinate with a bitmapped font in the very sector i draw, but i get nothing at all.. i tested it out before outside of the loop, and it works, although i'm not sure what coordinate system i should use.
GLfloat angle,a,s,d;

GLvoid display(void)
{
GLfloat x,y;

/* Clear color and depth buffer [specified in init()] */
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

/* Reset MODELVIEW and PROJECTION matrices */
glMatrixMode(GL_MODELVIEW);

/* Initialization mode. Here we 	maintain our grid. */
glTranslatef(0.0,0.0,-6.0);
/* This will rotate local coordinate system!*/
//for(a=0.0;a<95.0;a+=1.1)
glRotatef(a,1.0f,0.0f,0.0f);
glRotatef(s,0.0f,1.0f,0.0f);
glRotatef(d,0.0f,0.0f,1.0f);

glMatrixMode(GL_PROJECTION);

/* Setup our main grid. We use QUADS and POINTS to
define the sectors. The QUADS are using blending. */

for(x=-10.0;x<GRID_SIZE;x+=SECTOR_SIZE) {
glColor4f(1.0,1.0,1.0,0.0);
renderbitmapfont(x,y,0,GLUT_BITMAP_TIMES_ROMAN_10,"TEST");
glColor4f(0.0,0.0,0.1,1.0);
for(y=-10.0;y<GRID_SIZE;y+=SECTOR_SIZE) {
glVertex3f(x-SECTOR_SIZE,y,0);
glVertex3f(x,y,0);
glVertex3f(x-SECTOR_SIZE,y-SECTOR_SIZE,0);
glVertex3f(x,y-SECTOR_SIZE,0);
glVertex3f(x-SECTOR_SIZE,y,0);
glVertex3f(x-SECTOR_SIZE,y-SECTOR_SIZE,0);
glVertex3f(x,y,0);
glVertex3f(x,y-SECTOR_SIZE,0);
}
glColor4f(1.0,1.0,1.0,0.0);
renderbitmapfont(x,y,0,GLUT_BITMAP_TIMES_ROMAN_10,"TEST");
}
glEnd();

glColor4f(0.5,0.0,0.0,1.0);
glBegin(GL_LINES);

for(x=-10.0;x<GRID_SIZE;x+=SECTOR_SIZE) {
for(y=-10.0;y<GRID_SIZE;y+=SECTOR_SIZE) {
glVertex3f(x-SECTOR_SIZE,y,0);
glVertex3f(x,y,0);
glVertex3f(x-SECTOR_SIZE,y-SECTOR_SIZE,0);
glVertex3f(x,y-SECTOR_SIZE,0);
glVertex3f(x-SECTOR_SIZE,y,0);
glVertex3f(x-SECTOR_SIZE,y-SECTOR_SIZE,0);
glVertex3f(x,y,0);
glVertex3f(x,y-SECTOR_SIZE,0);
}
}
glEnd();

glFlush();
glutSwapBuffers();
}

the bitmap function is :
void renderbitmapfont(GLint x,GLint y,GLint z,void *font,char *string)
{
char *c;

/* Set position of text */
glRasterPos3f(x,y,z);

for (c=string;*c!='\0';c++) {
glutBitmapCharacter(font, *c);
}

}


Share on other sites
Dave Hunt    4872
	for(x=-10.0;x<GRID_SIZE;x+=SECTOR_SIZE) {	glColor4f(1.0,1.0,1.0,0.0);	renderbitmapfont(x,y,0,GLUT_BITMAP_TIMES_ROMAN_10,"TEST");	glColor4f(0.0,0.0,0.1,1.0);		for(y=-10.0;y<GRID_SIZE;y+=SECTOR_SIZE) {

You are using y outside of the the loop in which it is set. I'm not sure what you really intended, so I can't tell you exactly how to fix it, but you definitely don't want to be referencing y outside of the for-loop that sets it.