From: Combe, C. <C....@na...> - 2002-12-17 16:23:34
|
OK, i wasn't managing my GLContext correctly. Maybe I should change to using the EventListener way rather than the subclassing way. This is all about using gljMakeCurrent() and gljFree() to ensure that only one thread is trying to issue gl commands at any time - right? Do all commands that start glj. , gl. or glu. need to be between gljMakeCurrent() and gljFree()? I notice people don't seem to put instructions in their init() or reshape() methods between these commands - why is this?. If you were 100% certain that only one Thread would call GL commands could you miss the commands out (this is just out of interest, its not something I want to do) ? Is a thread blocked until gljMakeCurrent() suceeds? If not, and gljMakeCurrent() fails do the commands just not happen? any advice about how to deal with multiple threads interacting with one canvas will be most welcome, cheers, col -----Original Message----- From: Combe, Colin [mailto:C....@na...] Sent: 17 December 2002 12:52 To: gl4...@li... Subject: [gl4java-usergroup] confused by reshape 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 ------------------------------------------------------- This sf.net email is sponsored by: With Great Power, Comes Great Responsibility Learn to use your power at OSDN's High Performance Computing Channel http://hpc.devchannel.org/ _______________________________________________ gl4java-usergroup mailing list gl4...@li... https://lists.sourceforge.net/lists/listinfo/gl4java-usergroup |