gl calls outisde paintGL in applets

Started by polskyman, October 20, 2006, 22:05:02

Previous topic - Next topic

polskyman

Hi,

I am beginning to be familiar with applets but i have a problem when i try to call openGL instructions from without the paintGL function it does not work.
the only call to GL functions can be made from initGL but if call a gl instruction from a function called initator then gl functions do not work

package org.lwjgl.test.applet; 
  
import java.applet.Applet; 
import java.awt.BorderLayout; 
import java.awt.Canvas; 
  
import org.lwjgl.LWJGLException; 
import org.lwjgl.opengl.AWTGLCanvas; 
import org.lwjgl.opengl.Display; 
import org.lwjgl.opengl.GL11; 
import org.lwjgl.util.applet.LWJGLInstaller; 
  
public class AppletTestComplete extends Applet { 
  
  public void init() { 
    
    /* Install applet binaries */ 
    try { 
      LWJGLInstaller.tempInstall(); 
    } catch (Exception le) { 
      le.printStackTrace(); 
    } 
    
    setLayout(new BorderLayout()); 
    try { 
      Canvas canvas = new AppletCanvas(); 
      canvas.setSize(getWidth(), getHeight()); 
      add(canvas); 
    } catch (Exception e) { 
      e.printStackTrace(); 
    } 
  } 
  
  /* 
   * @see org.lwjgl.opengl.AWTGLCanvas 
   */ 
  public class AppletCanvas extends AWTGLCanvas { 
    
    float angle = 0; 
    
    /* 
     * @see org.lwjgl.opengl.AWTGLCanvas#AWTGLCanvas() 
     */ 
    public AppletCanvas() throws LWJGLException { 
      // Launch a thread to repaint the canvas 60 fps 
      Thread t = new Thread() { 
        public void run() { 
//////////////////////////////////////////////          
initator();   // the call to function at beginning of the main loop
/////////////////////////////////////////////
while (true) { 
            if (isVisible()) { 
              repaint(); 
            } 
            Display.sync(60); 
          } 
        } 
      }; 
      t.setDaemon(true); 
      t.start();      
    } 
/////////////////////////////////////////
// the function I want to call but it does not work
public void initator()
{

GL11.glClearColor(1.0f, 0, 1.0f, 0.0f);  //clear with pink color

}
  ////////////////////////////////////  
    /* 
     * @see org.lwjgl.opengl.AWTGLCanvas#paintGL() 
     */ 
    public void paintGL() { 
      GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); 
      GL11.glMatrixMode(GL11.GL_PROJECTION_MATRIX); 
      GL11.glLoadIdentity(); 
      GL11.glOrtho(0, 640, 0, 480, 1, -1); 
      GL11.glMatrixMode(GL11.GL_MODELVIEW_MATRIX); 
  
      GL11.glPushMatrix(); 
      GL11.glTranslatef(320, 240, 0.0f); 
      GL11.glRotatef(angle, 0, 0, 1.0f); 
      GL11.glBegin(GL11.GL_QUADS); 
      GL11.glVertex2i(-50, -50); 
      GL11.glVertex2i(50, -50); 
      GL11.glVertex2i(50, 50); 
      GL11.glVertex2i(-50, 50); 
      GL11.glEnd(); 
      GL11.glPopMatrix(); 
  
      angle += 1; 
  
      try { 
        swapBuffers(); 
      } catch (Exception e) { 
      } 
    }    
  } 
}



please help thanks

Matzon

the problem is that only the thread that created the context (the event thread) can be used to make OpenGL calls.
Otherwise you need to look into contexts and make current

polskyman