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

Author Topic: [SOLVED] What's going on here? getting graphics distortions using RenderTexture  (Read 5314 times)

0 Members and 1 Guest are viewing this topic.

SoleSoul

  • Newbie
  • *
  • Posts: 26
    • View Profile
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:

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:
  • The M_03.png is a 10x10px png.
  • There is no console output at all.

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):
« Last Edit: December 04, 2012, 05:19:37 pm by SoleSoul »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: What's going on here? getting graphics distortions using RenderTexture
« Reply #1 on: December 04, 2012, 03:27:31 pm »
Your code looks perfect, I can't see anything wrong.

Have you tried other graphics drivers?
Laurent Gomila - SFML developer

SoleSoul

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: What's going on here? getting graphics distortions using RenderTexture
« Reply #2 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.

SoleSoul

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: What's going on here? getting graphics distortions using RenderTexture
« Reply #3 on: December 04, 2012, 03:43:01 pm »
With the nvidia blob it works.
Is there anything we can do?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: What's going on here? getting graphics distortions using RenderTexture
« Reply #4 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.
Laurent Gomila - SFML developer

SoleSoul

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: What's going on here? getting graphics distortions using RenderTexture
« Reply #5 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!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: What's going on here? getting graphics distortions using RenderTexture
« Reply #6 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.
Laurent Gomila - SFML developer

SoleSoul

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: What's going on here? getting graphics distortions using RenderTexture
« Reply #7 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?

SoleSoul

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: What's going on here? getting graphics distortions using RenderTexture
« Reply #8 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: What's going on here? getting graphics distortions using RenderTexture
« Reply #9 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?
Laurent Gomila - SFML developer

SoleSoul

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: What's going on here? getting graphics distortions using RenderTexture
« Reply #10 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)

SoleSoul

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: What's going on here? getting graphics distortions using RenderTexture
« Reply #11 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?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: Re: What's going on here? getting graphics distortions using RenderTexture
« Reply #12 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. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

SoleSoul

  • Newbie
  • *
  • Posts: 26
    • View Profile
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.