I have a problem with text, everytime i try it, it always goes to the last object on the screen
how do i get it so it just stays in the bottom left corner of the screen, and if i decide to change the color, every thing else changes to that color.
To solve your color problem, you need to set the color to black after you draw,ie.
void Draw()
{
glColor3f(1,0,0); // Set color to red
// ... Draw ... // Draw your stuff
glColor3f(0,0,0); // Set color to black
}
As for your text, are you using 3D or 2D text?
void Draw()
{
glColor3f(1,0,0); // Set color to red
// ... Draw ... // Draw your stuff
glColor3f(0,0,0); // Set color to black
}
As for your text, are you using 3D or 2D text?
OpenGL is a statemachine. Every state you set ( like a colour ) sticks until you set it to something else.
If at first you don't succeed, redefine success.
i just want 2d text, like your health or something on the bottom left of your screen, and thatnks, that color thing worked
Just glTranslate to the position you want to draw the text, before you draw it. You'll probably want to push a new matrix and clear it too. How are you drawing your text?
If at first you don't succeed, redefine success.
GLvoid BuildFont(GLvoid) // Build Our Bitmap Font
{
HFONT font; // Windows Font ID
HFONT oldfont; // Used For Good House Keeping
base = glGenLists(96);
font = CreateFont( -24, // Height Of Font ( NEW )
0, // Width Of Font
0, // Angle Of Escapement
0, // Orientation Angle
FW_BOLD, // Font Weight
FALSE, // Italic
FALSE, // Underline
FALSE, // Strikeout
ANSI_CHARSET, // Character Set Identifier
OUT_TT_PRECIS, // Output Precision
CLIP_DEFAULT_PRECIS, // Clipping Precision
ANTIALIASED_QUALITY, // Output Quality
FF_DONTCARE|DEFAULT_PITCH, // Family And Pitch
"Courier New"); // Font Name
oldfont = (HFONT)SelectObject(hDC, font); // Selects The Font We Want
wglUseFontBitmaps(hDC, 32, 96, base); // Builds 96 Characters Starting At Character 32
SelectObject(hDC, oldfont); // Selects The Font We Want
DeleteObject(font); // Delete The Font
}
GLvoid print(const char *fmt, GLfloat tx, GLfloat ty, ...) // Custom GL "Print" Routine
{
glRasterPos2f(tx,ty);
char text[256]; // Holds Our String
va_list ap; // Pointer To List Of Arguments
if (fmt == NULL) // If There's No Text
return; // Do Nothing
va_start(ap, fmt); // Parses The String For Variables
vsprintf(text, fmt, ap); // And Converts Symbols To Actual Numbers
va_end(ap); // Results Are Stored In Text
glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits ( NEW )
glListBase(base - 32); // Sets The Base Character to 32 ( NEW )
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); // Draws The Display List Text ( NEW )
glPopAttrib(); // Pops The Display List Bits ( NEW )
}
this is how i did it
{
HFONT font; // Windows Font ID
HFONT oldfont; // Used For Good House Keeping
base = glGenLists(96);
font = CreateFont( -24, // Height Of Font ( NEW )
0, // Width Of Font
0, // Angle Of Escapement
0, // Orientation Angle
FW_BOLD, // Font Weight
FALSE, // Italic
FALSE, // Underline
FALSE, // Strikeout
ANSI_CHARSET, // Character Set Identifier
OUT_TT_PRECIS, // Output Precision
CLIP_DEFAULT_PRECIS, // Clipping Precision
ANTIALIASED_QUALITY, // Output Quality
FF_DONTCARE|DEFAULT_PITCH, // Family And Pitch
"Courier New"); // Font Name
oldfont = (HFONT)SelectObject(hDC, font); // Selects The Font We Want
wglUseFontBitmaps(hDC, 32, 96, base); // Builds 96 Characters Starting At Character 32
SelectObject(hDC, oldfont); // Selects The Font We Want
DeleteObject(font); // Delete The Font
}
GLvoid print(const char *fmt, GLfloat tx, GLfloat ty, ...) // Custom GL "Print" Routine
{
glRasterPos2f(tx,ty);
char text[256]; // Holds Our String
va_list ap; // Pointer To List Of Arguments
if (fmt == NULL) // If There's No Text
return; // Do Nothing
va_start(ap, fmt); // Parses The String For Variables
vsprintf(text, fmt, ap); // And Converts Symbols To Actual Numbers
va_end(ap); // Results Are Stored In Text
glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits ( NEW )
glListBase(base - 32); // Sets The Base Character to 32 ( NEW )
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); // Draws The Display List Text ( NEW )
glPopAttrib(); // Pops The Display List Bits ( NEW )
}
this is how i did it
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement