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.


Messages - Valky

Pages: [1]
1
Graphics / Error : with my Texture
« on: October 12, 2014, 08:32:19 pm »
Sorry, I'm a beginner with the SFML. I have just started to make projects with it.
And I have a annoying error ! The window draws a white square with the same dimension as the image that I want to draw. I think it's a problem with my texture.

Here's the code :
main.cpp
#include <SFML/Graphics.hpp>
#include "gastaud.h"
#include <iostream>

using namespace std;


int main()
{

    sf::RenderWindow app(sf::VideoMode(800, 600), "SFML window");
    Gastaud leboss;

    while (app.isOpen())
    {
        // Process events
        sf::Event event;
        while (app.pollEvent(event))
        {
            // Close window : exit
            if (event.type == sf::Event::Closed)
                app.close();
        }

        // Clear screen
        app.clear();

        // Draw the sprite
        app.draw(leboss.getPhotoGastaud());
        // Update the window
        app.display();
    }

    return EXIT_SUCCESS;
}
 

gastaud.h
#ifndef GASTAUD_H_INCLUDED
#define GASTAUD_H_INCLUDED
#include <SFML/Graphics.hpp>

class Gastaud
{
    public :
    Gastaud();
    sf::Sprite getPhotoGastaud();
    sf::Texture PreparePhoto();

    private :
    sf::Sprite *PhotoGastaud;

};
#endif // GASTAUD_H_INCLUDED
 

gastaud.cpp
#include "gastaud.h"
#include <SFML/Graphics.hpp>
#include <iostream>

using namespace std;

Gastaud::Gastaud()
{
    PhotoGastaud = new sf::Sprite;
    PhotoGastaud->setTexture(PreparePhoto());
}

sf::Sprite Gastaud::getPhotoGastaud()
{
    return *PhotoGastaud;
}

sf::Texture Gastaud::PreparePhoto()
{
    sf::Texture textureProf;
    if(!textureProf.loadFromFile("gastaud.png"))
    {
        cout << "Probleme with the image : gastaud.png !" << endl;
    }
    textureProf.setSmooth(true);
    return textureProf;
}
 

Can you help me to fix the problem ?

Pages: [1]
anything