Reputation: 497
I just tried to write a chess engine, and what is important to me is that I get a nice visual representation of the game. I tried to implement the Code in a Visual Studio project - the problem is that the program only shows me a black screen instead of the texture I loaded.
My Code is the following:
#include <SFML/Graphics.hpp>
#include <time.h>
using namespace sf;
int main(){
RenderWindow window(VideoMode(1000, 1000), "MattseChess!");
Texture t1;
t1.loadFromFile("images/board.png");
Sprite s(t1);
while (window.isOpen())
{
Event e;
while (window.pollEvent(e)) {
if (e.type == Event::Closed)
window.close();
//Draw
window.clear();
window.draw(s);
window.display();
}
}
return 0;
}
Do you have any idea of what I did wrong?
Upvotes: 0
Views: 614
Reputation: 36567
Make sure to put your drawing code outside your event loop. Otherwise you're only drawing whenever there's some event happening (such as cursor movement).
Upvotes: 2
Reputation: 518
That code works. I am pretty sure you did not put your board.png into the images directory in your execution path.
Make sure this image is available:
t1.loadFromFile("images/board.png");
Upvotes: 0