Sign in to follow this  
rgc183

Unexpected behaviour with glFramebufferTexture1D

Recommended Posts

I am using render to texture concept with glFramebufferTexture1D. I am drawing a cube on non-default FBO with all the vertices as -1,1 (maximum) in X Y Z direction. Now i am setting viewport to X while rendering on non default FBO. My background is blue with white color of cube.
For default FBO, i have created 1-D texture and attached this texture to above FBO with color attachment. I am setting width of texture equal to width*height of above FBO view-port. Now, when i render this texture to on another cube, i can see continuous white color on start or end of each face of the cube. That means part of the face is white and rest is blue. I am not sure whether this behavior is correct or not. I expect all the texels should be white as i am using -1 and 1 coordinates for cube rendered on non-default FBO.
[code]

#define WIDTH 3
#define HEIGHT 3
GLfloat vertices8[]={
1.0f,1.0f,1.0f,
-1.0f,1.0f,1.0f,
-1.0f,-1.0f,1.0f,
1.0f,-1.0f,1.0f,//face 1
1.0f,-1.0f,-1.0f,
-1.0f,-1.0f,-1.0f,
-1.0f,1.0f,-1.0f,
1.0f,1.0f,-1.0f,//face 2
1.0f,1.0f,1.0f,
1.0f,-1.0f,1.0f,
1.0f,-1.0f,-1.0f,
1.0f,1.0f,-1.0f,//face 3
-1.0f,1.0f,1.0f,
-1.0f,1.0f,-1.0f,
-1.0f,-1.0f,-1.0f,
-1.0f,-1.0f,1.0f,//face 4
1.0f,1.0f,1.0f,
1.0f,1.0f,-1.0f,
-1.0f,1.0f,-1.0f,
-1.0f,1.0f,1.0f,//face 5
-1.0f,-1.0f,1.0f,
-1.0f,-1.0f,-1.0f,
1.0f,-1.0f,-1.0f,
1.0f,-1.0f,1.0f//face 6

};
GLfloat vertices[]=
{
0.5f,0.5f,0.5f,
-0.5f,0.5f,0.5f,
-0.5f,-0.5f,0.5f,
0.5f,-0.5f,0.5f,//face 1
0.5f,-0.5f,-0.5f,
-0.5f,-0.5f,-0.5f,
-0.5f,0.5f,-0.5f,
0.5f,0.5f,-0.5f,//face 2
0.5f,0.5f,0.5f,
0.5f,-0.5f,0.5f,
0.5f,-0.5f,-0.5f,
0.5f,0.5f,-0.5f,//face 3
-0.5f,0.5f,0.5f,
-0.5f,0.5f,-0.5f,
-0.5f,-0.5f,-0.5f,
-0.5f,-0.5f,0.5f,//face 4
0.5f,0.5f,0.5f,
0.5f,0.5f,-0.5f,
-0.5f,0.5f,-0.5f,
-0.5f,0.5f,0.5f,//face 5
-0.5f,-0.5f,0.5f,
-0.5f,-0.5f,-0.5f,
0.5f,-0.5f,-0.5f,
0.5f,-0.5f,0.5f//face 6
};
GLuint indices[] =
{
0, 2, 1,
0, 3, 2,
4, 5, 6,
4, 6, 7,
8, 9, 10,
8, 10, 11,
12, 15, 14,
12, 14, 13,
16, 17, 18,
16, 18, 19,
20, 23, 22,
20, 22, 21
};

GLfloat texcoord[] =
{
0.0, 0.0,
1.0, 0.0,
1.0, 1.0,
0.0, 1.0,
0.0, 0.0,
1.0, 0.0,
1.0, 1.0,
0.0, 1.0,
0.0, 0.0,
1.0, 0.0,
1.0, 1.0,
0.0, 1.0,
0.0, 0.0,
1.0, 0.0,
1.0, 1.0,
0.0, 1.0,
0.0, 0.0,
1.0, 0.0,
1.0, 1.0,
0.0, 1.0,
0.0, 0.0,
1.0, 0.0,
1.0, 1.0,
0.0, 1.0
};
glGenTextures(1, &id1);
glBindTexture(GL_TEXTURE_1D, id1);
glGenFramebuffers(1, &Fboid);
glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, WIDTH*HEIGHT , 0, GL_RGBA, GL_UNSIGNED_BYTE,0);
glBindFramebuffer(GL_FRAMEBUFFER, Fboid);
glFramebufferTexture1D(GL_DRAW_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_1D,id1,0);

draw_cube();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
draw();
}
draw_cube()
{
glViewport(0, 0, WIDTH, HEIGHT);
glClearColor(0.0f, 0.0f, 0.5f, 1.0f);

glClear(GL_COLOR_BUFFER_BIT);
glEnableVertexAttribArray(glGetAttribLocation(temp.psId,"position"));
glVertexAttribPointer(glGetAttribLocation(temp.psId,"position"), 3, GL_FLOAT, GL_FALSE, 0,vertices8);
glDrawArrays (GL_TRIANGLE_FAN, 0, 24);
}
draw()
{
glClearColor(1.0f, 0.0f, 0.0f, 1.0f);

glClearDepth(1.0f);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnableVertexAttribArray(glGetAttribLocation(shader_data.psId,"tk_position"));
glVertexAttribPointer(glGetAttribLocation(shader_data.psId,"tk_position"), 3, GL_FLOAT, GL_FALSE, 0,vertices);
nResult = GL_ERROR_CHECK((GL_NO_ERROR, "glVertexAttribPointer(position, 3, GL_FLOAT, GL_FALSE, 0,vertices);"));
glEnableVertexAttribArray(glGetAttribLocation(shader_data.psId,"inputtexcoord"));
glVertexAttribPointer(glGetAttribLocation(shader_data.psId,"inputtexcoord"), 2, GL_FLOAT, GL_FALSE, 0,texcoord);
glBindTexture(*target11, id1);
glDrawElements ( GL_TRIANGLES, 36,GL_UNSIGNED_INT, indices );
}
[/code]

when i change WIDTH=HEIGHT=2, and call a glreadpixels with height, width equal to 4 in draw_cube() i can see first 2 pixels with white color, next two with blue(glclearcolor), next two white and then blue and so on.. Now when i change width parameter in glTeximage1D to 16 then ideally i should see alternate patches of white and blue right? But its not the case here.
Please help me out ...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this