SFML community forums
Help => Graphics => Topic started by: matt2224 on May 28, 2010, 11:43:05 am
-
#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?
-
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 ?
-
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)
-
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 ;) )
-
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?
-
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.
-
It's version 1.5
-
Ok, using openGL command salterate the render with SFML.
Use PreserveOpenglState (http://www.sfml-dev.org/documentation/1.5/classsf_1_1RenderTarget.htm#b763d16f00166b516fead600d8824c71)
-
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.
-
Any ideas Laurent?
-
What graphics card do you have? Are your drivers up-to-date? Can you run other OpenGL applications?
-
Yes. The other tutorial with the 3D rotating cube worked fine.
-
What if you use another image (like one from the samples)?
-
Nope. :( I've already tried a multitude of images.
-
Do the SFML samples work?
-
Most of them don't but I think that's because of App.Clear() crashing them.
-
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 ?
-
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.
-
It works fine.
-
So now you just have to find what's different between the sample and your program ;)
-
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.
-
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.