Hello everybody!
First I’m french so please don’t be hard with my english
So my problem is when I draw multiple cube in the default framebuffer (so the screen) it render with a good depth testing and when I render in a framebuffer and then i render the texture in witch i have drawn my cubes it render 2D triangles. I really don’t understand why :/…
images are in the third post
GLuint framebuffertest,tex1,tex2;
glGenFramebuffers(1,&framebuffertest);
glGenTextures(1,&tex1);
glGenTextures(1,&tex2);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER,framebuffertest);
glBindTexture(GL_TEXTURE_2D,tex1);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,1024,768,0,GL_RGB,GL_FLOAT,NULL);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,tex1,0);
glBindTexture(GL_TEXTURE_2D,tex2);
glTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT,1024,768,0,GL_DEPTH_COMPONENT,GL_FLOAT,NULL);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D,tex2,0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER,0);
-------------------------------------------------------------------------------------------------
//render cube off screen
glBindFramebuffer(GL_DRAW_FRAMEBUFFER,framebuffertest);
glDrawBuffers(1,buffs);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
mainShader.useShader();
glBindTexture(GL_TEXTURE_BUFFER,textureBufferModel);
cube.drawInstanced(NB_CUBE,36,GL_TRIANGLES);
/************************************************/
//render the texture
glBindFramebuffer(GL_DRAW_FRAMEBUFFER,0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D,tex1);
graussianBlurShader.useShader();
drawScreen.draw(4,GL_TRIANGLE_STRIP);
glBindTexture(GL_TEXTURE_2D,0);
/************************************************/
//render directly the cube on the screen
/*glBindFramebuffer(GL_DRAW_FRAMEBUFFER,0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glBindTexture(GL_TEXTURE_BUFFER,textureBufferModel);
mainShader.useShader();
cube.drawInstanced(NB_CUBE,36,GL_TRIANGLES);*/
/************************************************/
glFinish();
window->swapBuffers();
mainShader :
vertex shader
#version 330
layout(std140,binding = 0) uniform Matrice
{
mat4 projection;
mat4 view;
}Matrice;
layout(binding = 0) uniform samplerBuffer modelMatrice;
in vec4 vertex_vs;
out vec3 color_fs;
void main()
{
mat4 model;
vec3 color;
int i;
vec4 tmp[4];
for(i = 0 ; i < 16 ; i++)
{
tmp[(i/4)][i%4] = texelFetch(modelMatrice,gl_InstanceID*19 + i).x;
}
model[0] = tmp[0];
model[1] = tmp[1];
model[2] = tmp[2];
model[3] = tmp[3];
for(i = 0 ; i < 3 ; i++)
{
color[i] = texelFetch(modelMatrice,gl_InstanceID*19 + 16 + i).x;
}
color_fs = color;
gl_Position = Matrice.projection * Matrice.view * model * vertex_vs;
}
fragment shader
#version 330
in vec3 color_fs;
out vec3 color_pixel;
void main()
{
color_pixel = color_fs;
}
graussianblurshader (witch is realy not a graussian blur but it will be int futur )
vertex shader
#version 330
in vec2 vertex_vs;
in vec2 coords_vs;
out vec2 coords_fs;
void main()
{
coords_fs = coords_vs;
gl_Position.xy = vertex_vs;
}
fragment shader
#version 330
out vec4 color_pixel;
uniform sampler2D textureToBlur;
in vec2 coords_fs;
void main()
{
color_pixel = texture2D(textureToBlur,coords_fs);
}
I don’t give you all my code but if you want it ask and i’ll give you.
Thanks,
Jedi768
GPU : ATI HD 6850
Opengl : 3.3 core