Hello,
I try to do layered rendering with framebuffers but I have trouble.
I try to implement cubemap (render to texture) but it doesn’t work like expected. All I get is a black cubemap I don’t understand why.
What I want is to dynamically change the texture (like wave simulation, etc…)
this is how I initialize a texture :
glGenTextures(1, &texture_cubemap);
glBindTexture(GL_TEXTURE_CUBE_MAP, texture_cubemap);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_FLOAT, NULL);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_FLOAT, NULL);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_FLOAT, NULL);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_FLOAT, NULL);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_FLOAT, NULL);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_FLOAT, NULL);
glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
the framebuffer:
glGenFramebuffers(1, &_fbo);
glBindFramebuffer(GL_FRAMEBUFFER, _fbo);
for(i = 0; i < 6; i++)
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0+i, GL_TEXTURE_CUBE_MAP_POSITIVE_X+i, texture_cubemap, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
And my shaders :
The vertex shader :
#version 330
layout (location = 0) in vec3 positionsPoints;
uniform mat4 modelMatrix;
uniform mat4 viewMatrix;
uniform mat4 projectionMatrix;
void main(){
gl_Position = vec4(positionsPoints, 1);
}
The geometry shader with gl_layer :
#version 330
layout(points) in;
layout(points, max_vertices = 1) out;
uniform mat4 projectionMatrix;
//out vec3 fsotexCoord;
out vec4 colorPoint;
void main(void) {
int i, layer;
for (layer = 0; layer < 6; layer++) {
gl_Layer = layer;
for (i = 0; i < gl_in.length(); i++) {
gl_Position = gl_in[0].gl_Position;//vec4(, 1);//projectionMatrix *
colorPoint = vec4(1, 0, 0, 1);
EmitVertex();
}
EndPrimitive();
}
}
and the fragment :
#version 330
in vec4 colorPoint;
out vec4 fragColor;
void main() {
fragColor = colorPoint;
}
If I set an array of vertices in glTexImage2D (instead of NULL) I have something but that mean that gl_layer doesn’t work and I don’t understand why…
Thanks for the help.