Hello Guest

AWT gl Canvas separate Context

  • 0 Replies
  • 1344 Views
AWT gl Canvas separate Context
« on: February 08, 2015, 13:50:39 »
Hi everyone,

im trying to create a separate frame with an AWTGlCanvas. This canvas needs to have a different context then my original one. -a higher openGL Version (4.0).
The frame is created properly and im even able to draw onto it with openGL but if i check the Version it's still in the wrong context.
Maybe you have an idea how to fix it?
Here are the interesting code parts, how i'm creating the canvas.

Code: [Select]
public class FogExe implements Runnable {

private FogAWTGLCanvas awtglcanvas;

    public void run() {

    Frame frame=new Frame("Fog Renderer Context");
PixelFormat pixelFormat = new PixelFormat();
ContextAttribs contextAtrributes = new ContextAttribs(4, 0)
    .withForwardCompatible(true)
    .withProfileCore(true);

try {
System.out.println("creating awt canvas");
awtglcanvas = new FogAWTGLCanvas(GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(), pixelFormat ,null, contextAtrributes);
} catch (LWJGLException e) {
e.printStackTrace();
}
frame.setLayout(new GridLayout(1, 2));
frame.add(awtglcanvas,"Center");
awtglcanvas.setPreferredSize(new Dimension(854,480));
frame.pack();
frame.setVisible(true);
    }
 
}

This is executed like this:
Code: [Select]
Thread ComputingThread = new Thread(new FogExe());
ComputingThread.start();

My custom Canvas class FogAWTGLCanvas just extends the standard AWTGLCanvas and overrides those functions:
Code: [Select]
protected void initGL() {
program = LoadShader.SetupFourShader("screen40");
GL11.glViewport(0, 0,Width, Height);
GL11.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
}

/** Override this to do painting */
protected void paintGL() {
System.out.println(GL11.glGetString(GL11.GL_VERSION));
GL11.glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
try{
this.swapBuffers();
}catch(LWJGLException e){
System.out.println("Failed buffer swap");
}
repaint();
}

I hope you understand my Problem,
thanks for reading,
Help would be awesome!

Cery