PDA

View Full Version : viewport works on width but not height



02-22-2003, 04:20 PM
Hi. My program's viewport seems to work on the width (ie when I resize the window, the box I drew does not move horizontally). However, when I resize the window it DOES move the object vertically. This makes me think that the viewport is somehow not correctly interpreting the height.

Here is my code if it helps:
________________________________________

#include <GL/glut.h>

GLsizei wh=600, ww=600;

void display(void)

{
//clear window
glClear(GL_COLOR_BUFFER_BIT);


//draw unit square polygon
glBegin(GL_POLYGON);
glVertex2f(-0.5, -0.5);
glVertex2f(-0.5, 0.5);
glVertex2f(0.5, 0.5);
glVertex2f(0.5, -0.5);
glEnd();

//flush GL buffers
glFlush();

}


void init()
{

//set bg color
glClearColor (0.695, 0.695, 0.934, 1.0);

//set fill color
glColor3f(1.0, 1.0, 1.0);

//this is the default view
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

void myReshape(GLsizei w, GLsizei h)
{
}

void main(int argc, char** argv)
{

/* Initialize mode and open a window in upper left corner of screen */
/* Window title is name of program (arg[0]) */

glutInit(&argc,argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(wh,ww);
glutInitWindowPosition(20,40);
glutCreateWindow("A Sunny Day with Phil");
init();
glutReshapeFunc(myReshape);
glutDisplayFunc(display);
glutMainLoop();

}

shinpaughp
02-22-2003, 06:09 PM
Your reshape function should at least call glViewPort(0, 0, w, h) and should probably redefine the projection matrix to maintain the aspect ratio, such as glOrtho(-w/(ww*2), w/(ww*2), -h/(wh*2), h/(wh*2), -1.0, 1.0). Or keep the viewport square by checking to see whether w or h is smaller and set glViewPort(0, 0, w<h?w:h, w<h?w:h), which would give you a square, but would not use the entire window.

Hope it gives you some ideas.

nexusone
02-23-2003, 05:21 AM
If don't see where you define the viewport in your code.

glViewport

Just finish posting twice on this same topic, check out the http://www.opengl.org/discussion_boards/ubb/Forum2/HTML/011865.html