SFML trouble with rect()

I've just gotten SFML installed and running on visual C++, but I can't seam to get rect() to run. can anyone tell me what I'm doing wrong in this code;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 #include "SFML/Graphics.hpp"
#include <string>
#include <iostream>
using namespace std;
int main()
{
	string a = "hello", b="again";

    sf::RenderWindow window(sf::VideoMode(600, 400), "SFML works!");
    sf::Text text(a + b);


    while (window.isOpen())
    {
		
		sf::Text Text1(a + b);
		sf::Rect rect(30,30,200,100);
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear(sf::Color(23,45,120));
        window.draw(Text1);
		window.draw(rect);
        window.display();
    }

    return 0;
}


The debugger errors are;

1>------ Build started: Project: main, Configuration: Debug Win32 ------
1> main.cpp
1>c:\users\michael\documents\visual studio 2010\projects\main\main\main.cpp(17): error C2955: 'sf::Rect' : use of class template requires template argument list
1> c:\users\michael\desktop\sfml-2.0-rc\include\sfml\graphics\rect.hpp(43) : see declaration of 'sf::Rect'
1>c:\users\michael\documents\visual studio 2010\projects\main\main\main.cpp(17): error C2514: 'sf::Rect' : class has no constructors
1> c:\users\michael\desktop\sfml-2.0-rc\include\sfml\graphics\rect.hpp(43) : see declaration of 'sf::Rect'
1>c:\users\michael\documents\visual studio 2010\projects\main\main\main.cpp(27): error C2664: 'void sf::RenderTarget::draw(const sf::Drawable &,const sf::RenderStates &)' : cannot convert parameter 1 from 'sf::Rect' to 'const sf::Drawable &'
1> Reason: cannot convert from 'sf::Rect' to 'const sf::Drawable'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Last edited on
Wow, thanks, I wasn't expecting to have to call so many different functions in order to draw a rectangle.
Also thanks for the web-page, I remember stumbling across those class outlines, but I was having trouble installing SFML so I didn't remember that I'd seen that. Very helpful, will consult them before asking any more SFML questions.

Edit;
So I did some playing around, the whole vector thing took a minute to understand. I just hate to leave a topic without some kind of working code, so, uh,

Expanding Rectangle!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include "SFML/Graphics/Rect.hpp"
#include <string>
#include <iostream>
using namespace std;
int main()
{
	string a = "hello", b="again";

    sf::RenderWindow window(sf::VideoMode(600, 400), "SFML works!");
    sf::Text text(a + b);
	sf::Vector2f v(24.1f,29.0f);

    while (window.isOpen())
    {
		
		sf::Text Text1(a + b);
		
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }
		
		v.x++;
                v.y+=.2;
 sf::RectangleShape rectangle;
 rectangle.setSize(v);
 rectangle.setOutlineColor(sf::Color(33,233,22));
 rectangle.setFillColor(sf::Color(144,33,223));
 rectangle.setOutlineThickness(5);
 rectangle.setPosition(50, 120);

        window.clear(sf::Color(23,45,120));
        window.draw(Text1);
		window.draw(rectangle);
        window.display();
	
    }

    return 0;
}

Thanks Again!
Last edited on
Topic archived. No new replies allowed.