09-24-2002, 11:27 AM
Thank you very much for your help. I got it according to your ways.
[This message has been edited by huizhang (edited 09-24-2002).]
09-24-2002, 11:32 AM
How does it not work exactly?
It's a little odd doing that in the Init function. Usually that should be done in the resize. You also are setting glViewport to a size of 500x300, but your window is initially 300x400.
09-24-2002, 12:12 PM
First I think that you maybe are thinking in 2D for seting up your world.
The view port is the physical size of your window. Starting at the top left hand of the window to the lower right hand side.
Don't get confused with your Windows desktop X/Y position, even though you tell it to put your window at 100, 100. Any graphics drawn in the openGL window start at 0,0 to 300,400, not 100+300, 100+400.
Viewport tell openGL the size space to render your 3D scene to.
// example reshape function which is called by windows, when then window has been re-sized.
glutReshapeFunc(reshape); // place in main function
void reshape (int w, int h)
glViewport (0, 0, (GLsizei) w, (GLsizei) h); Tell openGL the new size of our window in pixels.
Now your ortho view is the area in which opengl is going to render, anything not within the bounds of the ortho setting will not be drawn. For ortho2D you set your top/bottom points, but it also sets you front(near) and back(far) to -1, 1.
Anything drawn with a Z axis outside of -1 to 1 will not be drawn.
If you are want to work in pixels then the ortho should look like this gluOrtho2D(0,0,300,400); // Which is the size of your window.
But ortho view could also look something like this: gluOrtho2D(-10,10,10,-10) and would still fill the screeen.
Originally posted by huizhang:
Hi,I am a new student of OpenGL. Thank you for your help.
My program like the following. I don't know the reason that the glViewport() doesn't work.
glClearColor(1.0, 0.0, 1.0, 0.0);
int main(int argc, char** argv)
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.