Changing Vertex Color in game...

Loffen

Well-known member
Joined
Mar 21, 2004
Messages
51
Location
Akershus, Norway
OK. heres 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
 
Heres an idea: Try using Lighting to light that particular square :).
Hmm.. I guess d3d is weird when it comes to texturing PLUS using colors.. Ill experiment around with that, maybe you need to get the latest DirectX.

-The Pentium Guy
 
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
 
Last edited by a moderator:
Heres 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