SFML community forums

Help => Graphics => Topic started by: dragondgold on May 03, 2013, 03:19:04 am

Title: SFML 2.0 crappy graphics on Intel GMA3150
Post by: dragondgold on May 03, 2013, 03:19:04 am
Hello! I have recently started using SFML 2.0 with Thor 2.0. I made an example program to learn how the library works and I have correctly running it on my Ubuntu x64 PC in Eclipse:

#include <SFML/System.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <Thor/Animation.hpp>
#include <Thor/Particles.hpp>
#include <iostream>

int main()
{
        bool moveText = false;

        // Create the main window
        sf::RenderWindow Ventana(sf::VideoMode(800, 600), "Prueba Juego con SFML");

        // Create a graphical string to display
        sf::Font font;
        if(!font.loadFromFile("gkfont.ttf")) return EXIT_FAILURE;
        sf::Text mText("Hello!! :D", font, 50);

        sf::Music miMusica;
    if (!miMusica.openFromFile("musica.ogg")) return EXIT_FAILURE;

    Ventana.setFramerateLimit(60);
    Ventana.clear(sf::Color::Black);

        // Start the game loop
        while (Ventana.isOpen()){
                // Process events
                sf::Event Event;
                while (Ventana.pollEvent(Event)){
                        // Close window : exit
                        if (Event.type == sf::Event::Closed) Ventana.close();
                        if (Event.type == sf::Event::MouseButtonPressed){
                                mText.setPosition(Event.mouseButton.x, Event.mouseButton.y);
                                Ventana.draw(mText);
                                moveText = true;
                        }
                        if(Event.type == sf::Event::MouseMoved && moveText == true){
                                Ventana.clear(sf::Color::Black);
                                mText.setPosition(Event.mouseMove.x, Event.mouseMove.y);
                                Ventana.draw(mText);
                        }
                        if(Event.type == sf::Event::MouseButtonReleased){
                                Ventana.clear(sf::Color::Black);
                                moveText = false;
                        }
                        if(Event.type == sf::Event::KeyPressed && moveText){
                                if(Event.key.code == sf::Keyboard::A) mText.setCharacterSize(mText.getCharacterSize()-2);
                                if(Event.key.code == sf::Keyboard::S) mText.setCharacterSize(mText.getCharacterSize()+2);
                                Ventana.clear(sf::Color::Black);
                                Ventana.draw(mText);
                        }
                        if(Event.type == sf::Event::KeyPressed){
                                if(Event.key.code == sf::Keyboard::P) miMusica.pause();
                                if(Event.key.code == sf::Keyboard::O) miMusica.play();
                        }
                }
                // Update the window
                Ventana.display();
        }

        return EXIT_SUCCESS;
}

The program simply shows a text where the mouse pointer is, you can change its size pressing keys A and S and play music pressing O and P, everything ok.
The problem is when I try to run it on my netbook with Windows XP x86, Intel GMA3150, 1Gb RAM and Intel Athom even this very simple program is very slow and choppy:

The graphics card have OpenGL v1.4 I think it should be ok to display a simple text. I already updated the drivers to the latest version. Hope you can help me :)
Title: Re: SFML 2.0 crappy graphics on Intel GMA3150
Post by: Jebbs on May 03, 2013, 04:49:52 am
I'm not sure if this will help solve the problem, but I wouldn't put the Ventana.clear(sf::Color::Black) nor the Ventana.draw(mText) lines inside your events like that. Mixing event code with drawing might be what's causing the issues. What you would probably want is something along these lines.

#include <SFML/System.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <Thor/Animation.hpp>
#include <Thor/Particles.hpp>
#include <iostream>

int main()
{
    bool moveText = false;

    // Create the main window
    sf::RenderWindow Ventana(sf::VideoMode(800, 600), "Prueba Juego con SFML");

    // Create a graphical string to display
    sf::Font font;
    if(!font.loadFromFile("gkfont.ttf")) return EXIT_FAILURE;
    sf::Text mText("Hello!! :D", font, 50);

    sf::Music miMusica;
    if (!miMusica.openFromFile("musica.ogg")) return EXIT_FAILURE;

    Ventana.setFramerateLimit(60);
    Ventana.clear(sf::Color::Black);

    // Start the game loop
    while (Ventana.isOpen()){
        // Process events
        sf::Event Event;
        while (Ventana.pollEvent(Event)){
            // Close window : exit
            if (Event.type == sf::Event::Closed) Ventana.close();
            if (Event.type == sf::Event::MouseButtonPressed){
                mText.setPosition(Event.mouseButton.x, Event.mouseButton.y);
                moveText = true;
            }
            if(Event.type == sf::Event::MouseMoved && moveText == true){
                mText.setPosition(Event.mouseMove.x, Event.mouseMove.y);
               
            }
            if(Event.type == sf::Event::MouseButtonReleased){
                moveText = false;
            }
            if(Event.type == sf::Event::KeyPressed && moveText){
                if(Event.key.code == sf::Keyboard::A) mText.setCharacterSize(mText.getCharacterSize()-2);
                if(Event.key.code == sf::Keyboard::S) mText.setCharacterSize(mText.getCharacterSize()+2);
               
            }
            if(Event.type == sf::Event::KeyPressed){
                if(Event.key.code == sf::Keyboard::P) miMusica.pause();
                if(Event.key.code == sf::Keyboard::O) miMusica.play();
            }
        }

        // Update the window
        Ventana.clear(sf::Color::Black);
        Ventana.draw(mText);
        Ventana.display();
    }

    return EXIT_SUCCESS;
}
 
