ColorMask, beginScene() and background color

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
dircooles
Posts: 5
Joined: Wed Mar 17, 2010 4:03 pm
Location: Münster, Germany

ColorMask, beginScene() and background color

Post by dircooles »

hi everyone,

i'm confused by the behaviour of ColorMask and the background color provided with IVideoDriver::beginScene():

when i use color mask in the driver's OverrideMaterial and clear the backbuffer using a gray color (e.g (255, 128, 128, 128)) the scene is not entirely rendered in red, as i expected, but some areas which should be black are cyan though as the colors were blended!

Image

Code: Select all

    driver->getOverrideMaterial().EnablePasses = ESNRP_SOLID;
    driver->getOverrideMaterial().EnableFlags = EMF_COLOR_MASK;
    driver->getOverrideMaterial().Material.ColorMask = ECP_RED;

    driver->beginScene(true, true, SColor(255, 128, 128, 128));
    smgr->drawAll();
    driver->endScene();
when i use black color to clear the backbuffer ((255, 0, 0, 0)) the scene looks correct.

Image

to me it seems that this has something to do with the materials and blending, but i got no clue about it. anyone else?

thanks for your replies!
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post by Lonesome Ducky »

Alright, I checked the color in an image editor. Apparently, the blue color on the far left is (0,128,128). This is the same as the gray minus the red. Anyone have any insights on why this may be happening?

EDIT: I think I know the answer to this. It is only setting the red components, and since the red in that area is 0, it comes out (0,128,128). The blue and green stay 128 because you are masking them and are therefore not modifying them. Perhaps a safer way to do only a red channel would be through a shader, that returns only the red, while also setting green and blue to 0.
dircooles
Posts: 5
Joined: Wed Mar 17, 2010 4:03 pm
Location: Münster, Germany

Post by dircooles »

hi Lonesome Ducky,

thanks for your reply! of course you are right, but why does the color mask not affect the backbuffer's clear color? i know, this not the case in opengl either, but if it affected the clear color, the back buffer should have been cleared using (128, 0, 0) and no disturbing blue and green component would be present.

however, your suggestion using a shading would probably be the better one, though i don't know yet whether the override material can hold a shader. i think i rember having read some posts in this forum that this caused trouble, but it might be outdated.

but for the solution has to be simple and is only intended to add some fancieness to a tutorial for some students, i will simply use black color to clear the backbuffer.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

The color mask is reset for the buffer clear ops.
dircooles
Posts: 5
Joined: Wed Mar 17, 2010 4:03 pm
Location: Münster, Germany

Post by dircooles »

ahh, that's it! thanks, hybrid!
Post Reply