Sfml rendertarget

I wanted to try something like I saw a couple of years ago on scratch:
https://scratch.mit.edu/projects/114926871/
But I also wanted to use a rendertarget.
From what i understand, rendertarget is like a virtual window(Which is not seen by the user), which can then be drawn to a renderwindow. The following code is as far as ive gotten, and upon looking for documentation of errors and examples of the class rendertarget i came up with nothing.
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
#include <iostream>
#include <SFML\Graphics.hpp>
#include <SFML\Window.hpp>
#include <SFML\System.hpp>
using namespace std;
using namespace sf;
const int width = 500;
const int height = 500;
int main()
{
    RenderWindow window(VideoMode(width, height), "Pixels");
    VertexArray point(Points, 1);
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }
        RenderTarget target();
        for(unsigned int i = 0; i != height; i++){
            for(unsigned int j = 0; j != width; j++){
                point[1].position = Vector2f(i, j);
                point[1].color = Color(255, 255, 255);
                target.draw(point);
            }
        }
        window.clear();
        window.draw(target);
        window.display();
    }
}

I am using codeblocks and SFML 2.4.1
The error I get is:
 
error: invalid abstract return type 'sf::RenderTarget'

Thanks for any help you may provide in advance!
Last edited on
You cannot directly instantiate a sf::RenderTarget as this is an abstract class. A sf::RenderWindow is a sf::RenderTarget.

http://www.sfml-dev.org/documentation/2.4.1/classsf_1_1RenderTarget.php#details

I suspect that a sf::RenderTexture is more along the lines of what you're thinking of, although I don't think it is necessarily an appropriate tool for the job.

Line 21 declares a function, by the way, not an object of type RenderTarget. Your code has other issues as well. What is the point of a VertexArray with only one element? You know the only valid index for a container with one element is 0?

Ok, I fixed my code and ended up with this:
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
#include <iostream>
#include <SFML\Graphics.hpp>
#include <SFML\Window.hpp>
#include <SFML\System.hpp>
using namespace std;
using namespace sf;
const int width = 500;
const int height = 500;
int main()
{
    RenderWindow window(VideoMode(width, height), "Pixels");
    VertexArray point(Points, 0);
    Image rtex;
    Sprite container;
    Texture cont;
    container.setTexture(cont);
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }
        for(unsigned int i = 0; i != height; i++){
            for(unsigned int j = 0; j != width; j++){
                point[0].position = Vector2f(i, j);
                point[0].color = Color(255, 255, 255);
                rtex.setPixel(j, i, Color::Blue);
            }
        }
        cont.loadFromImage(rtex);
        window.clear(Color::Green);
        window.draw(container);
        window.display();
    }
}

and it compiles just fine, but when run, it just crashes
and it compiles just fine, but when run, it just crashes

Where is the image rtex given a size? What size is it given?
Topic archived. No new replies allowed.