Jump to content
  • Advertisement
Sign in to follow this  
littleeboy

How to translate the result of the two texture subtraction to a new texture in GLSL

This topic is 3596 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

I can see the right result using following source codes,but how can i use the existing texture img2 and texture img1 to generate a new texture img0 ? The two texture img2 and img1 are all 1024*1024 size. Tanks any reply! //fragment shader code uniform sampler2D img2; uniform sampler2D img1; vec4 object2 ; vec4 object1 ; object2 = texture2D(img2, gl_TexCoord[2].xy); object1 = texture2D(img1, gl_TexCoord[1].xy); gl_FragColor= object2 - object1 ; //main programe code glUseProgram(progObj); glUniform1i(uniform_img2_Location, 2); glUniform1i(uniform_img1_Location, 1); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glBegin(GL_QUADS); glMultiTexCoord2f(GL_TEXTURE2_ARB,0.0f, 0.0f); glMultiTexCoord2f(GL_TEXTURE1_ARB,0.0f, 0.0f); glVertex2f(-1.0f, -1.0f); glMultiTexCoord2f(GL_TEXTURE2_ARB,1.0f, 0.0f); glMultiTexCoord2f(GL_TEXTURE1_ARB,1.0f, 0.0f); glVertex2f(1.0f, -1.0f); glMultiTexCoord2f(GL_TEXTURE2_ARB,1.0f, 1.0f); glMultiTexCoord2f(GL_TEXTURE1_ARB,1.0f, 1.0f); glVertex2f(1.0f, 1.0f); glMultiTexCoord2f(GL_TEXTURE2_ARB,0.0f, 1.0f); glMultiTexCoord2f(GL_TEXTURE1_ARB,0.0f, 1.0f); glVertex2f(-1.0f, 1.0f); glEnd();

Share this post


Link to post
Share on other sites
Advertisement
thanks V-Man ,
but I still have two quesitons

First,is it possible in fragment shader or other GLSL methods to generate my desierd texture img0.

second i will try FBO ,i will back ,then tell you my practise result

thanks again

Share this post


Link to post
Share on other sites
Quote:
Original post by littleeboy
First,is it possible in GLSL to generate my desierd texture img0.

second i will try FBO
You need FBO in addition to GLSL to render to texture. GLSL always just renders to the current buffer, while the FBO extension allows you to set a texture as the current render buffer. There is no way to use GLSL to write to a bound texture sampler directly.

Share this post


Link to post
Share on other sites
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!