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

Author Topic: Mac os X Lion - RenderTexture show random pixels  (Read 7535 times)

0 Members and 1 Guest are viewing this topic.

pirate42

  • Newbie
  • *
  • Posts: 18
    • View Profile
Mac os X Lion - RenderTexture show random pixels
« Reply #15 on: January 15, 2012, 11:33:50 pm »
thanks for your time.

the problem is, I load all my images before the main loop, so I cannot draw the RT twice  :?

is there a temporary solution ?

pirate42

  • Newbie
  • *
  • Posts: 18
    • View Profile
Mac os X Lion - RenderTexture show random pixels
« Reply #16 on: January 16, 2012, 11:05:11 am »
hello,

tested again on another windows computer and it works

any idea ?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Mac os X Lion - RenderTexture show random pixels
« Reply #17 on: January 16, 2012, 11:18:29 am »
Since it's a Mac OS X only bug, I cannot help. We'd need someone with a Mac and OpenGL/debugging skills.
Laurent Gomila - SFML developer

Haikarainen

  • Guest
Mac os X Lion - RenderTexture show random pixels
« Reply #18 on: January 16, 2012, 11:20:06 am »
I noticed you clear your rendertexture using sf::Color::Transparent. Try clearing it with a solid color or without arguments

pirate42

  • Newbie
  • *
  • Posts: 18
    • View Profile
Mac os X Lion - RenderTexture show random pixels
« Reply #19 on: January 16, 2012, 11:24:08 am »
Quote from: "Haikarainen"
I noticed you clear your rendertexture using sf::Color::Transparent. Try clearing it with a solid color or without arguments


unfortunately, this is worse. I get no transparency, and I have more artifacts.

Quote
Since it's a Mac OS X only bug, I cannot help. We'd need someone with a Mac and OpenGL/debugging skills.


thx by the way

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Mac os X Lion - RenderTexture show random pixels
« Reply #20 on: January 16, 2012, 09:20:27 pm »
Quote from: "pirate42"
is there a temporary solution ?

I just tested some more things and it came out that the following code will work (except the window will "flash" when it is displayed the first time).

Code: [Select]
#include <SFML/Graphics.hpp>
#include "ResourcePath.hpp"

int main (int argc, const char * argv[])
{
    // Create the main window
    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
   
    // Load a sprite to display
    sf::Texture texture;
    if (!texture.LoadFromFile(ResourcePath() + "cute_image.jpg"))
    return EXIT_FAILURE;
    sf::Sprite spriteTmp(texture);
   
    sf::RenderTexture rt;
    if (!rt.Create(texture.GetWidth(), texture.GetHeight()))
        return EXIT_FAILURE;
   
    // Create RT with some content.
    window.Display(); // MAKES THINGS WORK!
    rt.Clear();
    rt.Draw(spriteTmp);
    rt.Display();
    sf::Sprite sprite(rt.GetTexture());
   
    // Start the game loop
    while (window.IsOpen())
    {
    // Process events
    sf::Event event;
    while (window.PollEvent(event))
    {
    // Close window : exit
    if (event.Type == sf::Event::Closed)
    window.Close();
           
    // Escape pressed : exit
    if (event.Type == sf::Event::KeyPressed && event.Key.Code == sf::Keyboard::Escape)
    window.Close();
    }
       
        // Draw the sprite
        window.Draw(sprite);
       
    // Update the window
    window.Display();
    }
   
return EXIT_SUCCESS;
}


Adding "window.Display();" before "rt.Clear();" makes it works. Still no idea why. Will spend some time on this issue ASAP (but exams first!).
SFML / OS X developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Mac os X Lion - RenderTexture show random pixels
« Reply #21 on: January 16, 2012, 10:15:52 pm »
Can you try to add calls to glFlush() after or before drawing to the render-texture?
Laurent Gomila - SFML developer

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Mac os X Lion - RenderTexture show random pixels
« Reply #22 on: January 16, 2012, 11:13:10 pm »
It doesn't help. I tried glFlush between each possible line but no luck. =/
SFML / OS X developer

pirate42

  • Newbie
  • *
  • Posts: 18
    • View Profile
Mac os X Lion - RenderTexture show random pixels
« Reply #23 on: January 17, 2012, 01:17:46 am »
Quote from: "Hiura"
Adding "window.Display();" before "rt.Clear();" makes it works. Still no idea why. Will spend some time on this issue ASAP (but exams first!).


Quote
Can you try to add calls to glFlush() after or before drawing to the render-texture?


first, both solution did not work in my program.
but then, I found a solution (for the moment, the bug did not appear again)

In my program (not in this sample code), I used "sf::RenderTexture*" instead of "sf::RenderTexture"

I changed it to "sf::RenderTexture"

Then, once render texture has been displayed, I create a new sf::texture(rt. GetTexture)

then I create a new sprite using the texture and with both solution, it works like a charm

but if I use a pointer for RenderTexture, it does not work and some artifacts appear

I guess that window.Display() calls glFlush() ?

I put the glFlush() before calling rt.Create()



so Hiura, your sample code should work with glflush if you create a new texture from rt, then create the sprite



by the way thanks a lot to both of you, I will post a message tomorrow after lots of test in order to tell you if problem is resolved or not


Bonne nuit et merci ;)



[/quote]

pirate42

  • Newbie
  • *
  • Posts: 18
    • View Profile
