Jump to content
  • Advertisement
Sign in to follow this  
ErikPeeters

OpenGL Blending using masks problem

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

Hi All... I have set up a little OpenGL program, just to try things. I based my code on Lesson 20 of the NeHe pages. Now i'm on the point of blending. The problem I have is that when I draw 2 textured quads with accompanying masks the black pixels of the image and mask are transparant but when the two textured quads overlap eachother with the not transparent colors they blend colors. The thing I want is that the second drawn texture is on top of the first drawn and not blend in with it. My code (texture[3] is the mask, texture[4] is the texture): int InitGL(GLvoid) { if(!LoadGLTextures()) return FALSE; glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClearDepth(1.0); glEnable(GL_DEPTH_TEST); glShadeModel(GL_SMOOTH); glEnable(GL_TEXTURE_2D); return TRUE; } int DrawGLScene(GLvoid) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslatef(0.0f, 0.0f, -1.0f); glEnable(GL_BLEND); glDisable(GL_DEPTH_TEST); if(masking) { glBlendFunc(GL_DST_COLOR,GL_ZERO); } if(masking) { glBindTexture(GL_TEXTURE_2D, texture[3]); glBegin(GL_QUADS); glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.1f,-0.1f, 0.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.1f,-0.1f, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.1f, 0.1f, 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.1f, 0.1f, 0.0f); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[3]); glBegin(GL_QUADS); glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.15f,-0.1f, 0.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.05f,-0.1f, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.05f, 0.1f, 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.15f, 0.1f, 0.0f); glEnd(); } glBlendFunc(GL_ONE, GL_ONE); glBindTexture(GL_TEXTURE_2D, texture[4]); glBegin(GL_QUADS); glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.1f,-0.1f, 0.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.1f,-0.1f, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.1f, 0.1f, 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.1f, 0.1f, 0.0f); glEnd(); glBlendFunc(GL_ONE, GL_ONE); glBindTexture(GL_TEXTURE_2D, texture[4]); glBegin(GL_QUADS); glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.15f,-0.1f, 0.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.05f,-0.1f, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.05f, 0.1f, 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.15f, 0.1f, 0.0f); glEnd(); glEnable(GL_DEPTH_TEST); glDisable(GL_BLEND); return TRUE; } Thank you for replying. - Erik

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!