Jump to content
  • Advertisement
Sign in to follow this  
Nit

Blending 2 tiles

This topic is 4811 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. I am having trouble blending textured triangles together. I have 1 square tile, which is composed of two triangles (without blending). After drawing this tile with the proper texture, I wish blend another texture onto the lower half of this tile. My approach for doing this is to draw the first tile opaque (no blending enabled), and then draw the new tile, with the bottom left/right verticies haveing an alpha value of half intensity, and the top upper left/right having an alpha value of zero. Unfortunately, the "blended" tile is rendering 100% opaque. After looking through the redbook, i was pretty sure that this was the blend function to use. Any tips/suggestions would be appreciated. The following code is my attempt at blending tile on top of the first tile.
//draw first tile

//draw blended tile
glEnable(GL_LIGHTING);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_DEPTH_TEST);

glBegin(GL_TRIANGLES);
for(each tile)
{

   //calculate normal
   glNormal3f(normal.x, normal.y, normal.z);
   glColor4f(1.0f, 1.0f, 1.0f, 0.5f);
   glTexCoord2f(u1,v1);
   glVertex3f(x1, y1, z1);//bottom left vertex
   glColor4f(1.0f, 1.0f, 1.0f, 0.5f);
   glTexCoord2f(u2,v2)
   glVertex3f(x2, y2, z2);//bottom right vertex
   glColor4f(1.0f, 1.0f, 1.0f, 0.0f);
   glTexCoord2f(u3,v3)
   glVertex3f(x3, y3, z3);//top right vertex


   //draw second triangle
   glNormal3f(normal.x, normal.y, normal.z);
   glColor4f(1.0f, 1.0f, 1.0f, 0.5f);   
   glTexCoord2f(u1,v1)
   glVertex3f(x1, y1, z1);//bottom left vertex
   glColor4f(1.0f, 1.0f, 1.0f, 0.0f);
   glTexCoord2f(u3,v3)
   glVertex3f(x3, y3, z3);//top right vertex
   glColor4f(1.0f, 1.0f, 1.0f, 0.0f);
   glTexCoord2f(u4,v4)
   glVertex3f(x4, y4, z4);//top left vertex
}

glEnd();
glEnable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
glDisable(GL_LIGHTING);

Share this post


Link to post
Share on other sites
Advertisement
My suggestion is to stick

glEnable( GL_COLOR_MATERIAL );
After you enable lighting.

The reason:
OpenGl ignores glColor calls while lighting is enabled because Opengl Uses Material values when lighting is enabled.

Share this post


Link to post
Share on other sites
That'll do it. Thanks for the tip.

On a related note, I was having trouble with getting my triangles to show up. Silly me, I was using Flat shading, so triangles with an alpha of 0 would be 100% transparent. Smooth shading fixed that right up.

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!