Hi all,
I am started to deal with opengl. My application is written in Java using SWT as windowing system.
Using http://lwjgl.org/ and SWT, I am able to use opengl in my SWT canvas. I wrote the following simple opengl code in my canvas paint listener:
// clear to background color
GL11.glClearColor(.3f, .5f, .8f, 1.0f);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
// draw rectangle
GL11.glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glBegin(GL11.GL_POLYGON);
GL11.glVertex3f(0.1f, 0.1f, 0.0f);
GL11.glVertex3f(0.1f, 0.9f, 0.0f);
GL11.glVertex3f(0.9f, 0.9f, 0.0f);
GL11.glVertex3f(0.9f, 0.1f, 0.0f);
GL11.glEnd();
GL11.glFlush();
I want know to add a resize listener on my canvas in order to always have my rectangle in the center of the window. How should I do that ?
Thanks in advance, Manu