Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 551153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:21:48+00:00 2026-05-13T11:21:48+00:00

I have the following code to render text in my app, first i get

  • 0

I have the following code to render text in my app, first i get the mouse coordinates in the world, then use those coordinates to place my text in the world, so it will follow my mouse position:

Edit: added buildfont() function in code example:

GLvoid BuildFont(GLvoid)                                // Build Our Bitmap Font
{
    HFONT   font;                                       // Windows Font ID
    HFONT   oldfont;                                    // Used For Good House Keeping

    base = glGenLists(96);                              // Storage For 96 Characters

    font = CreateFont(  -12,                            // Height Of Font
                        0,                              // Width Of Font
                        0,                              // Angle Of Escapement
                        0,                              // Orientation Angle
                        FW_NORMAL,                      // 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
                        "Verdana");                     // Font Name (if not found, its using some other font)

    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 glPrint(const char *fmt, ...){
    char text[256];
    va_list ap;
    if (fmt == NULL) return;
    va_start(ap, fmt);
        vsprintf(text, fmt, ap);
    va_end(ap);
    glPushAttrib(GL_LIST_BIT);  
    glListBase(base - 32);  
    glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
    glPopAttrib();
}

...

glPushMatrix();
    glColor4f(0,0,0,1);
    // X-1 wont work because these are the world coordinates:
    glRasterPos2d(MousePosX-1, MousePosY);
    glPrint("TEST");

    glColor4f(1,1,0,1);
    glRasterPos2d(MousePosX, MousePosY);
    glPrint("TEST");
glPopMatrix();

But i want to render multiline texts, or texts with “borders” (like in above code i tried) or text with background (so i could distinguish them better from the background)
So how i do this?

I just need to know how i can move it in pixels, so i could precisely modify the position on my screen WITHOUT using 2d projection view on top of my 3d render projection… i just want to make it as simple as possible.

I tried to draw a quad under the text, but of course it doesnt work since its still using the world coordinates… so when i rotate my camera the text doesnt move along the background of the text… i am afraid the only solution is to create another projection on top of the 3d projection…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T11:21:49+00:00Added an answer on May 13, 2026 at 11:21 am

    Here’s a small snippet of code that I use to render some debug text in a small application:

    void
    renderText(float x, float y, const char* text) {
        int viewport[4];
        glGetIntegerv(GL_VIEWPORT, viewport);
        glMatrixMode(GL_PROJECTION);
        glPushMatrix();
        glLoadIdentity();
        glOrtho(viewport[0], viewport[2], viewport[1], viewport[3], -1, 1);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glRasterPos2f(x, viewport[3] - y);
        const int length = (int)strlen(text);
        for (int i = 0; i < length; ++i) {
            glutBitmapCharacter(GLUT_BITMAP_9_BY_15, text[i]);
        }
        glMatrixMode( GL_PROJECTION );
        glPopMatrix();
        glMatrixMode( GL_MODELVIEW );   
        glPopMatrix();
    }
    

    xand y is the desired window coordinates of the string. glutBitmapCharacter(GLUT_BITMAP_9_BY_15, ...) is just a utility function from GLUT that renders a 9 x 15 pixels large bitmap character.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.