My game has day/night. Is it possible to tint nodes (and their children)?
Not necessarily the whole scene (because I don't want to tint my HUD stuff). I managed to overlay the scene with semi-transparent, 960x640 (retina) color image... but, maybe there is a more efficient way to achieve this effect.
You can just tint the affected nodes - sprites, labels, etc as long as they implement the CCRGBAProtocol.
For example these three colors can be used for daytime, dawn and night:
// full brightness
sprite.color = ccc3(255, 255, 255);
// getting darker
sprite.color = ccc3(200, 200, 220);
// night
sprite.color = ccc3(140, 140, 180);
I pulled up the blue channel because blue still feels pretty dark without draining too much of the brightness. You'll see this effect in a lot of games, where night colors actually have a blue-ish tone to them. It's a trick to retain some color and brightness while still giving the feeling of darkness.
These numbers are off the top of my head and certainly will need tweaking. Also you should aim for a subtle effect. "Night" in a game doesn't mean that all graphics are pitch black.
Related
Image negative effect is typically done like this:
pixel = rgb(1, 1 ,1) - pixel
but if the pixel color is close to gray, than:
pixel = rgb(1, 1, 1) - rgb(0.5, 0.5, 0.5) = 0.5
That's not a problem and it's how it should be, but for me it is, I am making a crosshair texture in my 3D game, which will be drawn in the center of the screen and I want it to have negative effect, reason for it is clearity, if I were to make crosshair white, it would not be visible when looking on white objects (I know I can make it with black outline so it is visible, but thats ugly), but it still has problems for grayish colors as I described, what can be done to fix that?
I have followed this gtkmm tutorial on how to draw shapes and fill them with colors (e.g. A red disc on a transparent background). I was also able, from this example, to derive another example with a red disc on a blue background.
However, what I would really need is a transparent disc with a blue background that fills everything minus the disc area, which should stay transparent.
So with cairo, the usual workflow is:
Create a surface
Draw a shape (e.g. draw a circle)
Fill the circle, so that it becomes a disc.
I would need some workflow that achieves something like this instead:
Create a surface
Draw a shape (e.g. draw a circle)
Fill the area outside the circle, so that I have a colored background with a transparent "hole" in the middle.
I have done some research on this on the web but all examples seem to assume that we want to fill the inner region of a shape (which I must admit is more typical).
How could I do this?
P.S. I have added the C tag because I don't mind if you prefer to use C (or even Python).
Draw your circle and draw a rectangle containing all the visible area. Set the cairo fill rule to even/odd. Fill. Done.
cairo_save(cr); // Save the state
cairo_arc(cr, 42, 42, 21, 0, 2*M_PI); // Draw circle
cairo_rectangle(cr, 0, 0, width, height); // Rectangle containing everything
cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD);
cairo_fill(cr);
cairo_restore(cr); // Restore default fill rule (optional; pairs with save above)
IMHO, The function of 'Draw outside the circle' is complex to the graphic framework. It may also be ambiguous if you draw more than one circle filled outside.
As graphic shapes drawn later are placed 'on' the ones drawn former. What is needed is that draw a rectangle to fill the entire graphic context before drawing other shapes. This is defined as clear with the background color in some frameworks.
the workflow would seem like:
1. Create the surface.
2. Draw the background colored with what outside the circle.
3. Draw the circle filled with a specific color, e.g. white.
As a result, the circle would cover the background.
If insist on draw the circle first, please search Flood Fill Algorithm, which is used to draw on images. However, it is needless and costly to achieve the screen pixels and play such algorithms when drawing on screen.
I find
Example Application: Creating a Clock with Cairo in the later section of the book you provide.
That seems help.
I am trying to modify the look of the graph displayed to have a white background with black axes.
However, simply modifying the RGB values of
m_OScopeCtrl.SetBackgroundColor(RGB(0, 64, 0)) ;
m_OScopeCtrl.SetGridColor(RGB(192, 255, 192)) ;
m_OScopeCtrl.SetPlotColor(RGB(255, 255, 255)) ;
in “TestOScopeDlg.cpp” doesn’t seem to do the trick, the entire graph just turns white and the plots disappear (presumably being hidden by the white background).
Link to source code on codeproject.
http://www.codeproject.com/Articles/241/Oscilloscope-StripChart-Control
How can I make the graph appear with a white background and black axes?
Found the answer. Changing SRCPAINT to SRCAND works.
It seems SRCPAINT works when trying to overlay a light color on top of a dark color and SRCAND works when trying to overlay a dark color on top of a light color.
What I'm doing to render some beautiful city lights on the night side of the Earth is to render a second sphere mesh on top of the Earth mesh, then I set the city lights texture on it with 200% ambient light so they become very bright, and make the alpha channel of the dds texture file transparent so the Earth texture can be seen behind on the original Earth mesh.
The result is this pretty nice effect:
http://s24.postimg.org/gpqg8a491/screenshot_2.png
This is the code for the mesh holding the lights texture:
d3ddev->LightEnable(0, FALSE);
d3ddev->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(200, 200, 200));
d3ddev->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
d3ddev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
d3ddev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_DESTALPHA);
//d3ddev->SetRenderState(D3DRS_ALPHAREF, (DWORD)0x0000008f);
d3ddev->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
d3ddev->SetTexture(0, earth_lights);
However the bad thing is that the lights also show in the day side, always, and that's pretty bad.
How can I achieve a similar result but with the lights not showing in the day side? Texture blending? Shaders?
I have a skyline as background in a game. The skyline has fully transparent areas and opaque areas and maybe some semitransparent areas... :-P
This time I'd like to create a gradient to place on top of the skyline, so that I can easily make the skyline darker/brighter, tint the color of it to fake different times of day, sky colors tinting it etc...
For this I need to make a gradient that is the same size of the skyline, but does not draw where the skyline is fully transparent.
I guess there would be maybe a few ways to do this, and avoiding photoshopish ways, I think I'm gonna try to render the skyline by using CCRenderTexture and/or possibly masking a gradient (preferrably CCGradientLayer that I could easily tint later) where the skyline is fully transparent. But I'm not very used to CCRenderTexture...
Any simple solution?