From: Combe, C. <C....@na...> - 2002-12-17 12:54:47
|
Hi I'm a bit confused by the reshape() method. I've got a button, in the frame that contains my subclass of GLCanvas, which I use to swap between a 2D and a 3D view. Depending on whether the canvas attribute 'flat' is true or false the button calls either goFlat() or go3D(). Here a code extract from my canvas class : public void reshape(int width, int height) { if (flat) goFlat(); else go3D(); } public void goFlat() { //not sure if you need to change to projection matrix before call to gluOrtho2D gl.glMatrixMode(GL_PROJECTION); //Reset The Projection Matrix gl.glLoadIdentity(); glu.gluOrtho2D(0, ((landWidth * 2) + 1), ((landWidth * 2) + 1), 0); gl.glMatrixMode(GL_MODELVIEW); gl.glViewport(0, 0, this.getWidth(), this.getHeight()); flat = true; } public void go3D() { //Select The Projection Matrix gl.glMatrixMode(GL_PROJECTION); //Reset The Projection Matrix gl.glLoadIdentity(); glu.gluPerspective(viewAngle, (float)getSize().width / (float)getSize().height, NPDist, 4500.0f); gl.glMatrixMode(GL_MODELVIEW); gl.glViewport(0, 0, this.getWidth(), this.getHeight()); flat = false; } The method that draws to the canvas does different things depending on the state of the 'flat' attribute. This sort of works but you need to resize the window after changing between 2D and 3D mode - this doesn't make sense to me as (it looks like) all the reshape() method does is call goFlat() or go3D(), which were called when the button was pressed. ? cheers, colin |