XNA glColor equivalent
I come from the land of OpenGL, so I'm similar with glColor functions, and how they work with the textures that get outputed using the default GL blending methods. I can't seem to get GraphicsDevice.BlendFactor to work as glColor does, but I may not be using the right blending settings. Without using shaders is it possible to get the equivalent functionality in XNA?
For example, I would like to set the current color to RGB开发者_如何学Python(1, 0, 0), and I would like a white cloud to appear red if outputted.
There is no way to set a colour on the device. Colour (even in OpenGL) is a per-vertex thing. OpenGL just happens to let you set a default across all vertices.
If you are using SpriteBatch
in XNA, then it handles all the magic with the vertices, and most of its Draw(...)
overloads have a color
parameter.
If you're sending vertices to the card yourself, make sure your vertex format includes a Color
component. Here's a tutorial on how to create a custom vertex format (although it does not include a Color
component).
Alternately you could just use one of the built in formats, like VertexPositionColor
or VertexPositionColorTexture
.
It's worth pointing out that there is no "without shaders" in XNA. You can use BasicEffect
(or one of the other built-in effects) which does the expected thing with the colour data - that is - it tints your texture. And SpriteBatch
uses a shader internally, too.
You can also use the Fog and Alpha settings of a BasicEffect (or other effect) to draw textures in a fixed color and still use their original alpha values (I use it for things like making an entity flash white when it gets hit by a bullet).
Example:
// Draw a silhouette in solid orange at 75% opacity
basic_effect.FogColor = new Vector3( 1.0f, 0.5f, 0.0f );
basic_effect.Alpha = 0.75f;
basic_effect.FogEnabled = true;
basic_effect.FogStart = 1;
basic_effect.FogEnd = 0;
... draw triangles ...
精彩评论