SFML community forums

Help => Graphics => Topic started by: matt2224 on May 28, 2010, 11:43:05 am

Title: Sprite won't draw correctly
Post by: matt2224 on May 28, 2010, 11:43:05 am
Code: [Select]
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML 2D");
    sf::Image image;
    sf::Sprite sprite;

    image.LoadFromFile("tree.tga");
    sprite.SetImage(image);

    while (App.IsOpened())
    {
        // Event handling
        sf::Event event;
        while (App.GetEvent(event))
        {
            if (event.Type == sf::Event::Closed)
                App.Close();
        }

        glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        glClear(GL_COLOR_BUFFER_BIT);
       
        App.Draw(sprite);
        App.Display();
    }

    return 0;
}


Tree.tga:
(http://img34.imageshack.us/img34/3346/grass1.png)

Output:
(http://img522.imageshack.us/img522/2514/20100528104114800x600sc.png)

Why won't it work?
Title: Sprite won't draw correctly
Post by: Mindiell on May 28, 2010, 12:02:32 pm
I'm unable to see your images (imageshack is blocked at my office), but :
- Use App.Clear() instead of openGL functions
- Verify the LoadFromFile return : is the image loaded correctly ?
Title: Sprite won't draw correctly
Post by: matt2224 on May 28, 2010, 12:05:35 pm
I'm using the OpenGl functions because App.Clear() crashes the program (other people have mentioned this in here before).

The image is loaded correctly, I've just tried checking the return. I'll try and upload the image at a different host if it helps.

Here:

(http://i47.tinypic.com/2wgfz86.png)
Title: Sprite won't draw correctly
Post by: Mindiell on May 28, 2010, 01:48:51 pm
Thx a lot, but there is a lot of websites blocked, even tinypic :)

By the way :
- SFML version ?
- IDE ?
- OS ?

Can you explain with words what is bad on the image ? (tonight I will be able to see them ;) )
Title: Sprite won't draw correctly
Post by: matt2224 on May 28, 2010, 01:50:34 pm
Basically, I have this huge box in the corner with a green-light green gradient. I though it was the sprite but massively upscaled, but if I try to scale it down again it disappears completely.

OS: Ubuntu 10.04
IDE: Qt Creator, but even when I compile manually it doesn't work

How do I find out my SFML version?
Title: Sprite won't draw correctly
Post by: Mindiell on May 28, 2010, 04:19:08 pm
Quote from: "matt2224"
How do I find out my SFML version?
Well, when you installed it, you had to choose a version, no ?
Did you recompile it ? Seems no.
Title: Sprite won't draw correctly
Post by: matt2224 on May 28, 2010, 04:57:45 pm
It's version 1.5
Title: Sprite won't draw correctly
Post by: Mindiell on May 28, 2010, 06:37:28 pm
Ok, using openGL command salterate the render with SFML.
Use PreserveOpenglState (http://www.sfml-dev.org/documentation/1.5/classsf_1_1RenderTarget.htm#b763d16f00166b516fead600d8824c71)
Title: Sprite won't draw correctly
Post by: Laurent on May 28, 2010, 07:08:14 pm
Quote
Ok, using openGL command salterate the render with SFML.
Use PreserveOpenglState

It doesn't matter, glClearColor has an effect only on glClear, it changes nothing for SFML.
Title: Sprite won't draw correctly
Post by: matt2224 on May 28, 2010, 07:16:59 pm
Any ideas Laurent?
Title: Sprite won't draw correctly
Post by: Laurent on May 28, 2010, 08:18:36 pm
What graphics card do you have? Are your drivers up-to-date? Can you run other OpenGL applications?
Title: Sprite won't draw correctly
Post by: matt2224 on May 28, 2010, 08:44:50 pm
Yes. The other tutorial with the 3D rotating cube worked fine.
Title: Sprite won't draw correctly
Post by: Laurent on May 28, 2010, 08:48:26 pm
What if you use another image (like one from the samples)?
Title: Sprite won't draw correctly
Post by: matt2224 on May 28, 2010, 08:53:23 pm
Nope. :( I've already tried a multitude of images.
Title: Sprite won't draw correctly
Post by: Laurent on May 28, 2010, 09:06:32 pm
Do the SFML samples work?
Title: Sprite won't draw correctly
Post by: matt2224 on May 28, 2010, 09:17:02 pm
Most of them don't but I think that's because of App.Clear() crashing them.
Title: Sprite won't draw correctly
Post by: Mindiell on May 28, 2010, 09:32:53 pm
can you verify sprite x and y ?
Can you draw an sf::Shape in order to see if it's ok ?

Seems like a camera position problem, no ?
Title: Sprite won't draw correctly
Post by: Laurent on May 28, 2010, 11:30:53 pm
Quote
Most of them don't but I think that's because of App.Clear() crashing them.

Remove this call and try again, let's say, the OpenGL sample.
Title: Sprite won't draw correctly
Post by: matt2224 on May 29, 2010, 01:23:30 am
It works fine.
Title: Sprite won't draw correctly
Post by: Laurent on May 29, 2010, 10:16:52 am
So now you just have to find what's different between the sample and your program ;)
Title: Sprite won't draw correctly
Post by: DormoTheNord on May 30, 2010, 08:54:57 pm
I had the exact same problem on Xubuntu. I used resize(0.5f,0.5f); That made it more or less the right size.
I'll test it on Arch Linux tonight to see if its just an Ubuntu problem.
Title: Sprite won't draw correctly
Post by: DormoTheNord on May 31, 2010, 06:49:19 am
So, the graphics-sprite.cpp example works fine for me on Arch Linux, whereas on Xubuntu it gave me the same problem it is giving you. This leads me to believe the problem has to do with Ubuntu.

Are you using 32 bit or 64 bit Ubuntu? I was using 64 bit Xubuntu and am now using 64 bit Arch.