import net.java.games.jogl.;
import javax.swing.;
public class PBufferTestApp implements GLEventListener
{
private GL gl;
private GLU glu;
private GLDrawable gldrawable;
private int textureHandle;
private JFrame frame;
private final Animator animator;
GLPbuffer pbuffer;
private class PBufferEventListener implements GLEventListener {
private float counter = 0;
private float r=0;
private float g=0;
private float b=0;
public void init(GLDrawable drawable) {
System.out.println("+PBUFFER INIT");
}
public void display(GLDrawable drawable) {
//System.out.println("+PBUFFER DISPLAY "+counter);
r = (float) Math.sin( (counter % 100) * 0.01f * 2.0f *3.1415f) ;
g = (float) Math.cos( (counter % 100) * 0.01f * 2.0f *3.1415f) ;
b= (float) Math.tan( (counter % 100) * 0.01f * 2.0f *3.1415f) ;
counter+=0.1f;
//clamp from [0,1]
r += 1.0f;
r *= 0.5f;
g += 1.0f;
g *= 0.5f;
b += 1.0f;
b *= 0.5f;
gl.glClearColor(r,g,b, 1);
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glFlush();
}
public void reshape(GLDrawable drawable, int x, int y, int width, int height)
{
System.out.println("+PBUFFER RESHAPE");
float h = (float)height / (float)width;
gl.glViewport(0,0,width,height);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluOrtho2D(0,0,1,1);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
}
public void displayChanged(GLDrawable drawable, boolean modeChanged, boolean deviceChanged) {}
}
public static void main(String args[])
{
PBufferTestApp remoteRenderer = new PBufferTestApp();
}
PBufferTestApp()
{
frame = new JFrame("Bah");
GLCapabilities attributes = new GLCapabilities();
GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas(attributes);
canvas.addGLEventListener(this);
frame.setFocusable(true);
frame.getContentPane().add(canvas);
animator = new Animator(canvas);
frame.show();
System.out.println("Initalized GUI");
animator.start();
frame.setSize(300, 300);
}
public void init(GLDrawable drawable)
{
gl = drawable.getGL();
glu = drawable.getGLU();
this.gldrawable = drawable;
System.err.println("INIT GL IS: " + gl.getClass().getName());
if (gl.isExtensionAvailable("WGL_ARB_pbuffer"))
{
System.out.println("PBUFFER SUPPORTED");
}
else
{
System.out.println("PBUFFER NOT SUPPORT");
}
boolean supported = drawable.canCreateOffscreenDrawable();
GLCapabilities caps = new GLCapabilities();
caps.setOffscreenRenderToTexture(true);
caps.setDoubleBuffered(false);
if(!supported)
{
System.err.println("PBuffers not supported, shadow mapping not available");
return;
}
pbuffer = drawable.createOffscreenDrawable(caps, 512, 512);
pbuffer.addGLEventListener(new PBufferEventListener());
System.err.println("Pbuffer created");
pbuffer.display();
int temp[] = new int[1];
gl.glGenTextures(1, temp);
textureHandle =temp[0];
gl.glBindTexture(GL.GL_TEXTURE_2D, textureHandle);
pbuffer.bindTexture();
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE);
// gl.glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
}
public void reshape(GLDrawable drawable, int x, int y, int width, int height)
{
float h = (float)height / (float)width;
gl.glViewport(0,0,width,height);
System.out.println("WINDOW SIZE " + width + " " + width);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(45.0f, 1.0f, 0.1f, 1000.0f);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
}
public void display(GLDrawable drawable)
{
pbuffer.display();
gl.glClearColor(0,0,0,1);
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glPushMatrix();
//loadCamera()
gl.glEnable(GL.GL_TEXTURE_2D);
gl.glBindTexture(GL.GL_TEXTURE_2D, textureHandle);
pbuffer.bindTexture();
gl.glBegin(GL.GL_QUADS);
gl.glColor3f(1,1,1);
gl.glTexCoord2f(0,0);
gl.glVertex3i(-5, -5, -15);
gl.glTexCoord2f(1,0);
gl.glVertex3i( 5, -5, -15);
gl.glTexCoord2f(1,1);
gl.glVertex3i( 5, 5, -15);
gl.glTexCoord2f(0,1);
gl.glVertex3i(-5, 5, -15);
gl.glEnd();
gl.glDisable(GL.GL_TEXTURE_2D);
gl.glPopMatrix();
}
public void displayChanged(GLDrawable drawable, boolean modeChanged, boolean deviceChanged) {}
}