Title: Re: SFML 2.0 crappy graphics on Intel GMA3150
Post by: dragondgold on May 03, 2013, 05:54:00 pm
Nice! Thank you! The flashing screen has disappeared and the text is being rendered correctly I can read it now :D
But still it is very slow, the movement is not smooth at all! I am not an expert on graphics but how can't a simple text move along a screen but if I run Warcraft 3 on OpenGL mode runs smooth (on low graphics)
Title: Re: SFML 2.0 crappy graphics on Intel GMA3150
Post by: eXpl0it3r on May 03, 2013, 06:04:38 pm
What about using the realtime class sf::Mouse:

#include <SFML/System.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <Thor/Animation.hpp>
#include <Thor/Particles.hpp>
#include <iostream>

int main()
{
    bool moveText = false;

    // Create the main window
    sf::RenderWindow Ventana(sf::VideoMode(800, 600), "Prueba Juego con SFML");

    // Create a graphical string to display
    sf::Font font;
    if(!font.loadFromFile("gkfont.ttf")) return EXIT_FAILURE;
    sf::Text mText("Hello!! :D", font, 50);

    sf::Music miMusica;
    if (!miMusica.openFromFile("musica.ogg")) return EXIT_FAILURE;

    Ventana.setFramerateLimit(60);
    Ventana.clear(sf::Color::Black);

    // Start the game loop
    while (Ventana.isOpen()){
        // Process events
        sf::Event Event;
        while (Ventana.pollEvent(Event)){
            // Close window : exit
            if (Event.type == sf::Event::Closed) Ventana.close();
            else if(Event.type == sf::Event::KeyPressed && moveText){
                if(Event.key.code == sf::Keyboard::A) mText.setCharacterSize(mText.getCharacterSize()-2);
                if(Event.key.code == sf::Keyboard::S) mText.setCharacterSize(mText.getCharacterSize()+2);
               
            }
            else if(Event.type == sf::Event::KeyPressed){
                if(Event.key.code == sf::Keyboard::P) miMusica.pause();
                if(Event.key.code == sf::Keyboard::O) miMusica.play();
            }
        }

                if(sf::Mouse::isButtonPressed(sf::Mouse::Left))
                        mText.setPosition(static_cast<sf::Vector2f>(sf::Mouse::getPosition(Ventana)));
               
        // Update the window
        Ventana.clear(sf::Color::Black);
        Ventana.draw(mText);
        Ventana.display();
    }
}
Title: Re: SFML 2.0 crappy graphics on Intel GMA3150
Post by: dragondgold on May 03, 2013, 06:39:32 pm
It works slightly better but still slow, here is the code, I added the color transparent to hide the text when I release the mouse button:

#include <SFML/System.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <Thor/Animation.hpp>
#include <Thor/Particles.hpp>
#include <iostream>

int main()
{
    bool moveText = false;

    // Create the main window
    sf::RenderWindow Ventana(sf::VideoMode(800, 600), "Prueba Juego con SFML");

    // Create a graphical string to display
    sf::Font font;
    if(!font.loadFromFile("gkfont.ttf")) return EXIT_FAILURE;
    sf::Text mText("Hello!! :D", font, 50);

    sf::Music miMusica;
    if (!miMusica.openFromFile("musica.ogg")) return EXIT_FAILURE;

    Ventana.setFramerateLimit(60);
    mText.setColor(sf::Color::Transparent);

    // Start the game loop
    while (Ventana.isOpen()){
        // Process events
        sf::Event Event;
        while (Ventana.pollEvent(Event)){
            // Close window : exit
            if (Event.type == sf::Event::Closed) Ventana.close();
            else if(Event.type == sf::Event::KeyPressed && moveText){
                if(Event.key.code == sf::Keyboard::A) mText.setCharacterSize(mText.getCharacterSize()-2);
                if(Event.key.code == sf::Keyboard::S) mText.setCharacterSize(mText.getCharacterSize()+2);

            }
            else if(Event.type == sf::Event::KeyPressed){
                if(Event.key.code == sf::Keyboard::P) miMusica.pause();
                if(Event.key.code == sf::Keyboard::O) miMusica.play();
            }
            else if(Event.type == sf::Event::MouseButtonReleased) mText.setColor(sf::Color::Transparent);
        }

        if(sf::Mouse::isButtonPressed(sf::Mouse::Left)){
                mText.setColor(sf::Color::White);
            mText.setPosition(static_cast<sf::Vector2f>(sf::Mouse::getPosition(Ventana)));
        }

        // Update the window
        Ventana.clear(sf::Color::Black);
        Ventana.draw(mText);
        Ventana.display();
    }
}
Title: Re: SFML 2.0 crappy graphics on Intel GMA3150
Post by: dragondgold on May 05, 2013, 12:38:05 am
Ok I think the problem is related to Events Polling because if I draw simple graphics moving around the screen they move smooth.
Title: Re: SFML 2.0 crappy graphics on Intel GMA3150
Post by: eXpl0it3r on May 05, 2013, 12:42:27 am
Is it also slow, when you don't move your mouse over the window? If not, what mouse are you using?
Title: Re: SFML 2.0 crappy graphics on Intel GMA3150
Post by: dragondgold on May 05, 2013, 01:09:32 am
Is it also slow, when you don't move your mouse over the window? If not, what mouse are you using?

I need to move the mouse in order to move my text around the screen. But I did a simple pong program who hits the screen limits and it is smooth and I don't use Events and it is more graphics intensive than this program writing text.