Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: glOrtho: How can I MOVE my text

  1. #1
    Intern Contributor
    Join Date
    Nov 2002
    Posts
    98

    glOrtho: How can I MOVE my text

    I used Nehe's method of drawing text: a display list with all characters, then calling the characters in list with a char array.
    Problem is that all my text I print is in the bottom of the screen and printed right behind the previous text.

    My code that handles the drawing:

    Code :
    glPushMatrix();
    		glOrtho(0,bound_x,bound_y,0,-1,1);
    		glTranslatef(300,400,0);
    		glPushAttrib(GL_LIST_BIT);
    		glListBase(base - 32);
     
    		glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
    		glPopAttrib();
    	glPopMatrix();
    As you see I have tried to use translatef to move the text about, but it doesn't work. Obviously I'm missing something simple.

    Thanks!

  2. #2
    Member Regular Contributor
    Join Date
    Jul 2001
    Posts
    409

    Re: glOrtho: How can I MOVE my text

    Show us what's inside the display list.

  3. #3
    Intern Contributor
    Join Date
    Nov 2002
    Posts
    98

    Re: glOrtho: How can I MOVE my text

    Name of the list is "base", here I assemble the characters.

    Code :
    HFONT	font;						
    	HFONT	oldfont;					
     
    	base = glGenLists(96);					
     
     
    	font = CreateFont(	-size,				
    						0,				
    						0,				
    						0,				
    						FW_BOLD,			
    						FALSE,				
    						FALSE,				
    						FALSE,				
    						ANSI_CHARSET,			
    						OUT_TT_PRECIS,			
    						CLIP_DEFAULT_PRECIS,		
    						ANTIALIASED_QUALITY,		
    						FF_DONTCARE|DEFAULT_PITCH,	
    						name);			
     
    	oldfont = (HFONT)SelectObject(hDC, font);		
    	wglUseFontBitmaps(hDC, 32, 96, base);			
    	SelectObject(hDC, oldfont);				
    	DeleteObject(font);

  4. #4
    Intern Newbie
    Join Date
    Jan 2003
    Location
    UK
    Posts
    44

    Re: glOrtho: How can I MOVE my text

    I *think* you have to use glRasterPos* commands to control the output position rather than glTranslatef.

  5. #5
    Intern Contributor
    Join Date
    Nov 2002
    Posts
    98

    Re: glOrtho: How can I MOVE my text

    Yes, I've used glRasterPos and it seems to work. A few things though...

    1: x axis is flipped. Is the ortho effected by the rotation? I have rotated my camera 180 degrees, so it seems to be logical.

    2: I thought to be smart and reloaded the identity matrix to see where the x flip came from... yeh, right, no text appears AT ALL...
    When i take out the rasterpos my text moves off the screen: it starts in the bottom of the screen and then quickly moves to the right. I mean, WTF?

    Code :
    	glColor3f(rc,gc,bc);
     
    	glPushMatrix();
    		glMatrixMode(GL_PROJECTION);
     
    	glPushMatrix();
    		glLoadIdentity(); // <- bad bad matrix!
    		glOrtho(0,800,0,600,-1,1);
    		glMatrixMode(GL_MODELVIEW);
    		//glRasterPos2f(x,y); // <- If left in, no text visible, if not, text moves off screen
    		glPushAttrib(GL_LIST_BIT);
    		glListBase(base - 32);
     
    		glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
    		glPopAttrib();
    	glPopMatrix();

    [This message has been edited by Structural (edited 01-10-2003).]

  6. #6
    Intern Newbie
    Join Date
    Jan 2003
    Location
    UK
    Posts
    44

    Re: glOrtho: How can I MOVE my text

    RasterPos will be affected by the current modelview matrix.

    The code fragment above has a mismatch with the number of PushMatrix and PopMatrix commands - does this occur in the program, or have you missed a pop off the cut/paste. Also remember that PopMatrix will pop the current matrix - you push the projection, but pop the modelview.

    [This message has been edited by T (edited 01-10-2003).]

  7. #7
    Intern Contributor
    Join Date
    Nov 2002
    Posts
    98

    Re: glOrtho: How can I MOVE my text

    oi... hadden't seen that, that was indeed a bug. But anyway, I took the MatrixMode out but the text keep running off the screen.
    When I put in a glMatrixMode(GL_MODELVIEW) line in the end to match the pushes, followed by another pop there isn't any change also...

    I copy-pasted NEHE's DISPLAY code from his lesson17 (texture mapped fonts) that also used the otho view, but the same things happens, while his demo works ok.

    Any ideas of what the hell is going on?

  8. #8
    Intern Newbie
    Join Date
    Jan 2003
    Location
    UK
    Posts
    44

    Re: glOrtho: How can I MOVE my text

    If using RasterPos results in nothing visible, then that suggests that the position you are giving it is not visible. Beware that if you place the rasterpos off the left of the screen, nothing will get drawn even if you think some of the text should be visible (if rasterpos is not visible nothing gets drawn at all).

    Without using RasterPos you say the text moves. I *think* the rasterpos will get updated when you have drawn the text to be at the end of the text, thus repeated drawing may make the text move to the right. Just a thought.

  9. #9
    Intern Contributor
    Join Date
    Nov 2002
    Posts
    98

    Re: glOrtho: How can I MOVE my text

    I have tried many reasonable values that should lie in my raster, but nothing... Even values between 0 and 1...

    When I leave out the loadIdentity it works fine. I do see text without the loadidentity, but as soon as I put in the loadidentity it's gone.....

    Could it have something to do with the last two parameters of glOrtho: the far and near clipping plane? I have tried this with different values too (originally -1 and 1) (no result ofcourse).

  10. #10
    Intern Newbie
    Join Date
    Jan 2003
    Location
    UK
    Posts
    44

    Re: glOrtho: How can I MOVE my text

    What is it you are trying to do? Place text just using 2D pixel coordinates or place text within a 3D scene.

    I'm guessing that you are trying to place text by specifying its 2D pixel coords. In this case your projection matrix should be set with ortho (like you are doing) and your modelview matrix should be identity.

    If you are using 2D commands then z will be assumed zero and it should be within the range in your ortho command.

    Why do you rotate the camera 180degrees?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •