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?
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).
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");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.