Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

ShadowP13

Textures, manually setting alpha

This topic is 5393 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. I''ve broken away from using DirectDraw about 2 months ago and I''ve been able to do almost everything I need with DirectX 9 but I''m having one problem and I was hoping someone could help with. How do you take a texture that you''ve created and loaded from a bmp graphic, and insert alpha information into the texture on a pixel by pixel bases. I want to make a function that will take a "color key" and replace pixels of that color with the same color but with the alpha values I need to make them transparent. Thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement
or any other solution would do to. It doesn''t need to be pixel by pixel All I need is a way to set the alpha values of certain colored areas to transparent if they match a given color (obviously) I just wanted to clarify.

Share this post


Link to post
Share on other sites
use the D3DXCreteTextureFromFileEX

im at work or id give you the proper arguments, but check the docs. one of the last arguments is the color to make transparent.

what it will do is take a standard bitmap and not copy the pixels of the selected color. another option would be to use microsofts proprietary texture format(i want to say it has a .fat extension but i dont recall, it will allow you to insert the alpha value upfront)

either method will work fine, just make sure to set the alphaenable on your device to true when you need to use alpha channels.


Best of Luck

Dredd
________________________________________

"To die with your sword still in its sheath is most regrettable" -- Miyomoto Musashi


Share this post


Link to post
Share on other sites
quote:
Original post by Dreddnafious Maelstrom
what it will do is take a standard bitmap and not copy the pixels of the selected color.


Actually it does copy the pixels of the selected colour, it just also sets those pixels to be fully transparent. But the colour is there.

quote:

another option would be to use microsofts proprietary texture format(i want to say it has a .fat extension but i dont recall, it will allow you to insert the alpha value upfront)


DDS, DirectDrawSurface. Supports a lot of formats internally, many of which include alpha information.



Stay Casual,

Ken
Drunken Hyena

Share this post


Link to post
Share on other sites
I've read about the the special graphic format your talking about but I was wanting players to be allowed to change the graphics if they want too so I am trying to stick to standard windows bitmaps.

I'll check out D3DXCreateTextureFromFileEX, I havn't looked at that yet. Thanks!!

Is there a solution that let's you use the top left most pixel as the color key (along with anchor pixels and other advance sprite techniques) that you know of. I'll probably just stick with using the FileEX method, that sounds easiest.

=-=-=

Just checked that function out... What the heck is a Miplevel? I'm using the non EX version of that function currently. If I just pass the UINT MipLevels a D3DX_DEFAULT would that be the same? This method has a lot of parameters that I don't understand :/ but it looks like I should be able to figure most of it out. I'll probably just pass all the default values whenever possible.

[edited by - ShadowP13 on January 12, 2004 11:31:15 PM]

Share this post


Link to post
Share on other sites
MipLevels controls how many mipmap level to generate. Mipmaps are pre-filtered smaller versions of your image. When you render something that''s far away, the card can make things look nicer, and run faster (less data to fetch) if you use mipmaps. Each mipmap is half the size of the previous.

A miplevel of 1 is no mipmaps (just your image). 2 is one level of mipmap, and so on. 0 is a special case meaning full mipmaps.

For example, if you have a 256x256 texture, and you ask for 4 levels you''ll get a texture with 4 surfaces (256x256, 128x128, 64x64, and 32x32). If you ask for 0 levels, it keeps going until it hits 1x1.

It takes a bit more texture memory, but it looks better. Textures that you write to (render to, or textures that you modify with code (lockrect, write, unlockrect)) are the only things you don''t really want mipmaps for.

You don''t need any special code to take advantage of mipmaps once you''ve set them up with this load call. You might want to set the filtering mode to linear (to get tri-linear filtering), but that''s about all.

Share this post


Link to post
Share on other sites
That''s really interesting so then the non EX maketexturefromfile probable just passes it a 1...

Another thing just struck me about what you typed. I used to lock down surfaces and manually manipulate the pixels that way. I forgot all about it. I wonder if that would work with textures. if you can lock a texture (which you can, I just checked) do you read and write to it exactly like you do with surfaces? If so I know exactly what I need to do as I''m sure to have an old DirectX 8 game I wrote that I can just copy code from. (that it is unless the method has changed from 8 to 9)

Share this post


Link to post
Share on other sites
quote:
Original post by ShadowP13
That''s really interesting so then the non EX maketexturefromfile probable just passes it a 1...


I''m pretty sure it passes D3DX_DEFAULT which generates a complete mipchain. If you know you don''t need them, then set it to 1 and save some memory.

If you''ve done locking in DX8, it''s basically the same under DX9.


Stay Casual,

Ken
Drunken Hyena

Share this post


Link to post
Share on other sites
If nothing else, I need to start using the EX loader because loading a texture with mipmaps is wastefull if you just plan on doing 2d work. Thanks for all the help. If there are any other little nuances of the EX texture loader that have only one loagial choise for 2D work I''d like to know, but otherwise I''ve gotten the original problem completely fixed by using the color keying option. Thanks!

Share this post


Link to post
Share on other sites
quote:
Original post by ShadowP13
If nothing else, I need to start using the EX loader because loading a texture with mipmaps is wastefull if you just plan on doing 2d work. Thanks for all the help. If there are any other little nuances of the EX texture loader that have only one loagial choise for 2D work I''d like to know, but otherwise I''ve gotten the original problem completely fixed by using the color keying option. Thanks!

It''s not necessarily a waste. If you''re planning on scaling your sprites then mipmaps help performance. If you aren''t ever going to scale them then it is just a waste of memory.



Stay Casual,

Ken
Drunken Hyena

Share this post


Link to post
Share on other sites

  • 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!