Hi,
I am tryin to use Viewport but I have no luck. No matter what settings I use for glViewport option, the whole window is displayed.
My window size is 500x400 but I need to show a viewport of size 50x50 inside the window. And I just cannot figure what the problem is???
void other_init()
{
glClearColor(1.0, 1.0, 1.0, 1.0); // Set background
glColor3d(0.0,0.0,0.0); // Set forecolor
// Setup for viewing
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-2026.0, 2026.0, -2026.0, 2026.0, -2026.0, 2026.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glViewport(20, 20, (GLsizei)50, (GLsizei)50); //<== THIS IS WHERE I AM TRYING TO SET VIEWPORT ????
// Callback event handlers
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT); // Clear
... draw a cube by reading lines from input file ...
}
I have the exact same problem, and I’m trying to do the same thing. I do have an ATI card, but the glScissor command does not work either. Anyone have a solution? It doesn’t seem like this should cause problems as I’ve followed our book and tutorials online and nothing seems to work. I’m beginning to wonder if the glViewport command is even implemented at all in opengl.
Well, after some testing, it looks like I must define a glutReshapeFunc(funcName) for the glViewport to do anything. the reshape function can be completely empty, but with the call to glutReshapeFunc present, the glViewport in the other_init() function will take effect. Anyone care to comment on why this is?
Edit: After reading through the OpenGL docs, it appears that before the initial showing of the window and before any focus, move, or resize, that the reshape function is called. If you do not specify a reshape function, it uses the default reshape function which uses the call glViewport(0,0,w,h) to use the full window, so any glViewport call by the programmer is overridden by the default. I guess that is an issue that our book and many tutorials should post, that a reshape callback function must be specified for proper behavior of glViewport.