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

Author Topic: SFML textures not loading  (Read 4347 times)

0 Members and 1 Guest are viewing this topic.

masterassassin1398

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
SFML textures not loading
« on: October 07, 2014, 08:03:29 pm »
Hiya.  I am having some problems trying to load my texture file.  I dont fully understand textures at all i dont feel that the tutorial is as descriptive as i would want it to be as far as what a texture is and what it is used for.  The way i am interpreting it is that its an image with a bunch of (for example characters) things on it and a sprite is an individual thing(character).  Im so confused =/  Anyway i am using codeblocks and c++.  My image is within the same file as my exe and everything else, i added the image file to my codeblocks project but that didnt seem to do anything.  Im not sure what else i could do.  Can anyone tell me what a texture is and how to use it?  And also what might be wrong with my code?  The reason it says its not working is because it is unable to open file.

Code:
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <iostream>

using namespace std;

int main(){
sf::RenderWindow window(sf::VideoMode(800, 600), "Insomnia");
window.setPosition(sf::Vector2i(0, 0));
sf::Vector2u size = window.getSize();
unsigned int windowLength = size.x;
unsigned int windowWidth = size.y;

while(window.isOpen()){
    sf::Texture texture;
    if(!texture.loadFromFile("TextureImage")){
        return 1;
    }

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

    if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)){
            window.close();
        }

        window.clear(sf::Color::Black);

        window.display();
}
return 0;
}

 
« Last Edit: October 07, 2014, 08:06:27 pm by masterassassin1398 »

ripps

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: SFML textures not loading
« Reply #1 on: October 07, 2014, 09:04:15 pm »
Could you try adding the extension to the filename?

eg.
!texture.loadFromFile("TextureImage.png")

The way I think of textures and sprites is the sprite is the object that you move, the texture is its "skin" - or what you see. You can't see a sprite.

Hope that makes sense.

masterassassin1398

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Re: SFML textures not loading
« Reply #2 on: October 08, 2014, 12:46:04 am »
Ahh yes of course I totally missed that.  And ya it kinda makes sense.  I will have to look into it more.  Thank you.

didii

  • Full Member
  • ***
  • Posts: 122
    • View Profile
Re: SFML textures not loading
« Reply #3 on: October 08, 2014, 01:09:16 pm »
The documentation is always a good place if you don't know exactly what each class does ;)

masterassassin1398

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Re: SFML textures not loading
« Reply #4 on: October 08, 2014, 05:48:30 pm »
Thank you  :)

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: SFML textures not loading
« Reply #5 on: October 09, 2014, 01:36:32 am »
A sprite is basically a rectangle and a texture is what can be shown on that rectangle.

You could think of it like a painting on the wall:
Sprite is the frame.
Texture is the painting.
Without a painting, it's just an empty frame.
Without a frame, there's no way to display the painting.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything