Archived

This topic is now archived and is closed to further replies.

greger

OpenGL Text in openGl

Recommended Posts

I''m still doing a 2D editor, and I''m trying to display text. I''ve tried this in a small test program, and it worked. But I can''t decide where the text should be displayed. In this program I try to display text where the mouse is clicked(tx, ty). Nothing happens. In the test program I couldn''t change color, always white, wherever I put the glColor3f. Here''s the two functions for the output of text. R,G,B are 0,0,0 default: void Print_Text(int tx, int ty){ cout << "x=" << tx << endl; cout << "y=" << ty << endl; void* font[1] = { GLUT_BITMAP_9_BY_15 }; char* number[1] = { "HEJ VICTOR" }; glColor3f(R,G,B); glRasterPos2f(tx,ty); print_bitmap_string(font[font_index],number[font_index]); } void print_bitmap_string(void* font, char* s) { if (s && strlen(s)) { while (*s) { glutBitmapCharacter(font, *s); s++; } } } Any help would be appreciated. /greger

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
This is what I use, and it works fine....


void DisplayString(float x, float y, float r, float g, float b, float a, char *str)
{
glColor4f(r,g,b,a);
glRasterPos2f(x,y);
while (*str)
glutBitmapCharacter(GLUT_BITMAP_8_BY_13,*str++);
//You can use whatever BITMAP you want, and Alpha Blending even works properly
}


I also do this to set it up as 2d (ScreenW, and ScreenH are the screens resolution, which I pull from my Reshape(width,height) function). This makes it so you can know the exact space you are putting the text on the screen. 0,0 = top left.

void Set2Dview(void)
{
glViewport(0,0,ScreenW,ScreenH);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, ScreenW, ScreenH, 0, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Oh yeah, if you need anything...

BillyB@mrsnj.com

Billy

Share this post


Link to post
Share on other sites