Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Can't compile basic circle  (Read 4143 times)

0 Members and 1 Guest are viewing this topic.

Niely

  • Full Member
  • ***
  • Posts: 101
    • View Profile
Can't compile basic circle
« on: January 01, 2015, 08:40:28 pm »
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:
Quote
g++ -o gui gui.cpp -lsfml-graphics -lsfml-system -std=c++11

G++ compiler output:
Quote
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

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Can't compile basic circle
« Reply #1 on: January 01, 2015, 08:49:26 pm »
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.

Niely

  • Full Member
  • ***
  • Posts: 101
    • View Profile
Re: Can't compile basic circle
« Reply #2 on: January 01, 2015, 09:18:05 pm »
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);
}
~                                                

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Can't compile basic circle
« Reply #3 on: January 01, 2015, 09:23:06 pm »
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.
« Last Edit: January 01, 2015, 09:28:53 pm by Jesper Juhl »

Niely

  • Full Member
  • ***
  • Posts: 101
    • View Profile
Re: Can't compile basic circle
« Reply #4 on: January 01, 2015, 11:48:07 pm »
Help-Docs don't help me at all regarding graphic library, and books also don't.
Renderwindow also doesn't work...

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Can't compile basic circle
« Reply #5 on: January 01, 2015, 11:54:17 pm »
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.

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Can't compile basic circle
« Reply #6 on: January 02, 2015, 12:07:07 am »
I have a simple 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.

Niely

  • Full Member
  • ***
  • Posts: 101
    • View Profile
Re: Can't compile basic circle
« Reply #7 on: January 02, 2015, 02:24:46 pm »
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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Can't compile basic circle
« Reply #8 on: January 02, 2015, 02:27:33 pm »
There's no default font in SFML, this was a SFML 1.x thing that was removed.
Laurent Gomila - SFML developer

Niely

  • Full Member
  • ***
  • Posts: 101
    • View Profile
Re: Can't compile basic circle
« Reply #9 on: January 02, 2015, 04:42:12 pm »
^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?

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Can't compile basic circle
« Reply #10 on: January 02, 2015, 04:50:54 pm »
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.

Niely

  • Full Member
  • ***
  • Posts: 101
    • View Profile
Re: Can't compile basic circle
« Reply #11 on: January 02, 2015, 05:08:29 pm »
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...

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Can't compile basic circle
« Reply #12 on: January 02, 2015, 05:14:51 pm »
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).

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10823
    • View Profile
    • development blog
    • Email
Re: Can't compile basic circle
« Reply #13 on: January 02, 2015, 06:16:35 pm »
[...] 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. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Can't compile basic circle
« Reply #14 on: January 06, 2015, 01:12:27 am »
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...
« Last Edit: January 12, 2015, 07:26:21 pm by Jesper Juhl »