• Advertisement
Sign in to follow this  

openGL viewport

This topic is 4327 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
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
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
Sign in to follow this  

  • Advertisement