Changing Vertex Color in game...

Loffen

Regular
Joined
Mar 21, 2004
Messages
51
Location
Akershus, Norway
OK. here's my idea:

I want to make some tilebased game, were the user/player can place structures on the map. I am pretty sure you have seen this before: There are some green squares under the "not yet placed structure". If i now move the mouse over a rock, some of the squares (the ones overlapping the rock) change to red, showing the player he cant place it there. I guess thats it.

And heres my problem:

Earlier i moved my sprite by destroying the vertexbuffer and recreated it with different vertex coordinates. I figured this was VERY inefficent, so i learnt how to move the world. Now, in the very same piece of code, while filling the vertexbuffer, i set a color. How can i change this color "in game" without destroying and recreating the vertexbuffer?? I dont want to recreate the vertexbuffer as this was extremely inefficent.

Got any ideas, links, suggestions or code snippets?? please post them here...

EDIT: When i use a color when filling the buffer, the result is only a lighter or darker square. Not even a glimpse of a color :confused:

-- Loffen
 
Here's an idea: Try using Lighting to light that particular square :).
Hmm.. I guess d3d is weird when it comes to texturing PLUS using colors.. I'll experiment around with that, maybe you need to get the latest DirectX.

-The Pentium Guy
 
You'd have to mess lighting with it a bit for it to work with 2d.
Also you'd need normals.. set the .Normal or the .RHW property of your vector3's to 1.

Yep 9.0c is the latest versoin.
 
I have been playing around with different textures, colors and different ways of adding the color to the vertex. Well, my english is too bad to tell how confused my head is right now.. will post 2 screenies from app to make things clearer.

The first one:
* The upper-left tiles are the images in original state.
* The "map" has the color integer set to 65000.

As you see, the green looks 100% the same, but the pink gets blue !?!?!?!

The secund one:
The same map as the first one but the color is now added like this:
Code:
Color.FromArgb(155, 200, 0, 0).ToArgb

What i expected from this was that all squares get red (actually 50% transparent red)....
EDIT: BTW: as you might want to know, my backbuffer format is Format.A8R8G8B8. Shouldnt this allow me to create transparent colors??

Any suggestions? Tips?

--Loffen
 

Attachments

Last edited:
Here's another idea, if you want all squares to get 50% red:

Create a 50% red bitmap (alternate every pixel.. red green red green.. assuming green is your transparent color). Must be a real pain to do this... heh... I guess it would work though.

-The Pentium Guy
 
Back
Top