Original Post
Hi All, I want to do Render-to-Texture using pbuffers. I tried the following without using pbuffers and if works fine. I draw a red quad bigger than the size of my screen and copy the framebuffer values to a texture. I then clear the screen to Grey. Now I render a green triangle and use the previously created texture on the triangle. I get a red triangle, which is correct. Now I tried the same thing using pbuffer. I create a pbuffer and make it the current rendering context. I render the red quad to the pbuffer. Now, I make the window the current rendering context and bind the pbuffer to a texture. I then draw the green triangle and use the previously created texture on it. I should be getting a red triangle here too. But I don't. Sometimes,I get a green triangle & half green and half black triangle some other time. I don't know whats happening. I am including my code here. It would be great someone can help me out in this. Program without using pBuffer: Here's the LoadGLTextures() method Here is the code using pbuffers: The pbufferEnable(), pbufferDisable(), and pbufferBind are from ATI's pbuffer demo. My window size is also 512,512. I am initializing the pbuffer in my InitGL() method. Thank you, Sriram
void Draw (void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor (0.5f, 0.5f, 0.5f, 1.0f);
glClearDepth (1.0f);
glLoadIdentity();
gluLookAt(0.0f,0.0f,50.0f,0.0f,0.0f,0.0f,0,1,0);
glColor3f(1.0,0.0,0.0);
glBegin(GL_QUADS);
glVertex3f(-100.0,-100.0,-10.0);
glVertex3f( 100.0,-100.0,-10.0);
glVertex3f( 100.0, 100.0,-10.0);
glVertex3f(-100.0, 100.0,-10.0);
glEnd();
texture1 = LoadGLTextures();
glBindTexture(GL_TEXTURE_2D, texture1);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 512, 512, 0);
glClear(GL_COLOR_BUFFER_BIT); //Clear screen to grey color
glColor3f(0.0,0.0,1.0);
glBegin(GL_TRIANGLES);
glTexCoord2f(0.0f,0.0f); glVertex3f(-10.0, 3.0, 0.0);
glTexCoord2f(1.0f,0.0f); glVertex3f( 0.0, 3.0, 0.0);
glTexCoord2f(0.5f,0.5f); glVertex3f( -5.0,10.0, 0.0);
glEnd();
glFlush();
}
GLuint LoadGLTextures(void)
{
glGenTextures(1, &texture); // Create The Texture
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
return texture;
}
void Draw (void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor (0.5f, 0.5f, 0.5f, 1.0f);
glClearDepth (1.0f);
glLoadIdentity();
gluLookAt(0.0f,0.0f,50.0f,0.0f,0.0f,0.0f,0,1,0);
pbufferEnable(512, 512);
glColor3f(1.0,0.0,0.0);
glBegin(GL_QUADS);
glVertex3f(-100.0,-100.0,-10.0);
glVertex3f( 100.0,-100.0,-10.0);
glVertex3f( 100.0, 100.0,-10.0);
glVertex3f(-100.0, 100.0,-10.0);
glEnd();
pbufferDisable(512, 512);
pbufferBind();
glColor3f(0.0,0.0,1.0);
glBegin(GL_TRIANGLES);
glTexCoord2f(0.0f,0.0f); glVertex3f(-10.0, 3.0, 0.0);
glTexCoord2f(1.0f,0.0f); glVertex3f( 0.0, 3.0, 0.0);
glTexCoord2f(0.5f,0.5f); glVertex3f( -5.0,10.0, 0.0);
glEnd();
glFlush();
}