View Full Version : 2D text in a 3D world
03-16-2000, 05:47 AM
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?).
The glRasterPos2D function looks like this:
glRasterPos2D(int x, int y);
You are not allowed to put float-digits as parameters.
09-22-2001, 05:12 AM
if you switch from 3d to 2d you can use:
glOrtho (0.0, g_width, g_height,0, -1.0,1.0);
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:
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,
09-19-2011, 01:35 AM
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:
glOrtho(0.0, (GLfloat)(viewport - viewport), 0.0, (GLfloat)(viewport - viewport), -1, 1);
glCallLists(...); //to draw the text
I've even tried to use glPushAttrib(GL_ALL_ATTRIB_BITS) and glPopAttrib()...
Thanks in advance,
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.