Hi i'm using OpenGL2 and i'm tryin to write calculated distance on the screen
this is my code:
in void display:
drawNumber(distance_1,-0.95,0.9); //distance_1 is a string with one digit number in each box
in drawNumber:
Hi i'm using OpenGL2 and i'm tryin to write calculated distance on the screen
this is my code:
in void display:
drawNumber(distance_1,-0.95,0.9); //distance_1 is a string with one digit number in each box
in drawNumber:
Can you be a bit more specific than 'does not work'? Do you see any text at all? Do you see anything at all? Are you able to draw other text correctly?
Can you show the code where you create distance_1? That will probably be the most useful thing to see since you say the drawNumber("456",-0.95,0.9); does work correctly, that suggests there's a problem with your string.
to use that you need to setup ortho etc. anyway you use opengl 2.0 and you use fixed function pipeline when you should use shaders.
void glWriteTEXT(int X,int Y, AnsiString text)
{
glPushAttrib(GL_DEPTH_TEST); // Save the current Depth test settings (Used for blending )
glDisable(GL_DEPTH_TEST); // Turn off depth testing (otherwise we get no FPS)
glMatrixMode(GL_PROJECTION); // Switch to the projection matrix
glPushMatrix(); // Save current projection matrix
glLoadIdentity();
// GetWindowRect(GetDesktopWindow(), drawRect); // Get current window size
glOrtho(0, WINDOW_WIDTH, 0, WINDOW_HEIGHT, -1, 1); // Change the projection matrix using an orthgraphic projection
glMatrixMode(GL_MODELVIEW); // Return to the modelview matrix
glPushMatrix(); // Save the current modelview matrix
glLoadIdentity();
// glColor3f(1.0, 1.0, 1.0); // Text color
glRasterPos2i(X, Y); // Position the Text
glPushAttrib(GL_LIST_BIT); // Save's the current base list
glListBase(base); // Set the base list to our character list
glCallLists(text.Length(), GL_UNSIGNED_BYTE, text.c_str()); // Display the text
glPopAttrib(); // Restore the old base list
glMatrixMode(GL_PROJECTION); //Switch to projection matrix
glPopMatrix(); // Restore the old projection matrix
glMatrixMode(GL_MODELVIEW); // Return to modelview matrix
glPopMatrix(); // Restore old modelview matrix
// glEnable(GL_TEXTURE_2D); // Turn on textures, don't want our text textured
// glEnable(GL_LIGHTING);
glPopAttrib(); // Restore depth testing
}
I know this may be hard to understand because he's writing it in a custom game engine made in his tutorials, however, I think you may find this useful as it overall explains text rendering very well:
And the second part for quality:
Just make sure to uniform as many text parameters as possible to have more control;)
WiredCat now that looks easy. No additional libs like glut needed? Thanks for the code, I'll try tomorrow.
Beware of unspecified dependencies.
AnsiString text
What is "AnsiString"? A custom class? Something from a library? Which library?
glListBase(base); // Set the base list to our character list
glCallLists(text.Length(), GL_UNSIGNED_BYTE, text.c_str()); // Display the text
What is base? Where does it's value come from? What is used to generate the display lists? Where are they generated? Does this generation have any other dependencies?
Seems to need glut, freetype etc., but I don't want dependencies. I'll try to link statically sdl_ttf now.
void BuildFont(unsigned int & Ufont)
{
HFONT font;
Ufont = glGenLists(256); // Generate enough display lists to hold
font = CreateFont(22, // height of font
0, // average character width
0, // angle of escapement
0, // base-line orientation angle
FW_BOLD, // font weight
0, // italic
0, // underline
0, // strikeout
DEFAULT_CHARSET, // character set
OUT_TT_PRECIS, // output precision
CLIP_DEFAULT_PRECIS, // clipping precision
ANTIALIASED_QUALITY, // output quality
FF_DONTCARE || DEFAULT_PITCH, // pitch and family
"Courier New"); // font
SelectObject((*dc), font); // Sets the new font as the current font in the device context
wglUseFontBitmaps((*dc), 0, 256, Ufont); // Creates a set display lists containing the bitmap fonts
}
AnsiString can be std::string
where BuildFont(base);
and where unsigned int base;
but my point was that you didnt se proper perspective projection for using glrasterpos
you should anyway use shaders, and one texture where you have all font characters, and quit using old stuff ;] ;p