Sign in to follow this  
judge dreadz

openGL viewport

Recommended Posts

judge dreadz    193
the perspective in my GLUT window is wrong. when i draw a circle, it looks slightly oval shaped. not really sure how this all works, hoping someone can tell me what the problem might be. here is the code that initialises the window:
void reSizeWindow(int width, int height)
{					
	glMatrixMode(GL_PROJECTION);						
	glLoadIdentity();									
	gluPerspective(60.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
	glViewport(0,0,width,height);
	glMatrixMode(GL_MODELVIEW);							
	glLoadIdentity();				
	gluLookAt(eye[0], eye[1], eye[2], 0.0f, 3.0f, 0.0f, upvec[0], upvec[1], upvec[2]);
}					
i also need to redefine the viewport in the display method before drawing anything. i use the following code:
	   	
   	glMatrixMode(GL_PROJECTION);						
	glLoadIdentity();
        gluPerspective(60.0f,glutGet(GLUT_WINDOW_WIDTH)/glutGet(GLUT_WINDOW_HEIGHT),0.1f,100.0f);
	glViewport(0,0,glutGet(GLUT_WINDOW_WIDTH),glutGet(GLUT_WINDOW_HEIGHT));
	glMatrixMode(GL_MODELVIEW);							
	glLoadIdentity();				
	gluLookAt(eye[0], eye[1], eye[2], 0.0f, 3.0f, 0.0f, upvec[0], upvec[1], upvec[2]);	

Share this post


Link to post
Share on other sites
jamba    124
In the gluPerspective call in the second block of code, the glutGet functions will return ints, so you're doing an integer divide. (So something like 4/3 will equal 1) Cast one of those glutGet results to a GLfloat.

But why do you need to "redefine the viewport in the display method before drawing anything"? It looks like you're setting it to the same value you're using in reSizeWindow. Just set the viewport and projection matrix in reSizeWindow.

Share this post


Link to post
Share on other sites
judge dreadz    193
Quote:
Original post by jamba
In the gluPerspective call in the second block of code, the glutGet functions will return ints, so you're doing an integer divide. (So something like 4/3 will equal 1) Cast one of those glutGet results to a GLfloat.


yeah thanks that looks right now.

Quote:

But why do you need to "redefine the viewport in the display method before drawing anything"? It looks like you're setting it to the same value you're using in reSizeWindow. Just set the viewport and projection matrix in reSizeWindow.


heh i knew someone would ask me that. the brief answer is that i have to set a different perspective in another part of the program to do a texture read in the GPU before every display.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this