I started to code a SFML project on Visual Studio Express 2013, i did some tests, everything was fine, then i started the real code and implemented a state manager, that also manages screen drawing, the RenderWindow variable is passed as reference to the draw function of my state manager, but nothing is being drawn.
I already did some tests, the current state is correct, and the texture is apparently being loaded correctly.
main.cpp:
#include <SFML/Graphics.hpp>
#include "statemanager.h"
int main()
{
sf::VideoMode desktop = sf::VideoMode::getDesktopMode();
sf::RenderWindow window(sf::VideoMode(desktop.width, desktop.height, desktop.bitsPerPixel), "Hunt and Explore", sf::Style::Fullscreen);
window.setFramerateLimit(75);
sf::View view(sf::FloatRect(0.0f, 0.0f, desktop.width, desktop.height));
window.setView(view);
StateManager* state_manager = StateManager::getInstance();
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
state_manager->draw(window);
window.display();
}
return 0;
}
statemanager.h:
#ifndef STATEMANAGER_HEADERFILE
# define STATEMANAGER_HEADERFILE
# include <vector>
# include <SFML/Graphics.hpp>
enum GAMESTATE
{
GS_RUNNING,
GS_PAUSED,
GS_MAINMENU
};
class StateManager
{
private:
StateManager(){}
GAMESTATE state;
void changeState(GAMESTATE st);
std::vector<sf::Sprite> loadedSprites;
std::vector<sf::RectangleShape> loadedRects;
sf::Image test;
public:
static StateManager* getInstance()
{
static StateManager* inst;
if (inst)
return inst;
inst = new StateManager();
inst->changeState(GS_MAINMENU);
return inst;
}
bool draw(sf::RenderWindow& w);
};
#endif
statemanager.cpp:
#include "statemanager.h"
void StateManager::changeState(GAMESTATE st)
{
state = st;
switch (state)
{
case GS_MAINMENU:
{
sf::VideoMode dkt = sf::VideoMode::getDesktopMode();
sf::RectangleShape rshape(sf::Vector2f(dkt.width, dkt.height));
rshape.setPosition(sf::Vector2f(0, 0));
sf::Texture texture;
texture.loadFromFile("data/mainmenu/bg.png");
texture.setSmooth(true);
rshape.setTexture(&texture);
loadedRects.push_back(rshape);
}
break;
case GS_PAUSED:
break;
case GS_RUNNING:
break;
default:
break;
}
}
bool StateManager::draw(sf::RenderWindow& w)
{
switch (state)
{
case GS_MAINMENU:
w.draw(loadedRects.back());
break;
case GS_PAUSED:
break;
case GS_RUNNING:
break;
default:
break;
}
return true;
}