Frame Buffer Object exceptions

Here’s my FBO class (sorry for the code dumb, thought it was necessary):

package ecumene.opengl.frame;

import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL30;
import org.lwjgl.opengl.Util;

import ecumene.EcuException;
import ecumene.opengl.texture.Texture;

/**
 * Framebuffer Objects are OpenGL Objects, which allow for the creation of user-defined Framebuffers. With them, 
 * one can render to non-Default Framebuffer locations, and thus render without disturbing the main screen.
 * 
 * @see IFrameBuffer
 * 
 * @author Ecumene
 */
public class Frame implements IFrame {
	private int frame;
	private Texture parent;
	
	public Frame() {
		frame = GL30.glGenFramebuffers();
		Util.checkGLError();
	}
	
	@Override
	public void bind() {
		GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, frame);
		Util.checkGLError();
	}
	
	@Override
	public void begin(int width, int height) {
		if(frame == 0) throw new EcuException("FBO was destroyed");
		GL11.glViewport(0, 0, width, height);
		GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, frame);
		Util.checkGLError();
	}

	@Override
	public void end(int width, int height) {
		if(frame == 0) return;
		GL11.glViewport(0, 0, width, height);
		GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
		Util.checkGLError();
	}
	
	@Override
	public void bufferTexture(Texture texture, int attachment) {
		this.parent = texture;
		
		bind();
		texture.bind();
		GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, attachment, texture.getTarget(), texture.getID(), 0);
		bindNone();
		
		Util.checkGLError();
	}

	@Override
	public int getStatus() {
		bind();
		int status = GL30.glCheckFramebufferStatus(frame);
		bindNone();
                Util.checkGLError();
		return status;
	}
	
	@Override
	public void destroy() {
		bindNone();
		GL30.glDeleteFramebuffers(frame);
		frame = 0;
		Util.checkGLError();
	}
	
	/** @return The FBO's texture object */
	public Texture getTexture(){
		return parent;
	}
	
	protected static void bindNone(){
		GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
	}
}

I’m initializing it like this:

frame = new Frame();
frame.bufferTexture(new Texture(GL11.GL_TEXTURE_2D), EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT);

Then I never use it again. But the weird thing is, [icode]frame.getStatus()[/icode] is causing a ‘invalid enum (1280)’ error. And when I remove that line, and use the begin() method, it says that a glUniform call is causing an invalid operation error… I’m checking for OpenGL errors in the begin(), so it should be throwing the error there, right?

I’m still very new to the frame buffer object stuff. Thanks in advance!

just from checking https://www.opengl.org/wiki/GLAPI/glCheckFramebufferStatus :

[quote]GL_INVALID_ENUM​ is generated if target​ is not GL_DRAW_FRAMEBUFFER​, GL_READ_FRAMEBUFFER​ or GL_FRAMEBUFFER​.
[/quote]
doesn’t make sense with the code, which looks ok to me. you’re doing it the right way :

  • gen frame buffer
  • bind frame buffer
  • set texture attachment
  • check status
  • unbind

:clue:

edit

btw, you do not need to bind the texture when attaching it to a fbo.

maybe it helps if you verify this :

attachment-number, is it just something like [icode]0 1 2 3[/icode] or do you add [icode]GL30.GL_COLOR_ATTACHMENT0[/icode] somewhere else … or do you always use the static GL_COLOR_ATTACHMENT0/1/2/3/… numbers ?

if attachment is an int like [icode]0 1 2 3[/icode], the correct way is

[icode]GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER,GL30.GL_COLOR_ATTACHMENT0 + attachment,texture.getTarget(), texture.getID(),0);[/icode]

wrong would be :

[icode]GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER,attachment, texture.getTarget(), texture.getID(),0);[/icode]

o/

Here’s my texture FBO/Texture object setup:

Texture tempTexture = new Texture(GL11.GL_TEXTURE_2D);
tempTexture.bind();
GL42.glTexStorage2D(GL11.GL_TEXTURE_2D, 1, GL11.GL_RGBA8, 512, 512);

frame = new Frame();
frame.bind();
frame.bufferTexture(tempTexture, GL30.GL_COLOR_ATTACHMENT0);

And my render method (I got desperate and used immediate mode/fixed function matrices):

// Clear color (white)
GL30.glClearBuffer(GL11.GL_COLOR, 0, clearColor);

// OGL fixed function matrices setup 
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0, Window.getWidth(), Window.getHeight(), 0, -1, 1);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();

frame.begin(512, 512);
// Clear color (white)
GL30.glClearBuffer(GL11.GL_COLOR, 0, clearColor);

// Begin rendering quad (yellow, 20x20)
GL11.glBegin(GL11.GL_QUADS);
	GL11.glVertex2f(0,  0);  GL11.glColor3f(1, 1, 0);
	GL11.glVertex2f(20, 0);  GL11.glColor3f(1, 1, 0);
	GL11.glVertex2f(20, 20); GL11.glColor3f(1, 1, 0);
	GL11.glVertex2f(0,  20); GL11.glColor3f(1, 1, 0);
GL11.glEnd();

frame.end(Window.getWidth(), Window.getHeight());		

// Begin rendering quad (textured, 512x512)
frame.getTexture().bind();
GL11.glBegin(GL11.GL_QUADS);
	GL11.glVertex2f(0,   0);   GL11.glTexCoord2f(0, 0);
	GL11.glVertex2f(512, 0);   GL11.glTexCoord2f(1, 0);
	GL11.glVertex2f(512, 512); GL11.glTexCoord2f(1, 1);
	GL11.glVertex2f(0,   512); GL11.glTexCoord2f(0, 1);
GL11.glEnd();

Product (800x600) window