• Advertisement
Sign in to follow this  

Odd Blending behavior?

This topic is 1652 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 again fellow programmers. I'm currently confused about some blending behavior. Let me explain the situation first:

I'm makin a menu and have a Background with 80% opacity in a dark gray color. On this background i will now render a green square with 100% opacity and as you can see from the image this works just fine:

 

pic1.png

 

Next i render a red square on this background. The red square has 50% opacity and overlaps the green square. Now the green square shouldn't let anything through (according to my logic, 'cause it has 100% opacity and thus shouldn't let anything through) but the game behind the green square is visible nevertheless as you can see in the next pic:

 

pic2.png

 

Any idea why this is happening? If you need my code you can find it here. The relevant files should be Graphics.cpp, MenuManager.cpp and MenuItem.cpp

 

Thank you in advance for helping.

Share this post


Link to post
Share on other sites
Advertisement

The only thing i could imagine why this happend is that the order how you draw this is wrong.

If i am right, you handle MenuItem with the class MenuManager, correct me please if I am wrong,

 

So the order in vector -> MenuItemPtr have to be wrong. It looks like you draw first the green square and then the red square.

Don't forget a vector sort his elements automatically with the > operator

Edited by exOfde

Share this post


Link to post
Share on other sites

The rendering order is determined by the zIndex of the elements. The Red square is definitely the last element that is rendered. I already checked this by making it 100% opaque. I also tried changing render order and when i do that the green square is rendered above the red one and everything is fine. The point here is, that when rendering the red square which has 50% opacity over the green one the green one also kind of inherits this opacity, which it should'nt.

Edited by Infinity95

Share this post


Link to post
Share on other sites

Ok after a night of rest i found the solution to the problem. I had to disable the Depth buffer and then change the zIndex loop to correctly loop through the elements:

void Graphics::RenderMenu() {

	this->devcon->OMSetRenderTargets(1, &this->backbuffer, NULL);

	......

	for(unsigned int zIndex = 0; zIndex <= 20; zIndex++) {
		for(unsigned int i = 0; i < Game::MenuManagerPtr->MenuItemPtrs.size(); i++) {

			if(Game::MenuManagerPtr->MenuItemPtrs[i]->showing && zIndex == Game::MenuManagerPtr->MenuItemPtrs[i]->zIndex) {
                                  
                                .....
		
				this->devcon->Draw(4, 0);
			}
		}
	}
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement