We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › [Solved]GLException when create new java.awt.Frame
Page Index Toggle Pages: 1
[Solved]GLException when create new java.awt.Frame (Read 1533 times)
[Solved]GLException when create new java.awt.Frame
Dec 5th, 2008, 10:36am
 
Hello, this is my first time writing here.
I always enjoy coding with Processing :-) thx.

I'm trying to make new java.awt.Frame for full screen support of my application.

Until revision0138 or so, it worked fine.
But with recent revisions, it has GLException when add PApplet to new Frame...

Can anyone help me?


Entire code here, and Error below...


Code:


package fullscreen;

import java.awt.DisplayMode;
import java.awt.Frame;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import processing.core.PApplet;

public class MyApplet extends PApplet{

private static MyApplet myApplet;
private static int[] frameSize = {1024, 768};
private static Frame frame;
private static boolean FULL_SCREEN = false;

public void setup(){
 size(frameSize[0], frameSize[1], OPENGL);
}

public void draw(){
 background(100);
 fill(255);
 rect(100, 100, 100, mouseY);
}

public void mousePressed(){
 if(FULL_SCREEN)
  fullScreenOff(myApplet);
 else
  fullScreenOn(myApplet);
}

public static void main(String[] args){
 myApplet = new MyApplet();
 myApplet.init();
 fullScreenOff(myApplet);
}

public static void fullScreenOn(PApplet p5){
 if(frame != null){
  frame.setVisible(false);
  frame.dispose();
 }
 
 //create new frame without menubar
 frame = new Frame("FullScreen - MyApplet");
 frame.setUndecorated(true);
 frame.setSize(frameSize[0], frameSize[1]);
 frame.add(p5);
 frame.setVisible(true);
 GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
 DisplayMode newMode = new DisplayMode(frameSize[0], frameSize[1], 32, 0);
 if(gd.isFullScreenSupported()){
  gd.setFullScreenWindow(frame);
 }
 if(gd.isDisplayChangeSupported()){
  gd.setDisplayMode(newMode);
 }
 FULL_SCREEN = true;
}

public static void fullScreenOff(PApplet p5){
 if(frame != null){
  frame.setVisible(false);
  frame.dispose();
 }
 frame = new Frame("MyApplet");
 frame.setSize(frameSize[0], frameSize[1]);
 frame.add(p5);
 frame.setVisible(true);
 frame.setLocationRelativeTo(null);
 FULL_SCREEN = false;
}
}


Code:

Exception in thread "Animation Thread" javax.media.opengl.GLException: Unable to create OpenGL context for device context 0xffffffffaf011d2b
at com.sun.opengl.impl.windows.WindowsGLContext.create(WindowsGLContext.java:122)
at com.sun.opengl.impl.windows.WindowsGLContext.makeCurrentImpl(WindowsGLContext.java:150)
at com.sun.opengl.impl.windows.WindowsOnscreenGLContext.makeCurrentImpl(WindowsOnscreenGLContext.java:66)
at com.sun.opengl.impl.GLContextImpl.makeCurrent(GLContextImpl.java:134)
at processing.opengl.PGraphicsOpenGL.detainContext(PGraphicsOpenGL.java:225)
at processing.opengl.PGraphicsOpenGL.beginDraw(PGraphicsOpenGL.java:270)
at processing.core.PApplet.handleDraw(PApplet.java:1376)
at processing.core.PApplet.run(PApplet.java:1311)
at java.lang.Thread.run(Unknown Source)
Re: GLException when create new java.awt.Frame
Reply #1 - Dec 8th, 2008, 6:28pm
 
I solved this problem to reallocate the rendering context like below.

Code:

// p5 - instance of PApplet which uses OpenGL

((PGraphicsOpenGL)p5.g).context.destroy();
((PGraphicsOpenGL)p5.g).context = null;
((PGraphicsOpenGL)p5.g).allocate();
Re: [Solved]GLException when create new java.awt.F
Reply #2 - Feb 28th, 2009, 6:20pm
 
Hi

I'm working with processing and opengl... but i have a problem with the Panel & Frames...

I have this code:

public class Browser {
private WebBrowser webBrowser;
private Panel panel;
private String url;
public Browser(PApplet p) {
Component tmpComp = p.frame.getComponent(p.frame.getComponentCount() - 1);
p.frame.remove(p.frame.getComponentCount() - 1);
p.frame.setLayout(new FlowLayout());
BrowserEngineManager mng = BrowserEngineManager.instance();
mng.setActiveEngine(BrowserEngineManager.IE);
webBrowser = new WebBrowser();
webBrowser.setSize(400, 300);
webBrowser.setLocation(0, 0);
webBrowser.setVisible(false);
panel = new Panel();
panel.setSize(400, 300);
panel.setLocation(50, 50);
panel.add(webBrowser);
panel.setVisible(true);
p.frame.add(panel);
p.frame.add(tmpComp);
}
}

