Visual Studio SFML tutorial graphics not displaying properly - c++

I'm not sure if this is a problem with Visual Studio (I'm using Visual Studio Community 2017) or SFML. I've followed the configuration process on https://www.sfml-dev.org/tutorials/2.4/start-vc.php and used their tutorial code. SFML is indeed configured but test graphic image is not displaying correctly according to the tutorial, and everything seems stretched vertically.
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}

If you're using a notebook with dual-GPU, then your Intel GPU driver is outdated and it has a bug, where it would setup the OpenGL "drawing area" on a window wrongly. Alternatively, you can force your application to run on the dedicated GPU.

Related

error for "Texture" sf not loading for cpp framework called sfml

I am trying to load my texture onto my window.... however when I compile in visual studio on windows 10 laptop It says "sf has no member texture" I'm honestly not sure what on earth is going on! for whatever reason its not loading the sf! if you have any ideas please let me know... thanks so much it means a great deal to me! (I have also tried to use "#include" and it has not worked out for me unfortunately)
#include <SFML/Window.hpp>
int main()
{
sf::Texture texture;
if (!texture.loadFromFile("sheet_1.png"))
{
// error...
}
sf::Window window(sf::VideoMode(800, 600), "My window");
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
}
return 0;
}
Since sf::Texture is not included in Window.hpp you need to also include Graphics.hpp in your project.
#include <SFML/Graphics.hpp>

SFML cannot load image file no matter what I try

I am trying a simple SFML project and it is giving me an error saying that it cannot load the image file. Here is my code:
#include <SFML/Graphics.hpp>
#include <iostream>
using namespace sf;
int main() {
RenderWindow window(VideoMode(600, 600), "Chess");
system("dir");
Texture texture;
texture.loadFromFile("board.png");
Sprite s(texture);
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
//draw
window.clear();
window.draw(s);
window.display();
}
}
I have tried every guide and fix for this problem I could find and not a single one of them has worked. Would anyone be able to help me? And yes, my image files are in the project directory. If it helps, I am using VS 2013.

Use of sf::RenderWindow causes a segmentation fault on linux mint

I'm trying to get SFML working on LinuxMint 18, the Cinnamon version, but I get a segmentation fault, whenever I use sf::RenderWindow.
I installed SFML 2.4.2 by downloading the 64-bit Linux Version from the official website, as
sudo apt-get install libsfml-dev
strangely didn't install the libraries.
Using something different, like sf::Clock works perfectly fine.
I'm using the code from the SFML website, posted below:
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}
Any suggestions?
EDIT: I'm not running Linux Mint in any Virtual Machine. I'm dualbooting with Windows 10. Also the segmentation fault happens to be an invalid pointer error.

Cannot Load clui.dll

for some reason when i try to compile and run this program following the Official SFML Website Tutorial:
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}
I get this error:
Severity Code Description Project File Line Suppression State
Error C1510 Cannot load language resource clui.dll. SFMLPractice1 >c:\Users\NAME\documents\visual studio >2015\Projects\SFMLPractice1\SFMLPractice1\CL 1
I need help on sorting this out.. Please Help!
You can move on to Visual Studio 2017 and install "VC++ 2015.3 v14.00 (v140) toolset for desktop". clui.dll seems to be inside this component.

SFML Window Not Rendering Shape

#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed) {
window.close();
}
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}
This is directly from the tutorial's page, and I've checked and rechecked, so I know this is not a syntax or linker error.
When I run this program, I get a window whose contents are the same as whatever the place it is located in. Yet, if I remove the window.draw(shape) command, I see a black window, like I should.
I'm compiling on Windows 7 (32 bit) using mingw32-g++.exe (4.7.1). Oh, and it's the same if I compile debug or release and static or dynamic, so that's not the problem either.
Your code is correct, but to me it looks like you need to set the position of your circle. I maybe wrong here but the position could be any value and that is why it isn't displaying.
Could you try updating your code to this please.
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
shape.setPosition(50f, 50f);
shape.setScale(2,2); // You can remove this line if you want to, I just put it there for debugging
while (window.isOpen())
{
...
Here is the SFML documentation for setPosition (http://www.sfml-dev.org/documentation/2.0/classsf_1_1Transformable.php#a4dbfb1a7c80688b0b4c477d706550208)
Here is the SFML documentation for setScale (http://www.sfml-dev.org/documentation/2.0/classsf_1_1Transformable.php#aaec50b46b3f41b054763304d1e727471)
Let me know if that fixes your problem.