glViewport Question

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)
    glutMainLoop();                 // Main event loop
void init_window(int argc, char** argv)
	glutInitDisplayMode (GLUT_RGB); 
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
	glOrtho(-2026.0, 2026.0, -2026.0, 2026.0, -2026.0, 2026.0);
    glViewport(20, 20, (GLsizei)50, (GLsizei)50);  //<== THIS IS WHERE I AM TRYING TO SET VIEWPORT ????

    // Callback event handlers
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.

Using ATI ? go for
The glViewport alone command is not forced to limit the drawing.

I’m using openGL and GLUT.

This is what I’m trying to do:

ATI … is a video card manufacturer … :rolleyes:
Did you try the glScissor ?

be warned that Viewport does not clip clears, you need to use scissor for that

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.