1
Window / Window init problem
« on: July 26, 2010, 10:36:06 pm »
OK, I have it working now. Thanks for the help.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
// program.h
//--------------
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
class Program
{
public:
sf::Window* win;
Program(unsigned int w, unsigned int h, unsigned int bitdepth, char* title);
void mainLoop();
void eventHandler();
void drawScreen();
~Program();
};
//program.cpp
//--------------
#include "program.h"
Program::Program(unsigned int w, unsigned int h, unsigned int bitdepth, char* title)
{
// Create window
win = &sf::Window(sf::VideoMode(w, h, bitdepth), title);
}
void Program::mainLoop()
{
while (win->IsOpened())
{
eventHandler();
drawScreen();
}
}
void Program::eventHandler()
{
sf::Event Event;
while (win->GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
win->Close();
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
win->Close();
}
}
void Program::drawScreen()
{
win->Display();
}
Program::~Program()
{}
//main.cpp
//----------
#include "program.h"
int main()
{
Program p(800, 600, 32, "Test");
p.mainLoop();
return 1;
}