Jump to content
  • Advertisement
Sign in to follow this  
french_hustler

Quick StretchRect question.

This topic is 4001 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

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: http://i8.tinypic.com/6jpgoqr.jpg Think of it this way... Though not possible, I'd want something like this: rect.top = 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
Advertisement
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 (rect.top = 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;
D3DXVECTOR2 tex1;
}

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[] =
{
{ 0, 0, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITIONT, 0 },
{ 0, 16, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
D3DDECL_END()
};

d3dDevice->CreateVertexDeclaration(vertexDecl, &quadVertexDecl);

// When drawing
d3dDevice->SetVertexDeclaration(quadVertexDecl);
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
Also I forgot to mention...you may want to use the ID3DXSprite interface. It allows you to simply specify a position and a texture, and it will draw that 2D texture onto the back buffer at the desired screen position.

Share this post


Link to post
Share on other sites
Quote:
Original post by french_hustler
That's exactly what I ended up using.

Worked perfectly.

Thanks again and Happy New Year.


You're welcome, and happy new year to you as well. [smile]

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!