Results 1 to 4 of 4

Thread: 2D text in a 3D world

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2000
    Posts
    9

    2D text in a 3D world

    I've tried to do 2D text in my 3D world, but I with no success so far.
    I've tried going to gluOrtho2D and then using glRasterPos2D to place the text, and then glutBitmapCharacter to actually draw the text.
    The problem is, I don't exactly know how to set up gluOrtho2D, and then what coordinates to put in glRasterPos2D (I've tried 0,1,0,1 in gluOrtho2D and then something like 0.4,0.4 in glRasterPos2D but that didn't work).
    If someone can please point me in the right direction, including what matrix operations I need to do (like glPushMatrix or glMatrixMode to go to the projection matrix maybe?).

    Thanks.

  2. #2
    Junior Member Newbie
    Join Date
    Mar 2001
    Location
    Sweden
    Posts
    8

    Re: 2D text in a 3D world

    The glRasterPos2D function looks like this:

    glRasterPos2D(int x, int y);

    You are not allowed to put float-digits as parameters.

  3. #3
    Senior Member Regular Contributor
    Join Date
    May 2001
    Posts
    105

    Re: 2D text in a 3D world

    Hi Tidhar,

    if you switch from 3d to 2d you can use:

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    glOrtho (0.0, g_width, g_height,0, -1.0,1.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    This will give you a rectangle with range (0,0) to (g_width,g_height). You may set g_width and g_height to the size of your window.

    Then you can do all your 2d drawing and text output (BTW void glRasterPos2f(GLfloat x, GLfloat y); is perfectly legal) and then reset your matrices:

    glEnable(GL_LIGHTING);
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    Please note that this restores your projection matrix but not your modelview matrix. But I guess that you'll update it each frame...

    Hope that helps,
    Stefan

  4. #4
    Junior Member Newbie
    Join Date
    Sep 2011
    Posts
    5

    Re: 2D text in a 3D world

    Hi,

    I'm trying to do the same, raster a 2d text. It works fine, but after restoring the projection and modelview matrixs something doesn't work properly with selection. I always get a hit wherever I put the mouse pointer. It seems like something is wrong with the modelview restoration. I don't know what I'm missing.

    Thats's a code snippet of what I'm doing:


    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    glOrtho(0.0, (GLfloat)(viewport[2] - viewport[0]), 0.0, (GLfloat)(viewport[3] - viewport[1]), -1, 1);
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();

    glPushAttrib(GL_LIST_BIT);
    glListBase(IDBASELISTAFUENTETEXTO);

    glRasterPos2d(...);
    glCallLists(...); //to draw the text

    glPopAttrib();


    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();

    I've even tried to use glPushAttrib(GL_ALL_ATTRIB_BITS) and glPopAttrib()...

    Thanks in advance,

    Ignasi

Similar Threads

  1. Text and/or textures position in 3D world
    By Slookeur in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 10-07-2014, 10:10 AM
  2. Writing text in a World
    By danu.oleg in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 10-15-2010, 06:31 AM
  3. Placing text in 3D world.
    By Zalewa in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 12-06-2009, 04:52 PM
  4. 3d Text & world vs. object coordinates
    By GW in forum OpenGL: Advanced Coding
    Replies: 8
    Last Post: 05-29-2004, 12:39 AM
  5. Rotated Text in 2d world
    By marcelo_g_souza in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 06-20-2003, 03:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean