Skip to main content
GameDev.net gamedev.net
🔒 Locked

Blending using masks problem

Started by ErikPeeters Sep 7, 2006 at 4:42 AM 0 replies 500+ views
Original Post
ErikPeeters
ErikPeeters
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
AIRmichael
AIRmichael
It might be a sorting problem. Render from front to back, then you probably won't get that blending problem .

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.