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

Author Topic: Text not Drawing  (Read 4912 times)

0 Members and 1 Guest are viewing this topic.

Arzimon

  • Newbie
  • *
  • Posts: 4
    • View Profile
Text not Drawing
« on: June 03, 2012, 04:24:25 pm »
Hey all! New to SFML and trying to get the following code to work. Got all the dependencies to work, but now the text won't display.  :P I followed the tutorial on the site but to no avail. here's my code:

#define _WIN32_WINNT 0x500
#include<Windows.h>
#include<SFML/System.hpp>
#include<SFML/Graphics.hpp>
#include<iostream>

using namespace sf;

int main(int argc, char** argv)
{
        HWND hwnd = GetConsoleWindow();
        ShowWindow(hwnd, SW_HIDE);
       
        RenderWindow app;
        const Input& in = app.GetInput();
        Image screen;
        sf::Event e;

        String text("Hello World",Font::GetDefaultFont(),100);
        text.SetColor(Color(0,0,255));
        text.SetStyle(String::Regular);
        text.SetRotation(90.0f);
        text.SetScale(2.0f,2.0f);
        text.Move(10.0f, 10.0f);
        app.Draw(text);
       
        app.Create(VideoMode(800,600), "SFML Fonts");
        app.Display();

       

        while(app.IsOpened())
        {      
                while(app.GetEvent(e))
                {
               
                        if(e.Type == Event::Closed)
                        {
                                app.Close();
                                ShowWindow(hwnd, SW_RESTORE);
                        }
                        if((e.Type == Event::KeyPressed) && (e.Key.Code == Key::Escape))
                        {
                                        app.Close();
                        }

                        if(e.Key.Code == Key::S)
                        {
                                screen = app.Capture();
                                screen.SaveToFile("screenshot.jpg");
                        }

                }

               
               
                app.Clear(Color(Color::White));
                app.Draw(text);
                app.Display();

        }

        return 0;

}
« Last Edit: June 03, 2012, 04:39:05 pm by Laurent »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Text not Drawing
« Reply #1 on: June 03, 2012, 04:41:09 pm »
Does it work if you create the SFML window before doing anything else?

By the way, you don't need this Windows specific code to hide the console. A simple flag in your linker settings can do the job.
Laurent Gomila - SFML developer

Arzimon

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Text not Drawing
« Reply #2 on: June 03, 2012, 05:28:28 pm »
tried creating the window first, no luck.  :(

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Text not Drawing
« Reply #3 on: June 03, 2012, 05:58:33 pm »
You should try SFML 2.
Laurent Gomila - SFML developer

Arzimon

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Text not Drawing
« Reply #4 on: June 03, 2012, 10:52:06 pm »
tried it and its still not showing up, lol. Hopefully its just an error on my part.
Here's the updated code

#include<SFML/System.hpp>
#include<SFML/Graphics.hpp>
#include<iostream>

using namespace sf;

int main(int argc, char** argv)
{      
        RenderWindow app;
       
        Image screen;
        sf::Event e;

        app.create(VideoMode(800,600,32), "SFML Fonts");


        Text text("Hello World",Font::getDefaultFont(),100);
        text.setColor(Color(0,0,255));
        text.setStyle(Text::Regular);
        text.setRotation(90.0f);
        text.setScale(2.0f,2.0f);
        text.move(10.0f, 10.0f);
        app.draw(text);
       
        app.display();


       

        while(app.isOpen())
        {      
                while(app.pollEvent(e))
                {
               
                        if(e.type == Event::Closed)
                        {
                                app.close();
                        }
                        if((e.type == Event::KeyPressed) && (e.key.code == Keyboard::Escape))
                        {
                                        app.close();
                        }

                        if(e.key.code == Keyboard::S)
                        {
                                screen = app.capture();
                                screen.saveToFile("screenshot.jpg");
                        }

                }

               
               
                app.clear(Color(Color::White));
                app.draw(text);
                app.display();

        }

        return 0;
}
« Last Edit: June 04, 2012, 09:16:03 pm by Arzimon »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Text not Drawing
« Reply #5 on: June 04, 2012, 08:09:07 am »
Can you please use the code=cpp tag instead of tt?

Have you tried the precompiled SFML examples?
Laurent Gomila - SFML developer

Arzimon

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Text not Drawing
« Reply #6 on: June 04, 2012, 06:54:48 pm »
All of the examples work except the ones that need OpenAL. my b bout the code.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Text not Drawing
« Reply #7 on: June 04, 2012, 07:34:16 pm »
If the examples work, try to start from them and see what's wrong in your code.

Quote
Can you please use the code=cpp tag instead of tt?
Sorry if it was not clear, but I mean "Can you please edit your previous messages to use the code=cpp tag instead of tt?".
Laurent Gomila - SFML developer

 

anything