quick Q about text in Ortho mode
I''m developing some gui classes & I can''t get any text to show up in ortho mode. I''m using the glprint() from from one of Nehe''s lessons & it just doesn''t work in ortho mode. Any tips?
Whatsoever you do, do it heartily as to the Lord, and not unto men.
alright... lemme update my question... the "text" isn''t blank anymore... I see colored squares where the text should be... the color is the color that I set it to before I draw the text... any clues ???
Whatsoever you do, do it heartily as to the Lord, and not unto men.
as a test... I''m just drawing the GUI in ortho mode, & thats it. so before everything else. whats your train of thought? *sigh... I know its something stupid... it always is
want some source?
want some source?
Whatsoever you do, do it heartily as to the Lord, and not unto men.
That would be nice yeah, it might be a problem with depth testing/masking settings or something, maybe blending problems or something completely different...
Yes, blending might be the problem, but I''d check the texture as well.
Maybe you''re not loading it in the right way, or you''re not using it when drawing.
Anyway, if I had to guess, I''d say it''s the blending function.
Maybe you''re not loading it in the right way, or you''re not using it when drawing.
Anyway, if I had to guess, I''d say it''s the blending function.
all of this code was mostly ripped from nehe in one form or another.. I am just not using it right somehow.
Here is the initialize function & the print function of one attempt:
here is the source for how I switch back & forth to ortho perspective & where I draw some of the objects:
here is another attempt, taking a different route:
Here is the initialize function & the print function of one attempt:
HFONT fonts[2];unsigned int guiFontBase[2];// need an array of fonts?void Build2dFont(void) // Build Our Bitmap Font - ditched "GLVoid," (?){ //HFONT font; // Windows Font ID int numFonts = 2; guiFontBase[0] = glGenLists(96); // Storage For 96 Characters guiFontBase[1] = glGenLists(96); fonts[0] = CreateFont( 18, // Height Of Font (-24 originally?) 0, // Width Of Font 0, // Angle Of Escapement 0, // Orientation Angle FW_BOLD, // Font Weight TRUE, // 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 "Arial"); // Font Name fonts[1] = CreateFont(-12,0,0,0,FW_NORMAL,FALSE,FALSE,FALSE, ANSI_CHARSET,OUT_TT_PRECIS,CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,FF_DONTCARE|DEFAULT_PITCH, "Arial"); SelectObject(hDC, fonts[0]); // Selects The Font We Want wglUseFontBitmaps(hDC, 32, 96, guiFontBase[0]); // Builds 96 Characters Starting At Character 32 SelectObject(hDC, fonts[1]); wglUseFontBitmaps(hDC, 32, 96, guiFontBase[1]);}void gl2dPrint(const char *fmt, ...) // Custom GL "Print" Routine{ 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 glListBase(guiFontBase[0] - 32); // Sets The Base Character to 32 glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); // Draws The Display List Text glPopAttrib(); // Pops The Display List Bits}
here is the source for how I switch back & forth to ortho perspective & where I draw some of the objects:
void Gui::switchToOrtho(void) { glMatrixMode(GL_PROJECTION); // Select Projection glPushMatrix(); // Push The Matrix glLoadIdentity(); // Reset The Matrix glOrtho( 0, screenWidth, screenHeight, 0, -1, 1 ); // Select Ortho Mode (640x480) glMatrixMode(GL_MODELVIEW); // Select Modelview Matrix glPushMatrix(); // Push The Matrix glLoadIdentity(); // Reset The Matrix}void Gui::switchBackToPerspective(void) { glMatrixMode( GL_PROJECTION ); // Select Projection glPopMatrix(); // Pop The Matrix glMatrixMode( GL_MODELVIEW ); // Select Modelview glPopMatrix(); // Pop The Matrix}void Gui::drawGui(void) { int i; switchToOrtho(); glDisable(GL_DEPTH_TEST); glDisable(GL_BLEND); for(i=0;i<numPanels;i++) { panels[i].drawObject(); } switchBackToPerspective();}
here is another attempt, taking a different route:
//globals for now, ECH!!!unsigned int guiTexture[1];int fontBase;void buildGuiFont(void) { int loop1 = 0; glColor4f(1.0f,1.0f,1.0f,1.0f); glEnable(GL_TEXTURE_2D); // Enable Texture Mapping glGenTextures(1, &guiTexture[0]); fontBase=glGenLists(256); // Creating 256 Display Lists glBindTexture(GL_TEXTURE_2D, guiTexture[0]); // Select Our Font Texture for (loop1=0; loop1<256; loop1++) // Loop Through All 256 Lists { float cx=float(loop1%16)/16.0f; // X Position Of Current Character float cy=float(loop1/16)/16.0f; // Y Position Of Current Character glNewList(base+loop1,GL_COMPILE); // Start Building A List glBegin(GL_QUADS); // Use A Quad For Each Character glTexCoord2f(cx,1.0f-cy-0.0625f); // Texture Coord (Bottom Left) glVertex2d(0,16); // Vertex Coord (Bottom Left) glTexCoord2f(cx+0.0625f,1.0f-cy-0.0625f); // Texture Coord (Bottom Right) glVertex2i(16,16); // Vertex Coord (Bottom Right) glTexCoord2f(cx+0.0625f,1.0f-cy); // Texture Coord (Top Right) glVertex2i(16,0); // Vertex Coord (Top Right) glTexCoord2f(cx,1.0f-cy); // Texture Coord (Top Left) glVertex2i(0,0); // Vertex Coord (Top Left) glEnd(); // Done Building Our Quad (Character) glTranslated(15,0,0); // Move To The Right Of The Character glEndList(); // Done Building The Display List }}void glPrint(int x, int y, int set, const char *fmt, ...){ glBindTexture(GL_TEXTURE_2D, guiTexture[0]); 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 if (set>0) { // Did User Choose An Invalid Character Set? set=1; // If So, Select Set 1 (Italic) } else if(set<0) { set = 0; } glEnable(GL_TEXTURE_2D); // Enable Texture Mapping glLoadIdentity(); // Reset The Modelview Matrix glTranslated(x,y,0); // Position The Text (0,0 - Bottom Left) glListBase(fontBase-32+(128*set)); // Choose The Font Set (0 or 1) if (set==0) { // If Set 0 Is Being Used Enlarge Font glScalef(1.5f,2.0f,1.0f); // Enlarge Font Width And Height } glCallLists(strlen(text),GL_UNSIGNED_BYTE, text); // Write The Text To The Screen glDisable(GL_TEXTURE_2D); // Disable Texture Mapping}
Whatsoever you do, do it heartily as to the Lord, and not unto men.
still stuck... got a question... do I need to setup some kinda raster for the text? (even though I''m in ortho mode)
like... glRasterPos2f() ????
like... glRasterPos2f() ????
Whatsoever you do, do it heartily as to the Lord, and not unto men.
glRasterPos is like glTranslate but it only changes the following data it''s position, not the actual matrix transformation (am i right?). Anyway your problem is probably that the masking doesn''t work, i don''t know if wglUseFontBitmaps does that automatically but i doubt it and your second attempt doesn''t do that for sure. Try masking (maybe look through the masking tutorial at NeHe''s).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement