PDA

View Full Version : resolution problems in glut



onlyhuman23
07-28-2002, 10:43 PM
I am working on a simple 2D application in glut. The problem is that I set glutOrtho2D() and glViewport() according to the screenWidth and screen height I want. but wheen I change the resolution of windows the resolution of the glut application does not change accordingly.
My second problem is that I use a function to reshape the viewport of the window but it reshapes the window as such that it leaves quit alot of space either vertically on one side or horizontally down. What should I do. The funcrtion that I pass to
glutReshapeFunc() is as follows. If anyone can provide me a better solution I will be very thankfull:
(I took it from the book computer graphics using openGL by F.S.HILL JR)
///////////////////////////////////////////
void main(int argc, char** argv)
{
glutInit(&argc, argv); //initialize the toolkit
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); //set display mode
glutInitWindowSize(screenWidth, screenHeight); //set window size
// glutInitWindowPosition(100,100); //set window position on screen
var=glutCreateWindow("Dot plot of a function"); //open the screen window
glutFullScreen();
glutDisplayFunc(myDisplay); //register redraw function
myInit();
glutReshapeFunc(myReshape);
createGLUTMenus();
glutMainLoop(); //go into a perpetual loop
}
//<<<<<<<<<<<<<<<<<<End of the Main Function>>>>>>>>>>>>>>>>>>>
//<<<<<<<<<<<<<<<<<<myReshape Func>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void myReshape(GLsizei W, GLsizei H)
{
int R = screenWidth/screenHeight;
if(R==W/H)
glViewport(0,0,W,H);
if(R> W/H)
glViewport(0,0,W,W/R);
else
glViewport(0,0,H*R,H);
}

Bob
07-29-2002, 12:55 AM
The problem is that I set glutOrtho2D() and glViewport() according to the screenWidth and screen height I want.

I don't see where you call gluOrtho2D.

Also, your reshape function contains lots of uneeded code. if you want the viewport to cover the entire window, just put this into your reshape function.



void myReshape(GLsizei W, GLsizei H)
{
glViewport(0, 0, W, H);
}

No need to mess with aspect ratio, since you have the size of the window passed to the function.