Jump to content
  • Advertisement
Sign in to follow this  
streamer

bitmap customization

This topic is 4816 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everybody! You have a texture with some basic colors. Texture has a man on it. Head is pink, torso is green, hair is blonde, etc... I want to use that sprite several times. For example I need that sprite with black, brown and blonde hair, and render it all to the screen. Yeah locking/unlocking texture, and changing pixels works, but if I want to render 10 style of hair, it is a little bit slow to change pixels on fly. Is there any other approach to do this (exluding having clones of that texture in memory because on the end I'll need 1GB of memory for simle game)? Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
In the old days that was solved with a palette...

Dunno if you can still get palettized textures in recent
dx-version.

Share this post


Link to post
Share on other sites
It depends on what interface you're using (D3D I suppose?). You can use a D3DXSprite (don't have to, could make your own), and load up the various parts. Your standard texture would contain the body outline and leave the head, hair, and torso transparent. First you draw the hair color, which is fully transparent except where the hair color is (this would be 1 texture or clipped texture per hair color). Next you draw the face fully transparent except where the face is. Draw the torso the same way. Finally, draw your sprite lastly on top of those others and you've created a handy little layer system. If you want to optimize, the player won't change the hair, face, or torso very often probably, not each frame anyway, so you can combine those into a single texture and draw that one first, then the character sprite. How you combine the texture is up to you. You could render it to a render target as a texture, or you could lock the pixels and copy by hand. I tend to prefer render targets. :)

Share this post


Link to post
Share on other sites
Quote:
Original post by Supernat02
It depends on what interface you're using (D3D I suppose?). You can use a D3DXSprite (don't have to, could make your own), and load up the various parts. Your standard texture would contain the body outline and leave the head, hair, and torso transparent. First you draw the hair color, which is fully transparent except where the hair color is (this would be 1 texture or clipped texture per hair color). Next you draw the face fully transparent except where the face is. Draw the torso the same way. Finally, draw your sprite lastly on top of those others and you've created a handy little layer system. If you want to optimize, the player won't change the hair, face, or torso very often probably, not each frame anyway, so you can combine those into a single texture and draw that one first, then the character sprite. How you combine the texture is up to you. You could render it to a render target as a texture, or you could lock the pixels and copy by hand. I tend to prefer render targets. :)


Sounds nice [smile] but the point is that I'm making MMORPG in which I would like that every player can customize his charachter(hair, head, skin, and clothes). I want to made only one charachter animation and change color of sprites based by player customization. And I don't want to use huge amount of memorie making a copies of sprites.
And I have no idea how can be this achieved...
I saw similar aproach in Baldurs Gate, and Fallout Tactics I think.
Anyway thank you for your reply.

Share this post


Link to post
Share on other sites
A pixel shader could come in handy, though it wouldn't be too simple. You'd need to use HLSL probably.

You'd set certain color-keys that translate into another color:

if (color == float3(1.0f, 1.0f, 1.0f, 0.2f))
color = HairColor;

*note* you'll need to make the color-keys with values you know you won't use...

Sound good? It wouldn't be ultra-fast, but it should be acceptable :).

Share this post


Link to post
Share on other sites
Sorry if I wasn't very clear on my explanation. It does indeed allow for only one animation and a mixture of any number of colors. I didn't realize you want them to set them to their own colors though, thought it would be a "pick from 10 colors" type of thing. Either way, you wouldn't be using hardly any texture memory at all. It's only 1 "texture mask" for each modification.

Head + torso + hair + clothes = 4 modifications and thus 4 masked bitmaps. Each mask is just a fully opaque color white in the place of the modification, i.e. white hair.
blue + white + green + yellow + whatever, doesn't matter. When you go to draw the mask, you apply the color to it.
Body1 + Body2 + Body3 = 3 body types, let's say you have 20 though for grins, and let's say you have 30 frames of animation per body. 20*30 = 600 textures.

Here's where it would be important to know how big your sprites are. If they are 64x64, you'll use:
600*64*64 + 4*64*64 = 2473984 bytes
Roughly 2.5 MB. Now you can cut the animations in half by using the same texture for left/right, top/bottom, top-right/top-left, and bottom-left/bottom-right. Basically, you cut the number of frames in half, from 30 to 15.
300*64*64 + 4*64*64 = 1.25 MB.

If you use ID3DXSprite, it allows you to pass in the color you want to draw. It would look like this:
HeadSprite->Draw(...,...,...,HeadColor);
HairSprite->Draw(...,...,...,HairColor);
...
BodySprite->Draw(...);

Share this post


Link to post
Share on other sites
No. Sorry if I didn't understand you[smile].

Thank you very much for your fast reply. I'm not using sprite interface, but with some minor modification I think that I can get similar effect. I use a little bit more of textures for anination cca. 900 for male player, and also 900 for female.
And if I can get it to work within 15MB of textures that's very good.
Thank you again.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!