Jump to content
  • Advertisement
Sign in to follow this  
Thrawn80

StretchRect with colorkey

This topic is 4217 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 all, I know ppl hav been telling me to use textures. I hav no problem using them except for the fact that: 1) They must be in powers of 2 2) Their differences cannot be more than 2 powers, ie, 32x64 or 32x128 no more than that 3) We must use a textured quad to map them so that we can see them But ... I've been seeing some games render some colorkeyed buttons (in 2D) or alpha-blended buttons in arbitary width and height! Moreover, the buttons are very clearly defined, unlike the effects of a texture being stretched. May I ask, is there a way to StretchRect() an offscreen plain surface onto the back buffer with a color key? I tried setting all the pixel of my colorkey into alpha value of 0. It doesn't work. Is there another way? Please advise. Thanks, thrawn80

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Quote:
Original post by Thrawn80
I know ppl hav been telling me to use textures. I hav no problem using them except for the fact that:
1) They must be in powers of 2
2) Their differences cannot be more than 2 powers, ie, 32x64 or 32x128 no more than that

Let me correct you on this:

- If the texture cap D3DPTEXTURECAPS_POW2, then textures must be a power of 2

- Unless D3DPTEXTURECAPS_NONPOW2CONDITIONAL is also set, in which case the texture can be an arbitrary size, with some limitations (which are stated under D3DCAPS9) in the docs.

Cards these days either don't have the D3DPTEXTURECAPS_POW2 cap set, in which case there is no limitation, or (the majority) have the D3DPTEXTURECAPS_NONPOW2CONDITIONAL set, in which case you can still use any size, but not in all cases.

Quote:
But ... I've been seeing some games render some colorkeyed buttons (in 2D) or alpha-blended buttons in arbitary width and height! Moreover, the buttons are very clearly defined, unlike the effects of a texture being stretched.

Note that you can do that even with power of 2 textures! In fact, that's the way to go. It's inefficient to have each UI element in its own texture. You can easily put a lot of buttons into the same texture, and use texture coordinates to draw the button you want with the right size.

Quote:
May I ask, is there a way to StretchRect() an offscreen plain surface onto the back buffer with a color key?

No. Direct3D doesn't support colour key directly. D3DX can do that in software, when loading a texture, but you can't easily do that at runtime. Use alpha blending or alpha testing.

Share this post


Link to post
Share on other sites
Quote:
Original post by Thrawn80
I tried setting all the pixel of my colorkey into alpha value of 0. It doesn't work.


StretchRect is slow. If all you want to do is blit 2D images to the screen, then use ID3DXSprite. Its simple to use, it's fast, and it supports things like rotation and alpha blending.

Share this post


Link to post
Share on other sites
Thanks all for ur advises.

I've tried using textures not more than 256x256 and it seems to be ok.
The methodology in texture mapping using textured quads are very different from the traditional ddraw surfaces.

In DDraw surfaces, all surfaces map 1 on 1 to the screen where stretching is slow, even bltFast() pales in comparison to 3D acceleration.

Strange enuf ... my video card is ATI Radeon X700 PCI Express yet it doesn't support textures above the size of 256 pixels.

Nevertheless, I have a single problem remaining... That is, I have a self-rendered GUI system which renders the UI components by locking the surface. Each component has its on surface... may I ask, is it still possible to do it the 2D way?

Last of all, texture mapping has made me rethink many possibilities of how the rendering part can be done... phew... what a mind job!

Thanks for the comments for far :)
thrawn80

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!