Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

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.


Messages - M.S.T.O.P.

Pages: [1]
1
Window / Window init problem
« on: July 26, 2010, 10:36:06 pm »
OK, I have it working now.  Thanks for the help.  :)

2
Window / Window init problem
« on: July 24, 2010, 05:43:44 am »
I'm trying to initialize a window (win) in the constructor of an class (Program), but the window closes as soon as the the constructor finishes, preventing the main loop (mainLoop) from running.  There are no compiler errors, and I'm using SFML 1.6 with Visual Studio C++ 2008 Express.  My code is shown below:

Code: [Select]
// 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;
}

Pages: [1]
anything