Jump to content

  • Log In with Google      Sign In   
  • Create Account


Stretched pixels in windowed mode


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 george7378   Members   -  Reputation: 1185

Like
0Likes
Like

Posted 04 June 2014 - 05:15 PM

Hi all,

 

I've created a simple program using DX9 in windowed mode. It uses a simple diffuse shader to render a mesh in a 640x480 window. The program seems to work fine but there's a strange array of stretched pixels which distort the image. Here's a shot:

 

pix1.png

 

If you can't see them, here's the same image after edge-detect:

 

pix2.png

 

Is there anything I'm overlooking that needs to be done to render in windowed mode (I've been doing fullscreen stuff until now). Thanks!



Sponsor:

#2 L. Spiro   Crossbones+   -  Reputation: 13010

Like
4Likes
Like

Posted 04 June 2014 - 06:46 PM

The pixels aren’t being stretched, they are being squashed.

When the backbuffer and the window are not the same size the image will be rescaled upon presenting, which is what is happening here.

 

Most likely you set the window to 640-480 and you set the back buffer to the same value without taking into account the borders (hence it is squashed more vertically than horizontally, as vertically you have extra window border spent on the title bar).

The client area of a window will be smaller than the actual window size.  Your back buffer must be the same size as the client rectangle to avoid scaling.

 

If you want the client area to be 640-480, adjust the window size using AdjustWindowRect().

 

 

L. Spiro


Edited by L. Spiro, 04 June 2014 - 09:00 PM.

It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#3 IkarusDowned   Members   -  Reputation: 286

Like
1Likes
Like

Posted 04 June 2014 - 08:00 PM

You should also keep in mind that the ratio of buffer size to window size is important. If your backbuffer is set to say 640 x 480 but your window rectangle is 600 x 480, then the result will look "squashed" as you put it. If the window rectangle was, say, 700 x 480, then it would look "stretched."

 

As a rule I like to not optimize unless I must, and also try to keep things simple until it needs to be changed...thus I would suggest that your backbuffer and window rect keep the width and height in constant ratio of each other. I like to use multiples of the back buffer. Again, this isn't "optimal" as much as I just follow the rule: "get it to look right before getting to be fast."



#4 george7378   Members   -  Reputation: 1185

Like
0Likes
Like

Posted 05 June 2014 - 08:19 AM

Thanks for the help, yes, I resized the client area to 640x480 and the problem's solved. That bit of code will be staying in my future projects :)



#5 Buckeye   Crossbones+   -  Reputation: 4170

Like
3Likes
Like

Posted 05 June 2014 - 12:20 PM

As it appears that you're coding a windowed app, a better approach might be to size the backbuffer to the client area, rather than the other way 'round. Using a window means the user may move or resize the window for his/her own convenience, and you should respect that. So, when the window is resized:

RECT rect;
GetClientRect(hwnd, &rect);
params.BackBufferWidth = rect.right - rect.left;
params.BackBufferHeight = rect.bottom - rect.top;
OnDeviceLost(); // prepare objects for device reset
device->Reset( &params );
OnDeviceRestored(); // restore objects after the reset
ResetProjectionAspectRatio(); // account for change in the aspect ratio


Perhaps even better than setting the width/height yourself, unless you have some specific reason to size the backbuffer to a particular size, set the BackBufferWidth and BackBufferHeight to 0, and let D3DX set the buffer to the client area dimensions itself. You can do that when creating the device or when the window is resized (device reset). Just remember to check the aspect ratio of your projection matrix whenever the client/backbuffer is resized.


Edited by Buckeye, 05 June 2014 - 12:35 PM.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS