Reputation: 274
I working with OpenGL and "GLFW" to mapping the texture image to 2D polygon which is the set of vertices generated from OpenCV.
My question is, can I use the result of texture mapping as the new texture (which is already distort by the first mapping) to map with other polygon. I think my explanation is so bad, please look at the example;
Left image is my texture, and the right is the texture after mapping to polygon (the texture divided to 8 block for 8 set of vertices. What I want to do is using the mapping result on the right side as the new texture.
It is possible to do with OpenGL or OpenCV?
Upvotes: 1
Views: 171
Reputation: 255
You need 2 FBO and 2 texture.
You render the scene to the first FBO (fbo1) and you send the texture (texture1) to the shader and you render the scene to the second FBO (fbo2). After that you send the seconde texture (texture2) to the shader and render the scene in the main FBO (to display the scene) or in the first FBO (to make another pass).
example :
1) render the scene in FBO1 2) send texture 1 to the shader 3) render the texture 1 modified in FBO2 4) send texture 2 to the shader 5) render the texture 2 modifier in FBO1 6) send texture 1 to the shader etc, etc...
this is a little code of one of my project to describe what i try to explain (to make a blur).
//render the scene to the fbo1
glBindFramebuffer(GL_FRAMEBUFFER, f1);
glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
[self drawWithShader:_programRTT];
//apply horizontal blur the result go in the fbo2
glBindFramebuffer(GL_FRAMEBUFFER, f2);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, t1);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
[self drawWithShader:_programBH];
//apply vertical blur the result go in the fbo1
glBindFramebuffer(GL_FRAMEBUFFER, f1);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, t2);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
[self drawWithShader:_programBV];
//return to the main fbo and display result on screen
[view bindDrawable];
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, t1);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
[self drawWithShader:_program];
Upvotes: 2
Reputation: 52165
Render your scene to a FBO with a texture attachment, then use that texture to render more geometry.
Upvotes: 2