Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Odd Blending behavior?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Infinity95   Members   -  Reputation: 272

Like
0Likes
Like

Posted 15 July 2013 - 01:47 PM

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.


"Errare humanum est, sed in errare perseverare diabolicum."


Sponsor:

#2 exOfde   Members   -  Reputation: 810

Like
0Likes
Like

Posted 15 July 2013 - 03:05 PM

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, 15 July 2013 - 03:07 PM.


#3 Infinity95   Members   -  Reputation: 272

Like
0Likes
Like

Posted 15 July 2013 - 03:18 PM

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, 15 July 2013 - 03:20 PM.

"Errare humanum est, sed in errare perseverare diabolicum."


#4 Infinity95   Members   -  Reputation: 272

Like
0Likes
Like

Posted 16 July 2013 - 05:54 AM

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);
			}
		}
	}
}

"Errare humanum est, sed in errare perseverare diabolicum."





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS