First, I got the JOGL plugin for NetBeans, started a stock project, and put the FBO code into the following class, which I kind “Javaized” from here
http://www.songho.ca/opengl/gl_fbo.html
Now, I can run the example at that web page, under the OpenGL Capabilities that Netbeans says I have is GL_ARB_framebuffer_object, and I have a NVIDIA 8800 GT that I figured would be high end enough.
But the following line prints 36061, which according to the documents is GL_FRAMEBUFFER_UNSUPPORTED_EXT.
System.out.println(gl.glCheckFramebufferStatusEXT(gl.GL_FRAMEBUFFER_EXT));
Have I done anything wrong here?
Class with my FBO code:
package org.yourorghere;
import java.nio.IntBuffer;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.glu.GLU;
public class GLRenderer implements GLEventListener {
private final int texture = 0, frame = 1;
private IntBuffer buffer;
public void init(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
System.err.println("INIT GL IS: " + gl.getClass().getName());
gl.setSwapInterval(1);
//fbo code
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glShadeModel(GL.GL_SMOOTH);
buffer = IntBuffer.allocate(2);
buffer.position(frame);
gl.glGenFramebuffersEXT(1, buffer);
gl.glBindFramebufferEXT(gl.GL_FRAMEBUFFER_EXT, buffer.get(frame));
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glShadeModel(GL.GL_SMOOTH);
buffer.position(texture);
gl.glGenTextures(1, buffer);
gl.glBindTexture( gl.GL_TEXTURE_2D, buffer.get(texture));
gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_RGBA, 512, 512, 0, gl.GL_RGBA, gl.GL_INT, null);
gl.glFramebufferTexture2DEXT(gl.GL_FRAMEBUFFER_EXT, gl.GL_COLOR_ATTACHMENT0_EXT, gl.GL_TEXTURE_2D, buffer.get(texture), 0);
System.out.println(gl.glCheckFramebufferStatusEXT(gl.GL_FRAMEBUFFER_EXT));
gl.glMatrixMode(gl.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrtho(0, 512, 512, 0, -1, 1);
gl.glMatrixMode(gl.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glBegin(gl.GL_TRIANGLES);
gl.glColor3f(1, 0, 0);
gl.glVertex2f(256, 0);
gl.glColor3f(0, 1, 0);
gl.glVertex2f(512, 512);
gl.glColor3f(0, 0, 1);
gl.glVertex2f(0, 512);
gl.glEnd();
gl.glBindFramebufferEXT(gl.GL_FRAMEBUFFER_EXT, 0);
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glShadeModel(GL.GL_SMOOTH);
}
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
GL gl = drawable.getGL();
GLU glu = new GLU();
if (height <= 0) {
height = 1;
}
final float h = (float) width / (float) height;
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(45.0f, h, 1.0, 20.0);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
}
public void display(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glTranslatef(-1.5f, 0.0f, -6.0f);
gl.glBegin(GL.GL_TRIANGLES);
gl.glColor3f(1.0f, 0.0f, 0.0f);
gl.glVertex3f(0.0f, 1.0f, 0.0f);
gl.glColor3f(0.0f, 1.0f, 0.0f);
gl.glVertex3f(-1.0f, -1.0f, 0.0f);
gl.glColor3f(0.0f, 0.0f, 1.0f);
gl.glVertex3f(1.0f, -1.0f, 0.0f);
gl.glEnd();
gl.glTranslatef(3.0f, 0.0f, 0.0f);
gl.glBegin(GL.GL_QUADS);
gl.glColor3f(0.5f, 0.5f, 1.0f);
gl.glVertex3f(-1.0f, 1.0f, 0.0f);
gl.glVertex3f(1.0f, 1.0f, 0.0f);
gl.glVertex3f(1.0f, -1.0f, 0.0f);
gl.glVertex3f(-1.0f, -1.0f, 0.0f);
gl.glEnd();
gl.glFlush();
}
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
}
}
And if you need it, the main class that NetBeans made:
package org.yourorghere;
import com.sun.opengl.util.Animator;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLCapabilities;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPopupMenu;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.UIManager;
import javax.swing.WindowConstants;
public class FBOtest extends JFrame {
static {
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
}
private Animator animator;
public FBOtest() {
initComponents();
setTitle("Simple JOGL Application");
canvas.addGLEventListener(new GLRenderer());
animator = new Animator(canvas);
canvas.setMinimumSize(new Dimension());
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
new Thread(new Runnable() {
public void run() {
animator.stop();
System.exit(0);
}
}).start();
}
});
}
@Override
public void setVisible(boolean show){
if(!show)
animator.stop();
super.setVisible(show);
if(!show)
animator.start();
}
@SuppressWarnings("unchecked")
private void initComponents() {
JLabel label = new JLabel();
canvas = new GLCanvas(createGLCapabilites());
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
label.setText("Below you see a GLCanvas");
GroupLayout layout = new GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(Alignment.LEADING)
.addComponent(canvas, GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
.addComponent(label))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(label)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(canvas, GroupLayout.DEFAULT_SIZE, 255, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}
private GLCapabilities createGLCapabilites() {
GLCapabilities capabilities = new GLCapabilities();
capabilities.setHardwareAccelerated(true);
capabilities.setNumSamples(2);
capabilities.setSampleBuffers(true);
return capabilities;
}
public static void main(String args[]) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch(Exception ex) {
Logger.getLogger(getClass().getName()).log(Level.INFO, "can not enable system look and feel", ex);
}
FBOtest frame = new FBOtest();
frame.setVisible(true);
}
});
}
private GLCanvas canvas;
}