Razor Storm
Razor Storm

Reputation: 12336

Relationship between GraphicsDevice.Clear's color and the color drawn onto the screen

I am a beginner to XNA and am experimenting with my new kinect for windows so decided to follow a tutorial: http://digitalerr0r.wordpress.com/2011/06/20/kinect-fundamentals-2-basic-programming/

After doing this one I noticed that all the colors are tinted light blue. For example a color of rgb 20,20,20 will look like dark blue instead of dark gray.

I noticed that the GraphicsDevice.Clear() is using Color.CornflowerBlue. I experimented with changing it to Color.Black and sure enough all the stuff are now tinted black.

What's the relationship between the GraphicsDevice.Clear(color) and the colors being drawn onto the screen?

Here's my draw function:

/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
    GraphicsDevice.Clear(Color.Black);

    spriteBatch.Begin();
    spriteBatch.Draw(kinectRGBVideo, new Rectangle(0, 0, 640, 480), Color.White);
    spriteBatch.DrawString(font, connectedStatus, new Vector2(20, 80), Color.Black);
    spriteBatch.End();

    base.Draw(gameTime);
}

Upvotes: 1

Views: 671

Answers (1)

Chris Ortner
Chris Ortner

Reputation: 816

(As requested, in form of an answer.)

Try changing the BlendState at the call of the spriteBatch.Begin() method. This dictates how colors blend when drawn above each other.

I'm not exactly sure why BlendState.Opaque displays text as blocks, but my guess is that this blend state does not support alpha. Therefore the transparent regions around the text turn, well, opaque, making the text look like a rectangle. I don't have the tools to check this guess on me right now, so I can verify it.

Upvotes: 3

Related Questions