Jump to content
  • Advertisement
Sign in to follow this  

OpenGL problem blending properly in openGL

This topic is 2773 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'm trying to draw a 2d character sprite on top of a 2d tilemap, but when I draw the character he's got odd stuff behind him. This isn't in the sprite, so I think its the blending.

This is how my openGL is set up:

void InitGL(int Width, int Height) // We call this right after our OpenGL window is created.

glViewport(0, 0, Width, Height);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // This Will Clear The Background Color To Black
glClearDepth(1.0); // Enables Clearing Of The Depth Buffer
glDepthFunc(GL_LESS); // The Type Of Depth Test To Do
glDisable(GL_DEPTH_TEST); // Enables Depth Testing
//glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading
glEnable(GL_TEXTURE_2D); // Enable Texture Mapping ( NEW )
glAlphaFunc(GL_GREATER, 0.5f);

glMatrixMode(GL_PROJECTION);//configuring projection matrix now
glLoadIdentity();//reset matrix
glOrtho(0, Width, 0, Height, 0.0f, 100.0f);//set a 2d projection matrix


How should I set this up to work properly (i.e. drawing the sprite without odd stuff behind him.

This is what I am talking about: http://i.imgur.com/cmotJ.png

PS: I need to be able to put transparent/semi-transparent images on top of each other and have whats behind them visible too

Share this post

Link to post
Share on other sites
You're currently using pre-multiplied alpha blending ([font="Lucida Console"]GL_ONE , GL_ONE_MINUS_SRC_ALPHA[/font]), you might want traditional alpha blending instead ([font="Lucida Console"]GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA[/font]).

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!