-
Hello
I want to start creating my small GUI for my application.
But I can't even compile the example code for a circle.
C++ code:
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
using namespace std;
int main() {
sf::CircleShape shape(50);
// set the shape color to green
shape.setFillColor(sf::Color(100, 250, 50));
window.draw(shape);
}
G++ compiler input:
g++ -o gui gui.cpp -lsfml-graphics -lsfml-system -std=c++11
G++ compiler output:
gui.cpp: In function ‘int main()’:
gui.cpp:12:1: error: ‘window’ was not declared in this scope
window.draw(shape);
What is going wrong here?
Thanks for reading,
Niely
-
What is going wrong here?
You never create the "window" variable that your code refers to. Which the compiler also told you, plain and simple.
-
No I get the error: "No member named draw".
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
using namespace std;
int main() {
sf::CircleShape shape(50);
sf::Window window;
// set the shape color to green
shape.setFillColor(sf::Color(100, 250, 50));
window.draw(shape);
}
~
-
You want sf::RenderWindow
Please read the tutorials: http://www.sfml-dev.org/tutorials/2.2/
And the API documentation: http://www.sfml-dev.org/documentation/2.2/
And, I'm tempted to say, a good C++ book.
-
Help-Docs don't help me at all regarding graphic library, and books also don't.
Renderwindow also doesn't work...
-
Could you try being a little more specific about the actual problem you're having? I think a lot of us would strongly disagree with all three of those claims.
-
I have a simple bouncing ball (https://github.com/SFML/SFML/wiki/Source%3A-Bouncing-ball) example (that even uses circles like you seem to want) posted on the wiki that I know works on multiple platforms with multiple compilers (and it's a public piece of code that everyone can try, so let's use that as our reference example/code here - ok?).
Could you please try that and tell me if it works for you or not - and if it does not, then please tell us exactly what compiler/linker/runtime errors you get.
-
That's a really nice one! :)
Compiling does work with Clang++ but not with G++.
I'll keep that example for sure.
And I now understand how to draw shapes, it worked for me.
The only problem now is that I don't know how to get the default font with text.
Error:
GetDefaultFont() is not a member of sf::Font.
-
There's no default font in SFML, this was a SFML 1.x thing that was removed.
-
^Never mind. Fixed that by putting an Arial.ttf file into my project folder.
So it's cross-platform.
But my next problem, the window with graphics open in a new window. How can I keep doing cout's and cin's in that window?
-
A console window (where cin/cout go) and a gui window are two different things. You can't do both in the same window.
You can draw text in your non-console window with things like sf::Text, but if the goal is to see debugging output it's easiest to just configure your project so you have the console window in debug mode but not release mode.
-
That's a shame... :/
I just wanted a small header in top of my Terminal with the name of the application in it.. Nothing more...
-
I can't really tell what you're trying to describe there, but if you're asking for the ability to change the text in the console window's titlebar, I don't believe SFML provides that feature (it kind of assumes you want a "real" window you can draw things in; if you actually want to write a command-line console app then SFML isn't much use anyway).
-
[...] if you actually want to write a command-line console app then SFML isn't much use anyway).
Unless you want to use the system, audio or network module. ;)
-
That's a really nice one! :)
Thank you.
Compiling does work with Clang++ but not with G++.
I'm curious to know how that does not work with g++. it works fine for me on multiple Linux distributions - for example on CentOS 7 with g++ 4.8.2 :
[jj@jj src]$ g++ --version
g++ (GCC) 4.8.2 20140120 (Red Hat 4.8.2-16)
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[jj@jj src]$ g++ -std=c++11 -O3 -lsfml-window -lsfml-graphics -lsfml-system -o bounce bounce.cc
[jj@jj src]$ ./bounce
[jj@jj src]$ echo $?
0
What errors are you getting exactly?
Compiler errors? Linker errors? Runtime errors?
I'd really like to know so I can revise the example so it works perfectly for everyone as it is supposed to...