Jump to content
  • Advertisement
Sign in to follow this  
noodleBowl

Draw and move primitive help

This topic is 2130 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 currently am having a issue with my draw code and need help

 

I am just drawing a single quad made from two triangles, where this quad is drawn using triangle list and a index buffer. The quad draws correctly on the screen, but if I tell the quad it to move like so

//Inside of render method
x++;

batcher.beginBatch();
batcher.draw(x, 50.0f, 64.0f, 64.0f, D3DCOLOR_XRGB(0,255,255));	
batcher.endBatch(device);

It seems like it is growing by 1 pixel, moving to the new position, and then shrinking by 1 pixel again. Here is all of my code, it is ready to run all you have to do it change the Character Set  for the project to be "not set"

 

main.cpp : http://pastebin.com/zSa9wZ1x

SpriteBatcher.h : http://pastebin.com/cPnGs5eL

SpriteBatcher.cpp : http://pastebin.com/ZQAiHY0s

 

Could someone please help me fix this issue

Edited by noodleBowl

Share this post


Link to post
Share on other sites
Advertisement

Classic pitfall: Your backbuffer dimension don't match with the windows client area (there's usually a title bar and some small border, so the client area is smaller). Blitting the bigger backbuffer to a smaller target (happing when calling Present) will give you this annoying artifact.

 

You either calculate the back buffeer size after window creation using GetClientRect or - the other way round -  re-adjust the window to a desired size using AdjustWindowRect[Ex].

 

Edit: Something else: If you render such one-colored opaque rectangles a similar effect can happen, due to floating point rounding and the way the rasterizer works. One can prevent this using a textured sprite with smooth edges, linear texture filtering and e.g. alpha blending.

Edited by unbird

Share this post


Link to post
Share on other sites

Using GetClientRect totally worked thank you!

 

I just have a few questions, right now I am using the GetClientRect and resizing my backbuffer based on that. Now does that mean my backbuffer is a little smaller than it should be?

Example: Let say the I want the backbuffer to be 800 x 600. Then I use the GetClientRect method to readjust it. Does that mean my backbuffer is really like 750 x 550 because of the window boarders and title bar?

 

Also, if I use the method AdjustWindowRectEx (because I use a CreateWindowEx to make my window) there is a weird distortion on my sprite. Is this because I am using the method or calculating the RECT object wrong? Or is because I have to apply filtering to my textures?


//Code to set up the d3dpp	
d3dpp.Windowed = true;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
d3dpp.BackBufferCount = 1;

//Set the size of the back buffer
d3dpp.BackBufferWidth = 800;
d3dpp.BackBufferHeight = 600;
d3dpp.hDeviceWindow = winHandle;

//Set the size of the rect to base the window on
RECT rect;
rect.top = 0;
rect.bottom = 600;
rect.left = 0;
rect.right = 800;

//readjust the window size
AdjustWindowRectEx(&rect, WS_OVERLAPPEDWINDOW, true, NULL);
Edited by noodleBowl

Share this post


Link to post
Share on other sites
Ah, sorry, AdjustWindowRectEx doesn't really adjust the window, it just changes the rect parameter. It's actually mentioned in the docs that one should use it to get the parameters for CreateWindowEx right, so use it before that. Nontheless: You can still resize/reposition a window after creation with SetWindowPos.

Be careful with the parameters: For one, I don't think you have a menu (third parameter in AdjustWindowRectEx).

Share this post


Link to post
Share on other sites

I see, so I have changed my code to use AdjustWindowRectEx like so

//[ In global area ]
RECT windowSize

//[ Inside the area where I init my window ]

//Set the save/size of the window
windowSize.top = 0;
windowSize.left = 0;
windowSize.right = 800;
windowSize.bottom = 600;
AdjustWindowRectEx(&windowSize, WS_OVERLAPPEDWINDOW, false, NULL);

//[ Inside the area where I init DirectX ]
RECT rect;
GetClientRect(winHandle, &rect);

d3dpp.Windowed = true;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
d3dpp.BackBufferCount = 1;
d3dpp.BackBufferWidth = rect.right - rect.left;
d3dpp.BackBufferHeight = rect.bottom - rect.top;
d3dpp.hDeviceWindow = winHandle;

Is this correct? Am I supposed to use both AdjustWindowRectEx and GetClientRect in tandem? If I just use the windowSize rect when setting up direct x, there seems to be a small offset where my backbuffer is smaller than intended

Share this post


Link to post
Share on other sites
Either one is fine, but use whatever suits you best. If you wanna have a predefined resolution, then AdjustWindowRectEx is fine. GetClientRect comes in handy when you want to support window resizing (note: This is much more cumbersome with D3D9 since it will additionally need a so-called device reset).

Share this post


Link to post
Share on other sites

Either one is fine, but use whatever suits you best. If you wanna have a predefined resolution, then AdjustWindowRectEx is fine. GetClientRect comes in handy when you want to support window resizing (note: This is much more cumbersome with D3D9 since it will additionally need a so-called device reset).

 

I am a little confused, you say I should only need to use one

 

But if I use AdjustWindowRectEx and then create the backbuffer based on the RECT passed into the function

the backbuffer is larger than 800 x 600.

 

Now if I just use GetClientRect and then use the RECT I pass into that function, my backbuffer is smaller than intended (eg the backbuffer is 750 x 550 instead the desired size of 800 x 600)

 

It is only when I incorrperate both do I get the desired size of 800 x 600 for the backbuffer. So is this something that I have to do, use both AdjustWindowRectEx and GetClientRect, or am I just doing it wrong?

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!