View Full Version : problems with text and viewport
11-22-2003, 04:16 PM
I posted a message similar to this one a couple of days ago. I have a program where a color cube rotates about the x, y, and z axis, depending on which quadrant you click on, and the fourth quadrant pauses and restarts the rotation. I got a reply on how to keep the text from rotating with the cube by pushing and popping the matrix, but glortho readjusts the window to keep the cube in the middle, and the viewport clips off everything after about -2, 2 on the x and y axis, but it depends on the width and height of the window, but it is always around that. When you extend the window width, the text I have put in the upper left corner moves toward the center with the cube, and down when the height is exteded. How can I keep the text at the corner of the window without the viewport clipping it? Thanks
Have you used a reshape callback? Sounds (or reads) like you don't. The reshape callback is usually implemented like this (I am assuming you are using glut; if you're using windows put the code on a WM_SIZE message)
void reshape(int w, int h)
//w,h = current window width and height
glViewport(0, 0, w, h) // for a viewport that covers the entire window.
Try this and post back if your not satisfied.
11-22-2003, 07:22 PM
I am using a reshape function, this is it:
void myReshape(int w, int h)
glViewport(0,0, w, h);
if (w <= h)
glOrtho(-2.0, 2.0, -2.0 * (GLfloat) h / (GLfloat) w,
2.0 * (GLfloat) h / (GLfloat) w, -10.0, 10.0);
glOrtho(-2.0 * (GLfloat) w / (GLfloat) h,
2.0 * (GLfloat) w / (GLfloat) h, -2.0, 2.0, -10.0, 10.0);
I added this code to it to keep track of where I need to place the text:
if(w <= h)
whh=2.0 * ((GLfloat) h / (GLfloat) w);
www= 2.0 * (GLfloat) w / (GLfloat) h;
I start the text at (www, whh). Initially it doesnt even show up on the window, I have to increase the height a little to see it, but if I subtract as little as .1 from whh, it shows up in the middle of the window, so I am baffled as to what is going on. Thanks
[This message has been edited by snakepit (edited 11-22-2003).]
Powered by vBulletin® Version 4.2.2 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.