Hi!
I wrote a small application with what I could understood from
HDR demo and PBuffer javadocs. The program runs well on xp machines
but shows garbage on Emac.
Am I doing something wrong? Or PBuffers are not yet supported on macs?
Here is the app:
package test;
import javax.media.opengl.*;
import java.awt.*;
import java.awt.event.*;
public class Test implements GLEventListener {
private GLCanvas canvas;
private int sizex = 256, sizey = 256;
private GLPbuffer pbuffer ;
public static void main(String[] args) {
new Test();
}
Test() {
create_window();
create_pbuffer();
while(true) {
canvas.display();
Thread.yield();
}
}
private void create_window() {
GLCapabilities caps = new GLCapabilities();
caps.setRedBits(8);
caps.setGreenBits(8);
caps.setBlueBits(8);
caps.setAlphaBits(8);
caps.setDepthBits(24);
canvas = new GLCanvas(caps);
canvas.addGLEventListener(this);
Frame frame = new Frame("test");
frame.setLayout(new BorderLayout());
canvas.setSize(sizex, sizey);
frame.add(canvas, BorderLayout.CENTER);
frame.pack();
canvas.setFocusable(true);
canvas.requestFocus();
frame.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(WindowEvent winEvt) {
System.exit(0);
}
});
frame.setVisible(true);
}
private void create_pbuffer()
{
if (!GLDrawableFactory.getFactory().canCreateGLPbuffer()) {
System.out.println("!canCreateGLPbuffer");
System.exit(-1);
}
GLCapabilities caps = new GLCapabilities();
caps.setHardwareAccelerated(true);
caps.setDoubleBuffered(false);
caps.setPbufferFloatingPointBuffers(false);
caps.setRedBits(8);
caps.setGreenBits(8);
caps.setBlueBits(8);
caps.setAlphaBits(8);
caps.setDepthBits(24);
//caps.setPbufferRenderToTextureRectangle(true); // doesn't work
caps.setPbufferRenderToTexture(true);
pbuffer = GLDrawableFactory.getFactory().createGLPbuffer(caps, null, 128, 128, canvas.getContext());
pbuffer.addGLEventListener(new PBufferListener());
}
public void init(GLAutoDrawable drawable){ }
public void reshape(GLAutoDrawable drawable, int x1, int y1, int x2, int y2) {
sizex = x2-x1;
sizey = y2-y1;
}
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged){}
public void display(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glViewport(0, 0, sizex, sizey);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrtho(0, sizex, 0, sizey, -1, 1);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
if (pbuffer == null)
return;
pbuffer.display();
pbuffer.bindTexture();
gl.glEnable(GL.GL_TEXTURE_2D);
gl.glBegin(GL.GL_QUADS);
gl.glTexCoord2f(0, 0); gl.glVertex2f(0, 0);
gl.glTexCoord2f(1, 0); gl.glVertex2f(sizex, 0);
gl.glTexCoord2f(1, 1); gl.glVertex2f(sizex, sizey);
gl.glTexCoord2f(0, 1); gl.glVertex2f(0, sizey);
gl.glEnd();
pbuffer.releaseTexture();
}
}
class PBufferListener implements GLEventListener {
public void init(GLAutoDrawable drawable){ }
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged){}
public void reshape(GLAutoDrawable drawable, int x1, int y1, int x2, int y2) { }
public void display(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glViewport(0, 0, 128, 128);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrtho(0, 128, 0, 128, -1, 1);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glColor3f(1,1,1);
gl.glTranslatef(64, 64, 0);
gl.glRotatef(45, 0, 0, 1);
gl.glRectf(-50, -50, 50, 50);
}
}