and if i run it with size(1024,768);  it works well...

But the problem is when i try to run it with opengl... the same error from your sketch of fullscreen appear...

Some body knows what can i do? Tnx!

The error is :

Exception in thread "Animation Thread" javax.media.opengl.GLException: Unable to create OpenGL context for device context 0x2a0123de

at com.sun.opengl.impl.windows.WindowsGLContext.create(WindowsGLContext.java:122)

at com.sun.opengl.impl.windows.WindowsGLContext.makeCurrentImpl(WindowsGLContext.ja
va:150)

at com.sun.opengl.impl.windows.WindowsOnscreenGLContext.makeCurrentImpl(WindowsOnsc
reenGLContext.java:66)

at com.sun.opengl.impl.GLContextImpl.makeCurrent(GLContextImpl.java:134)
Re: [Solved]GLException when create new java.awt.F
Reply #3 - Mar 3rd, 2009, 10:46am
 
hello oaragones,

you want to create something like tabbowser??
maybe i can help you. :-)

when you change the component of Frame with opengl, the rendering context and all the texture should be updated.
but so far, processing doesn't have this function, so you should make library to help it.

Code:

package processing.opengl;

import processing.core.PApplet;


public class GLContextReallocater {

public static void reallocate( PApplet p5){

if( p5.g.getClass().getName().equals( "processing.opengl.PGraphicsOpenGL" ) ){
((PGraphicsOpenGL)p5.g).context.release();
((PGraphicsOpenGL)p5.g).context.destroy();
((PGraphicsOpenGL)p5.g).context = null;
((PGraphicsOpenGL)p5.g).allocate();
}
}
}


Code:


package processing.core;

import processing.opengl.PGraphicsOpenGL;

public class GLTextureUpdater{

public static void update( PApplet p5 ){
if( p5.g.getClass().getName().equals( "processing.opengl.PGraphicsOpenGL" ) ){
PGraphicsOpenGL g = (PGraphicsOpenGL) p5.g;

PImage[] textures = g.textures;
for( int i = 0; i < textures.length; i++ ){
if( textures[i] != null ){
textures[i].updatePixels();
}
}
}
}
}



to use them, you simply call them.

GLContextReallocater.reallocate(p5);
GLTextureUpdater.update(p5);

you can download the library from below:

http://sadmb.com/archive/glupdater.zip


oaragones wrote on Feb 28th, 2009, 6:20pm:
Hi

I'm working with processing and opengl... but i have a problem with the Panel & Frames...

I have this code:

public class Browser {
private WebBrowser webBrowser;
private Panel panel;
private String url;
public Browser(PApplet p) {
Component tmpComp = p.frame.getComponent(p.frame.getComponentCount() - 1);
p.frame.remove(p.frame.getComponentCount() - 1);
p.frame.setLayout(new FlowLayout());
BrowserEngineManager mng = BrowserEngineManager.instance();
mng.setActiveEngine(BrowserEngineManager.IE);
webBrowser = new WebBrowser();
webBrowser.setSize(400, 300);
webBrowser.setLocation(0, 0);
webBrowser.setVisible(false);
panel = new Panel();
panel.setSize(400, 300);
panel.setLocation(50, 50);
panel.add(webBrowser);
panel.setVisible(true);
p.frame.add(panel);
p.frame.add(tmpComp);
}
}

and if i run it with size(1024,768);  it works well...

But the problem is when i try to run it with opengl... the same error from your sketch of fullscreen appear...

Some body knows what can i do Tnx!

The error is :

Exception in thread "Animation Thread" javax.media.opengl.GLException: Unable to create OpenGL context for device context 0x2a0123de

at com.sun.opengl.impl.windows.WindowsGLContext.create(WindowsGLContext.java:122)

at com.sun.opengl.impl.windows.WindowsGLContext.makeCurrentImpl(WindowsGLContext.ja
va:150)

at com.sun.opengl.impl.windows.WindowsOnscreenGLContext.makeCurrentImpl(WindowsOnsc
reenGLContext.java:66)

at com.sun.opengl.impl.GLContextImpl.makeCurrent(GLContextImpl.java:134)

Page Index Toggle Pages: 1