Jump to content
  • Advertisement
Sign in to follow this  
_NoISeR_

Problem rendering a texture using ARB multitexture and texture rectangle extensions

This topic is 3853 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello to all, I'm novice on GPU programming. I've spent the last two days trying to deal with this, but can't understand what is happening. I'm just trying to render the AD (Absolute Difference) of two images using a very simple Cg shader. The problem is that when I try to render the image to a framebuffer it shows a black image, and all the previous textures are "destroyed" (black). If I use the shader to render directly to the screen it works!! I've pasted the code of my display function. Hope that you can help me. If you need I can bring you the full program. Thank you!! -------------------------------------------------------------------------------- GLuint ADTexture; // First we generate the texture glGenTextures(1, &ADTexture); // Bind the first framebuffer glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, frameBuffer); // Attach texture to the frame buffer glBindTexture(GL_TEXTURE_RECTANGLE_NV, ADTexture); // Set properties to the output texture glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGBA, iWinWidth, iWinHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glTexParameteri(GL_TEXTURE_RECTANGLE_NV,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_RECTANGLE_NV,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // Attach the texture to the color buffer of the previous defined FBO glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_NV, ADTexture, 0); // Check if the FBO is valid isValidFBO(); // Render the AD texture cgGLEnableProfile(cgFragmentProfile); // Bind Cg Program cgGLBindProgram(cgFragmentSAD); // Bind the two input textures glActiveTextureARB(GL_TEXTURE0_ARB); glEnable(GL_TEXTURE_RECTANGLE_NV); glBindTexture(GL_TEXTURE_RECTANGLE_NV, initialTextures[0]); glActiveTextureARB(GL_TEXTURE1_ARB); glBindTexture(GL_TEXTURE_RECTANGLE_NV, initialTextures[1]); glEnable(GL_TEXTURE_RECTANGLE_NV); // Clear Color And Depth Buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Draw the rectangular area glBegin(GL_QUADS); glMultiTexCoord2fARB( GL_TEXTURE0_ARB, 0.0, 0.0); glMultiTexCoord2fARB( GL_TEXTURE1_ARB, 0.0, 0.0); glVertex3f(0.0, 0.0, -1.0); glMultiTexCoord2fARB( GL_TEXTURE0_ARB, 0.0, iWinHeight); glMultiTexCoord2fARB( GL_TEXTURE1_ARB, 0.0, iWinHeight); glVertex3f(0.0, 1.0, -1.0); glMultiTexCoord2fARB( GL_TEXTURE0_ARB, iWinWidth, iWinHeight); glMultiTexCoord2fARB( GL_TEXTURE1_ARB, iWinWidth, iWinHeight); glVertex3f(1.0, 1.0, -1.0); glMultiTexCoord2fARB( GL_TEXTURE0_ARB, iWinWidth, 0.0); glMultiTexCoord2fARB( GL_TEXTURE1_ARB, iWinWidth, 0.0); glVertex3f(1.0, 0.0, -1.0); glEnd(); glActiveTextureARB(GL_TEXTURE0_ARB); glDisable(GL_TEXTURE_RECTANGLE_NV); glActiveTextureARB(GL_TEXTURE1_ARB); glDisable(GL_TEXTURE_RECTANGLE_NV); // Disable the fragment profile cgGLDisableProfile(cgFragmentProfile); // After, display the rendered AD texture glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Enable the texture rectanlge extension glEnable(GL_TEXTURE_RECTANGLE_NV); // Bind the texture glBindTexture(GL_TEXTURE_RECTANGLE_NV, initialTextures[0]); // Draw the rectangular area glBegin(GL_QUADS); glTexCoord2i(0, 0); glVertex3f(0.0, 0.0, -1.0); glTexCoord2i(0, iWinHeight); glVertex3f(0.0, 1.0, -1.0); glTexCoord2i(iWinWidth, iWinHeight); glVertex3f(1.0, 1.0, -1.0); glTexCoord2i(iWinWidth , 0); glVertex3f(1.0, 0.0, -1.0); glEnd(); // Disable the texture rectanlge extension glDisable(GL_TEXTURE_RECTANGLE_NV); // Swap display buffers glutSwapBuffers();

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!