View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# 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.

3 replies to this topic

### #1Infinity95  Members

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:

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:

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."

### #2exOfde  Members

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.

"Hello World"

### #3Infinity95  Members

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."

### #4Infinity95  Members

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++) {

.....

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.