I'm trying to alter the view of a sf::RenderWindow - unfortunately, it seems to behavior weirdly, if I try to alter it from within a function.
I'm using version 1.6 (the official current version of SFML).
#include <SFML/Graphics.hpp>
#include <iostream>
void ChangeView(sf::RenderWindow *window)
{
window->SetView(sf::View(sf::FloatRect(0, 0, 640, 480)));
}
int main(int argc, char *argv[])
{
sf::RenderWindow window(sf::VideoMode(800, 600), "Titlebar text");
//Get default view's coordinate.
sf::Vector2f pos1 = window.ConvertCoords(0, 0);
//Change the view.
window.SetView(sf::View(sf::FloatRect(0, 0, 640, 480)));
//Get the coordinate now.
sf::Vector2f pos2 = window.ConvertCoords(0, 0);
//Change the view via a function.
ChangeView(&window);
//Get the view now.
sf::Vector2f pos3 = window.ConvertCoords(0, 0);
//Print out the results. Why is the third one different?
std::cout << "Pos1: (" << pos1.x << ", " << pos1.y << ")\n"
<< "Pos2: (" << pos2.x << ", " << pos2.y << ")\n"
<< "Pos3: (" << pos3.x << ", " << pos3.y << ")\n";
return 0;
}
See how the function 'ChangeView' is calling completely identical code to when I call 'SetView' in main() itself? Both are calling it like this:
window.SetView(sf::View(sf::FloatRect(0, 0, 640, 480)));
However, both are giving different results!
My output:
Pos1: (0, 0)
Pos2: (0, 0)
Pos3: (0, 240) <--- Why's this one different?
I've been looking at this for a few hours now, and can't find my mistake. Why are the results different if I'm calling them in the exact same way? Anyone know what I'm doing wrong?