tags:

views:

33

answers:

2

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(1, 0, 0), and I would like a white cloud to appear red if outputted.

Thanks!

+2  A: 

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.

Andrew Russell
I'm trying to achieve this effect with BasicEffect. I ment to say without 'custom' shaders.. It seems like you cannot even make your own on this device anyway =( .. I have an object of hundreds of polygons, and I need to sort of pulse the color and alpha in and out on the object. Unbinding the vertex buffer object from the device and resetting vertex colors and alphas across all vertices doesn't seem so great to me, and BlendFactor doesn't seem to do anything for me. Perhaps I'm missing something?
Kyle
Ah - so this is more of a question about BasicEffect. Try out the lighting options. I think `AmbientLightColor` will do what you want (or `DiffuseColor` if your models are lit).
Andrew Russell
DiffuseColor absolutely works! Brilliant. Combining that with Alpha gives the whole color/alpha functionality. Also, this works with LightingEnabled:false so I'm sure it's saving on some shader operations as well. Thanks for your help!
Kyle
+1  A: 

You can also use the Fog and Alpha settings of a BasicEffect (or other effect) to draw textures in a fixed color but still using 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 ...
AbePralle