PDA

View Full Version : glViewport Question



10-09-2006, 11:15 AM
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????

Here is my code:


void main(int argc, char** argv)
{
init_window(argc,argv);
other_init();
glutMainLoop(); // Main event loop
}
void init_window(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode (GLUT_RGB);
glutInitWindowSize(500,400);
glutInitWindowPosition(0,0);
glutCreateWindow("HW3");
}
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 ...

}Any help will be appreciated!
Thank you.
-Tom

ZbuffeR
10-09-2006, 11:30 AM
Using ATI ? go for http://www.mevis.de/opengl/glScissor.html
The glViewport alone command is not forced to limit the drawing.

10-09-2006, 11:39 AM
I'm using openGL and GLUT.

This is what I'm trying to do:
http://ipfwonline.com/images/hw3.jpg

ZbuffeR
10-09-2006, 01:13 PM
ATI ... is a video card manufacturer ... :rolleyes:
Did you try the glScissor ?

10-09-2006, 10:09 PM
be warned that Viewport does not clip clears, you need to use scissor for that

oryan_dunn
10-24-2006, 05:12 PM
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.

oryan_dunn
10-24-2006, 06:01 PM
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.