Sorry, I thought it would be easier to read the code with the syntax highlights that IntelliJ provide.
So do you want to render depth to a renderbuffer or to the texture?
I want to render depth to texture so I can use it for SSAO and lightcalculations.
The call passes 0 for the texture object
Should the last argument be the depth texture id, not the 4th one ?
This is the code I currently have:
GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, fbo);
for (int i = 0; i < textures.length; i++) {
glBindTexture(GL_TEXTURE_2D, textures[i]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
GL11.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA,
GL_UNSIGNED_BYTE, (ByteBuffer) null);
GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0 + i, GL11.GL_TEXTURE_2D, textures[i], 0);
}
//depth texture
glBindTexture(GL_TEXTURE_2D, depth);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, (ByteBuffer) null);
GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL_DEPTH_COMPONENT, depth, 0);
IntBuffer db = Utils.createIntBuffer(2);
db.put(GL30.GL_COLOR_ATTACHMENT0);
db.put(GL30.GL_COLOR_ATTACHMENT1);
db.flip();
GL20.glDrawBuffers(db);
int Status = GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER);
if (Status != GL30.GL_FRAMEBUFFER_COMPLETE) {
System.out.println("ERROR: FrameBuffer: " + fbo + " din't complete !" + Utils.glError(Status));
}
// restore default FBO
GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
I get a black texture instead of depth and no depth testing and error GL_INVALID_OPERATION, 0x0502 shows up (I think 0x0502 shows up because of my mesh code) and I get error GL_INVALID_VALUE 0x0501 too…