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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Haku

Pages: [1]
1
Graphics / Function Returning White Sprite
« on: May 31, 2012, 06:17:55 pm »
I know there are much better ways to implement intro screens and such, but I'm just messing around with SFML first to see its power. The problem with the code below is that the drawIntro() function seems to be returning a blank sprite. If anyone can figure out why, it would be greatly appreciated. I'm using SFML 2.0 RC 25.

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

using namespace std;

sf::Sprite drawIntro();

int main()
{
        // Variable declaration
        int gameState = 0;

        // Create the main window
        sf::RenderWindow window(sf::VideoMode(800, 600), "SFML works!");
       
        sf::Text text("Hello SFML");

        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                        window.close();
                }

                // Clear screen
                window.clear();

                // Game logic
                switch(gameState)
                {
                        case 0:
                                window.draw(drawIntro());
                                break;
                        case 1:
                                break;
                        case 3:
                                break;
                }
                //window.draw(text);

                // Update the window
                window.display();
        }

        return 0;
}

sf::Sprite drawIntro()
{
        // Create a new render-texture
        sf::RenderTexture texture;
        //texture.create(800, 600);
        if (!texture.create(800, 600))
                cout<< "Unable to create texture" << endl;
                //return -1;

        // Declare and load a font
        //sf::Font font;
        //font.loadFromFile("resources/fonts/lazy.ttf");       

        //sf::Text text("test");
        /*text.setFont(font);
        text.setCharacterSize(30);
        text.setStyle(sf::Text::Bold);
        text.setColor(sf::Color::Red);*/


        texture.clear(sf::Color::Black);
        //texture.draw(text);
        texture.display();

        sf::Sprite sprite(texture.getTexture());
       
        return sprite;
}
 

Pages: [1]