SFML community forums

Help => Graphics => Topic started by: SoleSoul on December 04, 2012, 03:21:20 pm

Title: [SOLVED] What's going on here? getting graphics distortions using RenderTexture
Post by: SoleSoul on December 04, 2012, 03:21:20 pm
Here is the whole code:
#include <SFML/Graphics.hpp>
#include <iostream>
using namespace std;

int main()
{
        // Create the main window
        sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");

        sf::Texture t_grass;
        if(!t_grass.loadFromFile("M_03.png"))
                cout<<"ERROR: can't load file"<<endl;
        sf::Sprite s_grass(t_grass);
        s_grass.setPosition(0,0);
       
        // Prepare the ground
        sf::RenderTexture rt_ground;
        if(!rt_ground.create(500, 500))
                cout<<"ERROR: can't create render texture"<<endl;

        rt_ground.clear(sf::Color::White);
        rt_ground.draw(s_grass);
        rt_ground.display();
       
        sf::Sprite s_ground(rt_ground.getTexture());
       
        sf::Event event;

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

                // Clear screen
                window.clear();
               
                window.draw(s_ground);
               
                // Update the window
                window.display();
        }

        return EXIT_SUCCESS;
}
 
And here is the result:
(http://i48.tinypic.com/nvpkpk.png)
As you can see, it is very weird. It renders the source code upside down and distorted but it's the source code. It's not always the source code, I simply got lucky once and the dirstortions were easy to compare to the stuff on the screen.
I am probably doing something very wrong. What is it?

notes:

Setup:
Archlinux
NVIDIA GeForce 7600GS
Nouveau open source driver

Thanks

EDIT: Just for completeness sake, this is how it should have looked like (it works using the nvidia blob):
(http://i45.tinypic.com/14uwdy.png)
Title: Re: What's going on here? getting graphics distortions using RenderTexture
Post by: Laurent on December 04, 2012, 03:27:31 pm
Your code looks perfect, I can't see anything wrong.

Have you tried other graphics drivers?
Title: Re: What's going on here? getting graphics distortions using RenderTexture
Post by: SoleSoul on December 04, 2012, 03:32:18 pm
I LOVE the speed of response :)
I'll try installing the nvidia binary blob and see what happens.
Title: Re: What's going on here? getting graphics distortions using RenderTexture
Post by: SoleSoul on December 04, 2012, 03:43:01 pm
With the nvidia blob it works.
Is there anything we can do?
Title: Re: What's going on here? getting graphics distortions using RenderTexture
Post by: Laurent on December 04, 2012, 03:49:03 pm
Quote
Is there anything we can do?
Two things:
- either fix the nouveau driver
- or test other OpenGL programs that use FBOs, and if they work, find what makes the driver unhappy in SFML code

Unfortunately I can't work on this kind of driver problems, so you're on your own.
Title: Re: What's going on here? getting graphics distortions using RenderTexture
Post by: SoleSoul on December 04, 2012, 03:51:29 pm
Yeah, I wasn't expecting you to fix the driver :) I only wanted to know what to ask the nouveau guys. I guess I'll show them the source code and the results and see what they say.

Thank you!
Title: Re: What's going on here? getting graphics distortions using RenderTexture
Post by: Laurent on December 04, 2012, 04:06:25 pm
You should first try to reproduce the problem with an OpenGL-only program, the nouveau guys won't look inside SFML code.

This one should be a good starting point, it might even reproduce your problem with no modification:
http://en.sfml-dev.org/forums/index.php?topic=9149.msg61891#msg61891

But first, try the latest SFML sources if was not already the case.
Title: Re: What's going on here? getting graphics distortions using RenderTexture
Post by: SoleSoul on December 04, 2012, 04:54:05 pm
I compiled the program from the link and ran it under both drivers. No error message was printed in both cases.
It finished immediately, and as I can see it is intentional because the application contains only tests.

What can  we learn from that? Maybe an OpenGL function is not implemented correctly in nouveau even if it doesn't return an error code?

Did I use the program from the link incorrectly?
Title: Re: What's going on here? getting graphics distortions using RenderTexture
Post by: SoleSoul on December 04, 2012, 04:55:55 pm
I guess I'll have to actually draw stuff to see if the bug is presend also in OpenGL only applicaton.
Title: Re: What's going on here? getting graphics distortions using RenderTexture
Post by: Laurent on December 04, 2012, 04:58:15 pm
Quote
I guess I'll have to actually draw stuff to see if the bug is presend also in OpenGL only applicaton.
Yes, sorry. So it's a little more complicated. Or maybe you can use an OpenGL debugger to watch the texture contents without touching the test code.

But anyway, are you using the latest SFML sources?
Title: Re: What's going on here? getting graphics distortions using RenderTexture
Post by: SoleSoul on December 04, 2012, 05:07:41 pm
Sorry for not mentioning earlier, I'm using the official SFML package from Archlinux. Its version is "sfml 2.0rc1-3". Should I try manually updating it further?
(in the meantime I'm compiling from git)

And if I would have to draw using OpenGL sadly I won't be able to do it in the near future. I never used OpenGL directly before and I don't have the time to learn it and try until I find the bug. I think I'll leave it for now.

That's actually a problem for me. The nvidia blob causes other problems on my hardware so for day to day use I must use nouveau.
I thought to use RenderTexture to construct a background image from many small images and for now I can't use it. Is there a good alternative? (I'm not that experienced with SFML either)
Title: Re: What's going on here? getting graphics distortions using RenderTexture
Post by: SoleSoul on December 04, 2012, 05:16:54 pm
Wait a minute, a miracle!    ;D
I updated to the latest git and it seem to work perfectly with nouveau.
I'll test some more and see if it is really ok.

Just for curiousity, do you have in mind which change fixed it?
Title: AW: Re: What's going on here? getting graphics distortions using RenderTexture
Post by: eXpl0it3r on December 04, 2012, 06:12:43 pm
Just for curiousity, do you have in mind which change fixed it?
Well there were changes for the Intel GPUs, so the RT would work with them, maybe that fixed it too. ;)
Title: Re: [SOLVED] What's going on here? getting graphics distortions using RenderTexture
Post by: SoleSoul on December 04, 2012, 06:22:49 pm
I *think* that this makes much sense because a large portion of the video stack of Linux is shared between the open source drivers. Since both intel and nouveau are open source drivers it is likely that they are affected by the same changes.