@lockandstrike
It's already been said, but in your code, where there is a "if(GameWindow.pollEvent(GameEvent))" statement there should be a "while(GameWindow.pollEvent(GameEvent))" statement. Change the code and post the result of that.
I changed it to while and its still not working. I've recompiled SFML 2.0 again from the beginning and tried to make it work with Code::Blocks.
Here's what I have been doing:
First, I downloaded the SFML source from here
https://github.com/SFML/SFML/tarball/masterThen, extracted the files from the zip.
Next I compiled them using Cmake using the command line as per as the instructions on this site :
http://sfmlcoder.wordpress.com/2011/06/16/building-sfml-2-0-with-mingw-make/After compiling everything (Debug and Release), I opened up Code::Blocks 12.11 and went to the compiler settings and added the include and lib directories of SFML 2.0(I added those lib files which I compiled).
Then, I created a new console app, went to its project build options and in the linker setting tab added these:
for debug,
sfml-graphics-d
sfml-system-d
sfml-window-d
for release,
sfml-graphics
sfml-system
sfml-window
Then I added this code:
#include <SFML/Graphics.hpp>
#include <iostream>
const int WINDOW_WIDTH = 800;
const int WINDOW_HEIGHT = 600;
const int WINDOW_BPP = 32;
const char *WINDOW_CAPTION = "MY_SFML";
int main()
{
sf::RenderWindow Window;
Window.create(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_BPP),
WINDOW_CAPTION, sf::Style::Close);
while(Window.isOpen())
{
sf::Event Event;
while(Window.pollEvent(Event))
{
switch(Event.type)
{
case sf::Event::Closed:
{
Window.close();
} break;
case sf::Event::KeyPressed:
{
if(Event.key.code == sf::Keyboard::Escape)
{
Window.close();
}
} break;
}
}
Window.display();
}
}
Uptill this, everything went on as expected. But when I added a few lines to display a circle:
#include <SFML/Graphics.hpp>
#include <iostream>
const int WINDOW_WIDTH = 800;
const int WINDOW_HEIGHT = 600;
const int WINDOW_BPP = 32;
const char *WINDOW_CAPTION = "MY_SFML";
const float CIRCLE_RADIUS = 100.0f;
int main()
{
sf::RenderWindow Window;
Window.create(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_BPP),
WINDOW_CAPTION, sf::Style::Close);
sf::Time Time;
sf::Clock Clock;
sf::CircleShape Circle(CIRCLE_RADIUS);
Circle.setFillColor(sf::Color::Green);
while(Window.isOpen())
{
sf::Event Event;
// Now I've also put pollEvent in a while loop as members
// AlejandroCoria and lockandstrike pointed out
while(Window.pollEvent(Event))
{
switch(Event.type)
{
case sf::Event::Closed:
{
Window.close();
} break;
case sf::Event::KeyPressed:
{
if(Event.key.code == sf::Keyboard::Escape)
{
Window.close();
}
} break;
}
}
Time = Clock.getElapsedTime();
std::cout << Time.asSeconds() << std::endl;
Window.draw(Circle); // problem started after //
Window.display();
Window.clear(); // adding these two lines //
}
}
The pgrogram is building, but when I run it, the console window and sfml window appear and then the sfml window turns white and a windows dialog saying mysfmlprogram.exe has stopped working and windows is looking for a solution. After that nothing happens until I close it.
EDIT:
quoted lockandstrike's reply