Sign in to follow this  

StretchRect - Texture vs Offscreen Surface

Recommended Posts

Hi there, I'm trying to render some 2d offscreen surfaces to a DirectX9 quads environment. I came up with 2 solutions a) use D3DXLoadSurfaceFromFile() to get the surface & blit using StretchRect() b) use D3DXCreateTextureFromFile() to get a texture, use GetSurfaceLevel() to get the surface, then use StretchRect() to blit to the backbuffer... However I want to use the alpha channel and .tga file formats. I've set the offscreen surface as a A8R8G8B8 surface, but when I use the first method, the alpha channels are discarded, and when I use the second method StretchRect() fails and nothing is drawn. I think the reason StretchRect fails is because of an issue with using a texture to draw to an offscreen surface (the backbuffer) as per MSDN's not so clear documentation. Has anyone else come across this problem, knows a solution, or knows of a better way to create alpha blended GUI's in DX9?

Share this post

Link to post
Share on other sites
First of all, you can check why StretchRect fails using the return code, or enable the debug runtime using the DirectX Control Panel application, which will then print the error to the output panel.

Regarding "using the alpha channel", if you mean you want to alpha blend the texture over the existing image, then StretchRect won't work for that, since it copies the alpha as is, and doesn't blend. You will have to draw a quad with the image as a texture (and alpha blending enabled).

Share this post

Link to post
Share on other sites
Yeah I was trying to blend. I was using the textured quad method for everything else, but there were issues with it - Namely that my library doesn't like to handle anything that isn't a square texture, which makes building buttons and other controls really difficult. Actually I think I built it off the textured quad tutorial on this site.

Plus for some reason the quads don't line up in the correct locations if I'm stretching the textures.

I dunno maybe my textured quad lib is messed up. Should I start looking that stuff over?

As for the StretchRect method it only returns 1 error which is D3DERR_INVALIDCALL.

So where should I head from here?

Share this post

Link to post
Share on other sites
How do I "draw a quad with the image as a texture"?

I should probably post this as a separate topic, but since I saw what might be the core of my quest, I thought I'd start by asking here.

Here's my real problem.

I have a perfectly fine DirectDraw (DirectX 7) app that loads in a bunch of really big images and performs moves and zooms while a narrator talks and music plays. Call it a Ken Burns effect.
Then I wanted to add dissolves. No alpha support in DirectDraw. So I had to move to Direct3D & DirectX9, even though everything I am doing is in 2D.
Well, as I am sure all of you are aware that is a wee bit more complex, and now I am lost.
I keep chasing tail around finding partial solutions that are written for DirectX 8.
I found some nice hints here (took a bit of time to make it work):
But I still don't know how to handle blitting a portion (different size source and dest rectangles) of the source surface/texture to the screen.
I'm hung right now on the business of loading in an image and taking part or all of the image and copying it to the screen with different sized source and destination rectangles.
I think it has something to do with SetTransform(), but I am not sure how to use that.
Basically, I want to:
1) Load very large images into video memory (for example 32 Bit 4700x3700).
2) Copy portions of these images to the screen to create panning and zooming.
3) Dissolve from one image to another.

Hardware is not a big problem as I can specify the graphics card.
Could anyone point me in the right direction?



Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this