glViewport doesnt set the window size

Hi

I have only just begun to learn JOGL, i have written several basic programs, but they have all had the same problem. All the drawing works correctly, but when the window is first displayed it is a tiny little square in the top left corner. If the bottom right corner is dragged to expand the window then as I said the drawing is displayed correctly.

Here is the code that i thought was supposed to set the viewable size of the GLCanvas:


public void init(GLAutoDrawable drawable)
{		
	GL lib = drawable.getGL();
	GLU glu = new GLU();
		
	lib.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	lib.glViewport(-500, -300, 500, 300);  // THIS LINE
	lib.glMatrixMode(GL.GL_PROJECTION);
	lib.glLoadIdentity();
		
	glu.gluOrtho2D(-500.0, 500.0, -300.0, 300.0);
}

Hi,

First it’s quite strange to call the GL object lib… no ???

To change the size of the GLCanvas you have to call setBounds (or setSize) on it. ( Or on the Frame containing it and use a correct layout manager).

The glViewport method is not devoted to that purpose… You should have a look to the jogl samples and the red book to used it properly.
Hope it helps.

I actually got the basis of this code from:

http://www.genedavissoftware.com/books/jogl/ljogl_ch1.html

and as i said, i am new to JOGL, and i figured that the GL object is a single instance used to call library (lib) functions to set state variables… i dunno it made sense to me.

so what exactly is glViewport supposed to do??

I also think it makes sense, but I would call it “context”, since there could be more than one (e.g. using multiple canvases) and the gl object defines the context in which your gl-calls are executed.

It only sets up the math behind converting the opengl-coordinates to pixel coordinates of your canvas: http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/viewport.html

So if you want the window size to be the correct size when it is first opened, you have to set the size of the OpenGL canvas object in the window/frame. In SWT, this is done using GLCanvas.setBounds(). I’m sure JOGL’s GLCanvas has something similar (like a setSize() method).