Author Topic: glColor3f in Direct3D  (Read 5590 times)

0 Members and 1 Guest are viewing this topic.

Offline Aeko

  • C= 64
  • **
  • Posts: 27
  • Karma: 1
    • View Profile
glColor3f in Direct3D
« on: October 15, 2008 »
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.

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Re: glColor3f in Direct3D
« Reply #1 on: October 15, 2008 »
Quote
Is 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, it might give you some ideas how to do it.

Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: glColor3f in Direct3D
« Reply #2 on: October 15, 2008 »
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
Challenge Trophies Won:

Offline Aeko

  • C= 64
  • **
  • Posts: 27
  • Karma: 1
    • View Profile
Re: glColor3f in Direct3D
« Reply #3 on: October 15, 2008 »
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.


Offline Aeko

  • C= 64
  • **
  • Posts: 27
  • Karma: 1
    • View Profile
Re: glColor3f in Direct3D
« Reply #4 on: October 16, 2008 »
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".