Hi all !
Is there any equivalent commando to glColor3f or glColor4f in Direct3D ?
I'm programming a little intro that shows in random position random cubes with random color. When it was done in OpenGL I changed the color with glColor3f and then painted the cube. But now, when using vertex buffers like:
{-1.0f,-1.0f,-1.0f, D3DCOLOR_ARGB(0,0,255,0)},
(...)
the color is pre-defined.
Any way to have a "neutral" color and the paint it with the color generated by a random function ?
Thanks for your ideas.
QuoteIs there any equivalent commando to glColor3f or glColor4f in Direct3D ?
Unfortunately not, as far as I know :/
The best thing to do is to make a function that creates your vertex buffer (Lock/Unlock) with your desired color on the fly.
Take a look at this tutorial (http://www.gamedev.net/reference/articles/article1972.asp), it might give you some ideas how to do it.
I seem to remember that there's a constant colour register in the renderstate which can be set, and also a texture stage state setting that chooses that as the output colour.
D3DRS_TEXTUREFACTOR
and
then set the COLOROP to use that.
Sorry, bit vague and I've no test rig to try it out.
Jim
Thanks rbz and Jim.
So, there are two general ideas on how to perform this:
(1) Changing the color vertex
(2) Changing the color texture and then apply it. (D3DRS_TEXTUREFACTOR)
This is my (3): To have a palete of cubes with different color pre-generated on setup. (Brute way ! :bricks:)
My worries are about Lock/Unlock performance dropping. I've reading a book about graphics with DX and every two pages make you remember about performance loosing in Lock/Unlock operations. Anyway, the best will be to make a try.
Hi all !
Well, yesterday night I tried the "changing color vertex method", re-doing the pixel verter every time before drawing while modifing its values:
{-1.0f,-1.0f,-1.0f, D3DCOLOR_RGBA(cube[n].r, cube[n].g, cube[n].b, cube[n].alpha)},
(...)
It's quite fast. Drawing 2000 cubes without problems in a cheap motherboard graphic card in a laptop of 5 years old.
TIP: don't forget vertexBuffer->Release() after drawing or you will have a BIG memory leaking.
In fact, I've had more problems with the rotations and projections in DX during this experience than other DX issues. And this distubs me a lot. May be too many years teaching me about right hand systems on mathematics, mechanical physics and CAD. This part of DX is directly a "kick in your balls".