Mac os X Lion - RenderTexture show random pixels
« Reply #24 on: January 17, 2012, 01:46:47 am »
I forgot an important thing. It doesn't work with integrated graphic card

you have to use the other one (geforce GT 330m for me)

on mac by default, the system switches automatically between the 2 graphic cards

I used this software to select manually which one I want to use :

gfxCardStatus

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Mac os X Lion - RenderTexture show random pixels
« Reply #25 on: January 17, 2012, 08:45:32 am »
Quote from: "pirate42"
I put the glFlush() before calling rt.Create()
That's right! I forget to try this one and it indeed seems to work.

Recap :

Code: [Select]
#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>
#include "ResourcePath.hpp"

int main (int argc, const char * argv[])
{
    // Create the main window
    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
   
    // Load a sprite to display
    sf::Texture texture;
    if (!texture.LoadFromFile(ResourcePath() + "cute_image.jpg"))
    return EXIT_FAILURE;
    sf::Sprite spriteTmp(texture);

    glFlush(); // FIXIT
   
    sf::RenderTexture rt;
    if (!rt.Create(texture.GetWidth(), texture.GetHeight()))
        return EXIT_FAILURE;
   
    // Create RT with some content.
    rt.Clear();
    rt.Draw(spriteTmp);
    rt.Display();
    sf::Sprite sprite(rt.GetTexture());
   
    // Start the game loop
    while (window.IsOpen())
    {
    // Process events
    sf::Event event;
    while (window.PollEvent(event))
    {
    // Close window : exit
    if (event.Type == sf::Event::Closed)
    window.Close();
           
    // Escape pressed : exit
    if (event.Type == sf::Event::KeyPressed && event.Key.Code == sf::Keyboard::Escape)
    window.Close();
    }
       
        window.Clear();
       
        // Draw the sprite
        window.Draw(sprite);
       
    // Update the window
    window.Display();
    }
   
return EXIT_SUCCESS;
}


I don't know if it is completely related or not, but I also tried something a little different with Image conversion. It appears that in the following code the two glFlush are required in order to prevent the same artefact bug.

Code: [Select]
   // Create the main window
    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
   
    // Load a sprite to display
    sf::Texture texture;
    if (!texture.LoadFromFile(ResourcePath() + "cute_image.jpg"))
    return EXIT_FAILURE;
    sf::Sprite spriteTmp(texture);
 
    glFlush(); // FIXIT A
   
    sf::RenderTexture rt;
    if (!rt.Create(texture.GetWidth(), texture.GetHeight()))
        return EXIT_FAILURE;
   
    // Create RT with some content.
    rt.Clear();
    rt.Draw(spriteTmp);
    rt.Display();
   
    sf::Image i = rt.GetTexture().CopyToImage();
    sf::Texture t;
    t.LoadFromImage(i);
   
    glFlush(); // FIXIT B
   
    sf::Sprite sprite(t);
   
    // Start the game loop
    while (window.IsOpen())
:
:


Maybe it will help someone to understand this issue.

(I don't have any Intel graphics so I can't say anything about them.)
SFML / OS X developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Mac os X Lion - RenderTexture show random pixels
« Reply #26 on: January 17, 2012, 09:02:45 am »
Thanks for the investigations :)

Each render-target has its own separate OpenGL context, but they share resources, such as textures, with each other. Another interesting fact is that OpenGL commands are never executed immediately, they are queued and flushed later (which you can force by calling glFlush).

So I guess that when the render-texture's context tries to draw the loaded texture, it's not ready yet in this context because there are still pending commands in the window's context. But I don't know why it happens only on OS X... I guess that other drivers are more clever :lol:

I'll see if I can flush contexts internally, when switching contexts, and if it doesn't impact performances too much.
Laurent Gomila - SFML developer

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Mac os X Lion - RenderTexture show random pixels
« Reply #27 on: January 17, 2012, 10:59:31 am »
Quote from: "Laurent"
I'll see if I can flush contexts internally, when switching contexts, and if it doesn't impact performances too much.
If the performances are too reduced maybe we can do it only on Mac, or, to be more precise : only on Mac until this issue appears on other OSes.

BTW, I tried on Nvidia GPU. It might work on ATI GPU (maybe) but I can't test that.
SFML / OS X developer

pirate42

  • Newbie
  • *
  • Posts: 18
    • View Profile
Mac os X Lion - RenderTexture show random pixels
« Reply #28 on: January 17, 2012, 12:08:04 pm »
Quote from: "Hiura"
Quote from: "Laurent"
I'll see if I can flush contexts internally, when switching contexts, and if it doesn't impact performances too much.
If the performances are too reduced maybe we can do it only on Mac, or, to be more precise : only on Mac until this issue appears on other OSes.

BTW, I tried on Nvidia GPU. It might work on ATI GPU (maybe) but I can't test that.


someone in my group project has a mac with an ATI graphic card. I let you informed if it works.

Quote
But I don't know why it happens only on OS X... I guess that other drivers are more clever


yes, and the problem on mac is that you cannot choose your drivers ... so maybe in a future drivers update by apple, this issue will be solved

pirate42

  • Newbie
  • *
  • Posts: 18
    • View Profile
Mac os X Lion - RenderTexture show random pixels
« Reply #29 on: January 17, 2012, 09:03:38 pm »
It's also working with ATI GPU :)

Thanks a lot for your help and hope that our troubles will help you to make your Librarie even better ;)

 

anything