Sunday, 15 September 2013

OpenGL FrameBuffer texture error

OpenGL FrameBuffer texture error

i tried to find a reason for my Problem but i could not find anything like
that in the Internet.
My Problem is the framebuffer or his texture.
It Looks something like a White texture with randomly generated black
Points, they Change the Position when i add for example
"glClearColor(0,0,0,0);".
Here is a direct link to the Image, it is uploadet to ImageShack
Image
Here is my FrameBufferObj.java
public int buffId;
public int tex_0;
public int depth_tex;
public int width;
public int height;
ByteBuffer buf = BufferUtils.createByteBuffer(1);
public void createFrameBuffer(int width, int height)
{
this.width = width;
this.height = height;
buffId = glGenFramebuffersEXT();
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, buffId);
/*init color texture*/
tex_0 = glGenTextures();
glBindTexture(GL_TEXTURE_2D, tex_0);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA,
GL_UNSIGNED_BYTE, (java.nio.ByteBuffer)null);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glBindTexture(GL_TEXTURE_2D, 0);
/*init depth texture*/
depth_tex = glGenRenderbuffersEXT();
glBindTexture(GL_TEXTURE_2D, depth_tex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, width, height,
0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, (java.nio.ByteBuffer)null);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE,
GL_COMPARE_R_TO_TEXTURE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LESS);
glBindTexture(GL_TEXTURE_2D, 0);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, buffId);
// Associate the depth and color rendering textures to the FBO
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, tex_0, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, depth_tex, 0);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
int framebuffer = glCheckFramebufferStatusEXT( GL_FRAMEBUFFER_EXT );
switch ( framebuffer ) {
case GL_FRAMEBUFFER_COMPLETE_EXT:
break;
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
throw new RuntimeException( "FrameBuffer: " + buffId
+ ", has caused a
GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT exception" );
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
throw new RuntimeException( "FrameBuffer: " + buffId
+ ", has caused a
GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
exception" );
case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
throw new RuntimeException( "FrameBuffer: " + buffId
+ ", has caused a
GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT exception" );
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
throw new RuntimeException( "FrameBuffer: " + buffId
+ ", has caused a
GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT exception"
);
case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
throw new RuntimeException( "FrameBuffer: " + buffId
+ ", has caused a
GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT exception" );
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
throw new RuntimeException( "FrameBuffer: " + buffId
+ ", has caused a
GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT exception"
);
default:
throw new RuntimeException( "Unexpected reply from
glCheckFramebufferStatusEXT: " + framebuffer );
}
}
public void bind()
{
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, buffId);
}
public void unbind()
{
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
}
public ByteBuffer getPixelColor(int x, int y)
{
buf = BufferUtils.createByteBuffer(3);
glReadPixels(x, y, 1, 1, GL_BGR, GL_UNSIGNED_BYTE, buf);
return buf;
}
public ByteBuffer getTexture()
{
buf = BufferUtils.createByteBuffer(width * height);
glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
glReadPixels(0, 0, width, height, GL_BGR, GL_UNSIGNED_BYTE, buf);
return buf;
}
}
And here is how i call it
public void preRenderPicking()
{
picker_screen.bind();
GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
GL11.glClearDepth(1.0f);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
camera.applyPerspectiveMatrix();
GL11.glLoadIdentity();
picking_colorizer.enableShader();
picker.processPicking(picking_colorizer,renderables);
picking_colorizer.disableShader();
updatePickedObject(Mouse.getX(), Mouse.getY());
picker_screen.unbind();
}
Then i just created the final quad with the framebuffer texture (look at
the Image)
When i remove the quad renderer there is just a black Screen.
Thanks for helping =)

No comments:

Post a Comment