With pbuffers i made it work. This is the code.
Let me know if there is a better way.
Thx
package util.studio;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLDrawableFactory;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLPbuffer;
import com.sun.opengl.util.texture.Texture;
import com.sun.opengl.util.texture.TextureCoords;
import com.sun.opengl.util.texture.TextureIO;
public class ProvaPBuffer {
GLPbuffer pbuffer;
GLCanvas glCanvas;
Frame frame;
boolean fullscreen;
Dimension size;
Point location;
Texture texture;
TextureCoords coords;
public ProvaPBuffer() {
pbuffer = GLDrawableFactory.getFactory().createGLPbuffer(new GLCapabilities(), null, 512, 512, null);
pbuffer.addGLEventListener(new GLEventListener() {
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
}
public void init(GLAutoDrawable drawable) {
try {
texture = TextureIO.newTexture(new File("gfx/fungo.png"), true);
coords = texture.getImageTexCoords();
} catch (Exception e) {
e.printStackTrace();
}
}
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
}
public void display(GLAutoDrawable drawable) {
}
});
pbuffer.display();
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gd = env.getScreenDevices();
GLCapabilities glc = new GLCapabilities();
glCanvas = new GLCanvas(glc, null, pbuffer.getContext(), gd[0]);
glCanvas.addGLEventListener(new GLEventListener() {
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
}
public void init(GLAutoDrawable drawable) {
}
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
}
public void display(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
gl.glLoadIdentity();
gl.glEnable(GL.GL_BLEND);
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
texture.enable();
texture.bind();
gl.glBegin(GL.GL_QUADS);
gl.glTexCoord2f(coords.left(), coords.bottom());
gl.glVertex2f(-1, -1);
gl.glTexCoord2f(coords.left(), coords.top());
gl.glVertex2f(-1, 1);
gl.glTexCoord2f(coords.right(), coords.top());
gl.glVertex2f(1, 1);
gl.glTexCoord2f(coords.right(), coords.bottom());
gl.glVertex2f(1, -1);
gl.glEnd();
}
});
}
void showGui() {
glCanvas.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
System.exit(0);
}
setFullScreen(!fullscreen);
}
});
frame = new Frame("PorcaProva");
frame.add(glCanvas);
frame.setBounds(100, 100, 300, 400);
frame.setVisible(true);
glCanvas.requestFocus();
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
public void setFullScreen(boolean fullScreen) {
this.fullscreen = fullScreen;
frame.dispose();
size = Toolkit.getDefaultToolkit().getScreenSize();
if (fullScreen) {
frame.setUndecorated(true);
location = new Point(0, 0);
} else {
frame.setUndecorated(false);
location = new Point((size.width - 300) / 2, (size.height - 400) / 2);
size = new Dimension(300, 400);
}
frame.setSize(size);
frame.setLocation(location);
frame.setVisible(true);
glCanvas.requestFocus();
}
public static void main(String[] args) {
ProvaPBuffer p = new ProvaPBuffer();
p.showGui();
}
}