Sign in to follow this  

Quick StretchRect question.

Recommended Posts

I tried searching but it seems that the question is too broad. Anyways. My window resolution is 1024x768. I have a backbuffer surface and I use ------GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer); -------- to make that surface my drawing buffer. Now I have an other surface that I copy into this buffer, but my goal is to have it showing halfway on the very left side of the screen. Meaning half of way will be shown, but the other half will be offscreen. Like this: Think of it this way... Though not possible, I'd want something like this: = 200; rect.left = -500; rect. right = 1000; rect.bottom = 400; How can I achieve this? If I set any thing in the surface's RECT to a negative value, nothing will show at all. Also is it possible to do it with the buffer I have? Or do I have to create a buffer that's bigger than the screen's resolution, if so how? I don't need an exact code, but something that'll lead me in the right direction. I'm currently studying "Design and Graphics - Prentice Hall - Beginning Game Programming (2005)", and everything is pretty much dumbed down. Thank you in advance.

Share this post

Link to post
Share on other sites
Instead of copying your entire surface outside the screen, copy just the relevant part. For example, if you want to copy the X range (0-1023) to -100, copy (100-1023) to 0.

Share this post

Link to post
Share on other sites
That sounds good, but I'm loading an image file to the surface, and StretchRect just resizes it to whatever the RECT for that surface is. How would you copy it to the buffer partly only?

The only way I see of doing this is by reloading my image file to the surface everytime I'm copying it to the buffer, which isn't that efficient.

There has to be a better way of doing it, no?

[Edited by - french_hustler on December 31, 2007 1:51:06 PM]

Share this post

Link to post
Share on other sites
I think instead of using StretchRect you should just draw your "other surface" onto the backbuffer using a quad. Just make 4 vertices, set them to the screen coordinates you've specified ( = 200; rect.left = -500; rect. right = 1000; rect.bottom = 400) with a D3DDECLUSAGE_POSITIONT vertex declaration, and draw it. Just be sure to offset your screen coordinates by -0.5 if you're using D3D9. Or in code...

struct QuadVertex
D3DXVECTOR4 position;

QuadVertex quad [4];

FLOAT left = -500.0f - 0.5f;
FLOAT right = 1000.0f - 0.5f
FLOAT top = 200.0f - 0.5f;
FLOAT bottom = 400.0f - 0.5f;

quad[0].position = D3DXVECTOR4(right, top, 1.0f, 1.0f);
quad[0].tex1 = D3DXVECTOR2(1.0f, 0.0f);

quad[1].position = D3DXVECTOR4(right, bottom, 1.0f, 1.0f);
quad[1].tex1 = D3DXVECTOR2(1.0f, 1.0f);

quad[2].position = D3DXVECTOR4(left, top, 1.0f, 1.0f);
quad[2].tex1 = D3DXVECTOR2(0.0f, 0.0f);

quad[3].position = D3DXVECTOR4(left, bottom, 1.0f, 1.0f);
quad[3].tex1 = D3DXVECTOR2(0.0f, 1.0f);

const D3DVERTEXELEMENT9 vertexDecl[] =

d3dDevice->CreateVertexDeclaration(vertexDecl, &quadVertexDecl);

// When drawing
d3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, quad, sizeof(QuadVertex));

Share this post

Link to post
Share on other sites
There might be a way to do it through other means, but to me it seems silly not to simply use D3D's drawing capabilities.

You would need to simply load the jpg as a texture, and bind that texture before rendering. D3DXCreateTextureFromFile() will accomplish the first part, while IDirect3DDevice9::SetTexture will handle the binding. Then you simply draw with lighting disabled and a few texture stages set if you're using fixed-function pipeline, or use a NULL vertex shader and and a very basic pixel shader if you're using effects.

Do you understand how to do what I just described? If not, I will try to explain more in-depth and show you some code.

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