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

Author Topic: Sprite won't draw correctly  (Read 6532 times)

0 Members and 2 Guests are viewing this topic.

matt2224

  • Newbie
  • *
  • Posts: 9
    • View Profile
Sprite won't draw correctly
« 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:


Output:


Why won't it work?

Mindiell

  • Hero Member
  • *****
  • Posts: 1261
    • ICQ Messenger - 41484135
    • View Profile
Sprite won't draw correctly
« Reply #1 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 ?
Mindiell
----

matt2224

  • Newbie
  • *
  • Posts: 9
    • View Profile
Sprite won't draw correctly
« Reply #2 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:


Mindiell

  • Hero Member
  • *****
  • Posts: 1261
    • ICQ Messenger - 41484135
    • View Profile
Sprite won't draw correctly
« Reply #3 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 ;) )
Mindiell
----

matt2224

  • Newbie
  • *
  • Posts: 9
    • View Profile
Sprite won't draw correctly
« Reply #4 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?

Mindiell

  • Hero Member
  • *****
  • Posts: 1261
    • ICQ Messenger - 41484135
    • View Profile
Sprite won't draw correctly
« Reply #5 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.
Mindiell
----

matt2224

  • Newbie
  • *
  • Posts: 9
    • View Profile
Sprite won't draw correctly
« Reply #6 on: May 28, 2010, 04:57:45 pm »
It's version 1.5

Mindiell

  • Hero Member
  • *****
  • Posts: 1261
    • ICQ Messenger - 41484135
    • View Profile
Sprite won't draw correctly
« Reply #7 on: May 28, 2010, 06:37:28 pm »
Ok, using openGL command salterate the render with SFML.
Use PreserveOpenglState
Mindiell
----

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Sprite won't draw correctly
« Reply #8 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.
Laurent Gomila - SFML developer

matt2224

  • Newbie
  • *
  • Posts: 9
    • View Profile
Sprite won't draw correctly
« Reply #9 on: May 28, 2010, 07:16:59 pm »
Any ideas Laurent?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Sprite won't draw correctly
« Reply #10 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?
Laurent Gomila - SFML developer

matt2224

  • Newbie
  • *
  • Posts: 9
    • View Profile
Sprite won't draw correctly
« Reply #11 on: May 28, 2010, 08:44:50 pm »
Yes. The other tutorial with the 3D rotating cube worked fine.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Sprite won't draw correctly
« Reply #12 on: May 28, 2010, 08:48:26 pm »
What if you use another image (like one from the samples)?
Laurent Gomila - SFML developer

matt2224

  • Newbie
  • *
  • Posts: 9
    • View Profile
Sprite won't draw correctly
« Reply #13 on: May 28, 2010, 08:53:23 pm »
Nope. :( I've already tried a multitude of images.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Sprite won't draw correctly
« Reply #14 on: May 28, 2010, 09:06:32 pm »
Do the SFML samples work?
Laurent Gomila - SFML developer

 

anything