SFML community forums
Help => Graphics => Topic started by: Wander on January 31, 2011, 07:37:50 am
-
I'm sure I'm just doing views wrong, but how would I fix this?
(http://img703.imageshack.us/img703/4121/fixm.png) (http://img703.imageshack.us/i/fixm.png/)
This should be a REALLY large image vertically. It seems to hold a 1:1 ratio along the X-Axis, but as you can see... the Y-Axis has been crushed from 90,000 to what look more like 5,000. ;( *tear*
Here is my minimal code that reproduces the error:
I'm getting good at this! ;D
#include <SFML\Graphics.hpp>
int main()
{
sf::RenderWindow Window(sf::VideoMode::GetMode(0), "Laz's Interactive Map");
sf::Shape Map;
Map.AddPoint(0,0,sf::Color(0,100,0));
Map.AddPoint(30000,0,sf::Color(0,100,0));
Map.AddPoint(30000,90000,sf::Color(0,100,0));
Map.AddPoint(0,90000,sf::Color(0,100,0));
Map.EnableFill(true);
Map.EnableOutline(false);
sf::View MainView;
MainView.SetFromRect(sf::FloatRect(0,0,30000,90000));
MainView.Zoom(.4f);
sf::Shape Circle = sf::Shape::Circle(5000,5000,2500,sf::Color::Red, 5, sf::Color::Red);
while (Window.IsOpened()) {
Window.Clear();
Window.SetView(MainView);
Window.Draw(Map);
Window.Draw(Circle);
Window.Display();
}
return 0;
}
PS: I'm am 90% sure that this is a View error... I am VERY sketchy in my views... I never know what I'm doing.
Thanks in advance.
-
The content of the view is mapped to the window, so here you are mapping 30000x90000 units to, let's say, 1024x768 pixels. That's why the Y axis is so much squeezed. If you don't want your scene to be distorted, your view must have the same aspect ratio as your window.
-
So, I'm going to have to change my view's size so it won't hold my REALLY large image?
-
Oh! I see what you are saying. But how would I make it change for each different screen size its on.
I tried putting variables in as a replacement for some of the values in the sf::FloatRect but it made my program crash. :/
-
If you want to keep the same aspect ratio as the window, create your view from the default view of the window and then only use Zoom().
Using variables should be fine, show us your code if it doesn't work.
-
Okay it doesn't seem to be working. I will post some minimal code within 10 minutes.
-
Hmmm. I'm having trouble reproducing the error in minimal code... Should I just send a screenshot and view code?
-
Hmmm. I'm having trouble reproducing the error in minimal code... Should I just send a screenshot and view code?
This means that the error is not trivial. So the only way to figure it out, is to gradually fill the gap between the minimal code that works, and the real code that fails. At one point you'll find which little thing makes it go crazy.
-
So the error isn't in my view code? Okay. I'll try to find it. :) Thanks.
-
I'm looking at my code and I really don't see anything that could possible cause this.... Got any ideas? It's the crushing thing again. Just any broad ideas.
EDIT: Oh my god! I just went through my entire code and never found a solution that kept my program fully operational. I fixed it once but that fix caused my key presses to quit working....
-
Yeah, Programming is never an easy task... Good luck! :)