how to display this?

closed account (Dy7SLyTq)
so im building this app, but im completely new to sfml (its 1.6 btw; dont ask. i am required to use it) and am having trouble with the tutorial. heres my code... but its not showing the string. just a snapshot of the process behind it

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
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>

int main(int argc, char *argv[])
{
    sf::Window       App(sf::VideoMode(800, 600, 32), "F*ck it. Uploads Happen.");
    sf::RenderWindow Window;
    sf::Font         Font;

    if(!Font.LoadFromFile("Tr2n.ttf")) Font = sf::Font::GetDefaultFont();

    sf::String Text("Hello, world!", Font, 50);

    Window.Draw(Text);

    while(App.IsOpened())
    {
        sf::Event Event;

        while(App.GetEvent(Event))
        {
            if(Event.Type == sf::Event::Closed)                                              App.Close();
            if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape)) App.Close();
        }
    }

    return EXIT_SUCCESS;
}
Last edited on
Your sf::Window is your sf::RenderWindow. You don't have to create another RenderWindow.

Get rid of your 'Window' and render to your 'App'.
closed account (Dy7SLyTq)
so wait... they are the same thing?
closed account (Dy7SLyTq)
i got rid of line 7 and added Render to the window, then replaced window with app on line 14
closed account (Dy7SLyTq)
nvr mnd... i skipped a tutorial
closed account (Dy7SLyTq)
ok wait... last thing heres my 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
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Fuck it. Uploads happen.");
    sf::Font         Font;

    if(!Font.LoadFromFile("Tr2n.ttf")) Font = sf::Font::GetDefaultFont();

    sf::String Text("Hello, world!", Font, 50);

    Text.SetColor(sf::Color(4, 128, 0));

    while(App.IsOpened())
    {
        sf::Event Event;

        while(App.GetEvent(Event))
        {
            if(Event.Type == sf::Event::Closed)                                              App.Close();
            if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape)) App.Close();
        }

        App.Clear   ();
        App.Display ();
    }

    return EXIT_SUCCESS;
}
Well you're not drawing your 'Text' object anywhere in that code. You're just clearing the screen.

1
2
3
        App.Clear   ();
        App.Draw(Text);  // <- need to draw your text here
        App.Display ();
closed account (Dy7SLyTq)
oh my god you rock. thanks.
closed account (Dy7SLyTq)
one last question... in java there is a class that can display an options bar. how would i do this in sfml?
Like a toolbar? That's more of a widgetry thing, and isn't something SFML is designed to do.
closed account (Dy7SLyTq)
damn oh well. ill just make it window based then
Topic archived. No new replies allowed.