SFML community forums

Help => Graphics => Topic started by: Richy19 on August 25, 2011, 07:23:49 pm

Title: Textures and RenderTextures broken
Post by: Richy19 on August 25, 2011, 07:23:49 pm
I tried using a renderTexture earlier but the program would just close straight away.
I am also using a Texture like this:

Code: [Select]
#include "TitleScreen.hpp"

TitleScreen::TitleScreen()
{

}

TitleScreen::TitleScreen(sf::RenderWindow &App)
{
    app = &App;
    titleImage.LoadFromFile("./data/Title.png");
    titleImage.Bind();
}

TitleScreen::~TitleScreen(){}

void TitleScreen::Update()
{

}

void TitleScreen::Draw()
{
    app->Draw(sf::Sprite(titleImage ));
}


but I just et this image
(http://i.imgur.com/nQmV5.png)
Title: Textures and RenderTextures broken
Post by: Laurent on August 25, 2011, 07:26:49 pm
Where is the RenderTexture? Why do you Bind() the texture after loading it?

Can you show a complete and minimal example that reproduces your problem please?
Title: Textures and RenderTextures broken
Post by: Richy19 on August 25, 2011, 07:45:59 pm
This is my current code, I currently am not using a render Texture as I thought I coud get rid of it by just using different Views

http://pastebin.com/Mk3jjdiV

A simple example of how I use the texture would be:
Code: [Select]


int main( int argc, const char* argv[] )
{
   sf::RenderWindow App;
   sf::Texture titleImage;
titleImage.LoadFromFile("./data/Title.png");

sf::ContextSettings Settings;
Settings.DepthBits         = 24; // Request a 24 bits depth buffer
Settings.StencilBits       = 8;  // Request a 8 bits stencil buffer
Settings.AntialiasingLevel = GlobalSettings::globalSettings.AntiAliasing;  // Request 2 levels of antialiasing
Settings.MajorVersion = 2;
Settings.MinorVersion = 1;



if(GlobalSettings::globalSettings.FullScreen)
App.Create(sf::VideoMode(800, 600, sf::VideoMode::GetDesktopMode().BitsPerPixel), GlobalSettings::globalSettings.getWindowName(), sf::Style::Fullscreen ,Settings);
else
App.Create(sf::VideoMode(800, 600, sf::VideoMode::GetDesktopMode().BitsPerPixel), GlobalSettings::globalSettings.getWindowName(), sf::Style::Default ,Settings);


App.EnableVerticalSync(false);



try{
std::cout << "Using OpenGL " << App.GetSettings().MajorVersion << "." << App.GetSettings().MinorVersion << std::endl;

if ((App.GetSettings().MajorVersion < Settings.MajorVersion) || (App.GetSettings().MajorVersion == Settings.MajorVersion && App.GetSettings().MinorVersion < Settings.MinorVersion))
{
std::cout << "Sorry but a minimum of OpenGL "<< Settings.MajorVersion <<"."<< Settings.MinorVersion <<" is required"<<std::endl;
std::cout << "Try updating your drivers." << std::endl;
return false;
}

}
catch(int e){
std::cout << "Failed to get OpenGL version. " << e << std::endl;

return false;
}

GLenum err = glewInit();
if (GLEW_OK != err)
{
/* Problem: glewInit failed, something is seriously wrong. */
std::cout << "Error: " << glewGetErrorString(err) << std::endl;
return false;
}
else
{
std::cout << "Using GLEW " << glewGetString(GLEW_VERSION) << std::endl;
}



   App.SetFramerateLimit(60 );
App.ShowMouseCursor(false);


while (App.IsOpened())
{
// Process events
sf::Event Event;
while (App.PollEvent(Event))
{
   // Close window
                if (Event.Type == sf::Event::Closed)
                    App.Close();

                // Escape key pressed
                if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Keyboard::Escape))
                    App.Close();

                if (Event.Type == sf::Event::Resized)
                    glViewport(0, 0, Event.Size.Width, Event.Size.Height);
            }



            App.SetActive();
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
                    // Dark blue background
                    glClearColor(0.392156863f, 0.584313725f, 0.929411765f, 0.0f);


            switch(gameStage)
            {
                case intro:
                {
                    App.SaveGLStates();
                    App.RestoreGLStates();
                    break;
                }
                case menu:
                {
                    App.SaveGLStates();
                   App.Draw(sf::Sprite(titleImage ));
                    App.RestoreGLStates();
                    break;
                }
                case game:
                {


                    break;
                }
                case options:
                {
                    break;
                }
                case quit:
                {
                    break;
                }
            }




#ifdef  THIS_DEBUG
    App.SaveGLStates();
    std::stringstream ss;
ss << App.GetFrameTime();
sf::Text string(ss.str() + " ms",sf::Font::GetDefaultFont(), 14);
string.SetPosition(5,5);
App.Draw(string);
    App.RestoreGLStates();
#endif


            // Display window contents on screen
App.Display();
}
}



    return 0;
}

Title: Textures and RenderTextures broken
Post by: Laurent on August 25, 2011, 09:27:31 pm
Ok thanks. So this code displays the artifact shown in your first message?
Title: Textures and RenderTextures broken
Post by: Richy19 on August 25, 2011, 09:58:23 pm
Well I made that up as I went so might not be exactly it but more or less


Here is code I have tried out: http://pastebin.com/B81PJ4uG
And gives me the broken image, it also just blocks the window input so I cant close it and need to stop it via the IDE

It seems to not be happening all the time with that code, however when it doesnt happen the image still doesnt display
Title: Textures and RenderTextures broken
Post by: Laurent on August 25, 2011, 10:20:28 pm
Works for me (I just disabled GLEW).
Title: Textures and RenderTextures broken
Post by: Richy19 on August 25, 2011, 10:24:35 pm
tried disabeling Glew but still did the same, guess it could be the drivers or something.
Do you know if there is anyway I can check?
Title: Textures and RenderTextures broken
Post by: Laurent on August 25, 2011, 10:50:52 pm
The only way would be to run an OpenGL application that doesn't use SFML.

And also make sure that your graphics drivers are up-to-date. What's your graphics card and OS?
Title: Textures and RenderTextures broken
Post by: Richy19 on August 25, 2011, 10:53:43 pm
Im on fedora 15, and the graphics card is an intel GMA 4500
It works fine on windows which just makes me think its that linux is using outdated drivers
Title: Textures and RenderTextures broken
Post by: Groogy on August 25, 2011, 10:59:39 pm
I've made it my holy cause to fight Intel integrated graphic cards whenever I find em...

Don't trust em', nugh' said! Their development tools(Vtune and like) is the best... but please Intel, STAY WITH CPU!
Title: Textures and RenderTextures broken
Post by: Richy19 on August 25, 2011, 11:48:42 pm
Just tried the linux version of Osmos and it worked fine :/
Title: Textures and RenderTextures broken
Post by: Laurent on August 25, 2011, 11:52:12 pm
Is it still wrong without OpenGL? In other words, can you try to make the above code as minimal as possible?
Title: Textures and RenderTextures broken
Post by: Richy19 on August 26, 2011, 12:05:19 am
Its till broken, however with out the openGL stuff I can now close the window.
Title: Textures and RenderTextures broken
Post by: Laurent on August 26, 2011, 12:14:09 am
So can you please show me the simplest code possible that still produces the problem...?
Title: Textures and RenderTextures broken
Post by: Richy19 on August 26, 2011, 12:26:47 am
Code: [Select]

#include <SFML/Graphics.hpp>


int main( int argc, const char* argv[] )
 {
    sf::RenderWindow App;
    sf::Texture titleImage;
 titleImage.LoadFromFile("./data/Title.png");

    App.Create(sf::VideoMode(800, 600, 32), "Test");




 while (App.IsOpened())
       {
          // Process events
          sf::Event Event;
          while (App.PollEvent(Event))
          {
              // Close window
                 if (Event.Type == sf::Event::Closed)
                     App.Close();

                 // Escape key pressed
                 if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Keyboard::Escape))
                     App.Close();

             }


             App.Clear();

                    App.Draw(sf::Sprite(titleImage ));




             // Display window contents on screen
          App.Display();
       }




     return 0;
 }


Linking with
Code: [Select]

-lsfml-graphics
-lsfml-window
-lsfml-system
Title: Textures and RenderTextures broken
Post by: Richy19 on August 26, 2011, 01:15:39 am
Update on this, I just downloaded SFML 1.6 from the downloads page and it works fine.
So unless there is any major changes between how 1.6 manages images and how 2.0 does it then it must be something to do with my build

Just tried rebuilding SFML 2 and same problem
Title: Textures and RenderTextures broken
Post by: Laurent on August 26, 2011, 09:01:27 am
What happens if you load the texture after creating the window?

PS: please fix your indentation :shock:
Title: Textures and RenderTextures broken
Post by: Richy19 on August 26, 2011, 02:29:22 pm
Recompiled SFML (I was messing with it last night) and the test minimal project works now :D

But for some reason the openGL one doesnt
:/
Title: Textures and RenderTextures broken
Post by: Richy19 on August 26, 2011, 06:48:38 pm
Well the program doesnt crash now, and it works ok except that it doesnt show the image.
Just to check is this the correct way of using it?


in main
Code: [Select]

//main loop
case menu:
            {
                titleScreen.Update();

                App.SaveGLStates();
                titleScreen.Draw(App);
                App.RestoreGLStates();
                break;
            }


title screen header

Code: [Select]

#ifndef TITLESCREEN_HPP_INCLUDED
#define TITLESCREEN_HPP_INCLUDED

#include <SFML/Graphics.hpp>

class TitleScreen
{
    sf::Texture titleImage;
public:
    TitleScreen();
    ~TitleScreen();
    void Draw(sf::RenderWindow &App);
    void Update();
};

#endif // TITLESCREEN_HPP_INCLUDED



titlescreen code

Code: [Select]

#include "TitleScreen.hpp"

TitleScreen::TitleScreen()
{

    titleImage.LoadFromFile("./data/Title.png");

}

TitleScreen::~TitleScreen() {}

void TitleScreen::Update()
{

}

void TitleScreen::Draw(sf::RenderWindow &App)
{
    App.Draw(sf::Sprite( titleImage ) );

}


Title: Textures and RenderTextures broken
Post by: Laurent on August 26, 2011, 06:49:55 pm
Yes, should be ok.
Title: Textures and RenderTextures broken
Post by: Richy19 on August 26, 2011, 07:52:29 pm
Im going to stickk with SFML 1.6 for the moment, 2.0 must not like my system too much :P

Is there any way to specify what version of openGL you want with SFML 1.6?
Title: Textures and RenderTextures broken
Post by: Laurent on August 26, 2011, 08:28:09 pm
Nop.
Title: Textures and RenderTextures broken
Post by: Richy19 on August 31, 2011, 08:24:26 pm
Just tried using valgrind thought this might give some more details about the porblem

Code: [Select]
==6759== Conditional jump or move depends on uninitialised value(s)
==6759==    at 0x4049DFA: sf::Renderer::SetShader(sf::Shader const*) (in /usr/local/lib/libsfml-graphics.so.2.0)
==6759==    by 0x4395FFFF: ???
==6759==
==6759== Conditional jump or move depends on uninitialised value(s)
==6759==    at 0x4049C28: sf::Renderer::SetBlendMode(sf::Blend::Mode) (in /usr/local/lib/libsfml-graphics.so.2.0)
==6759==    by 0x4395FFFF: ???
==6759==
==6759== Conditional jump or move depends on uninitialised value(s)
==6759==    at 0x4049D48: sf::Renderer::SetTexture(sf::Texture const*) (in /usr/local/lib/libsfml-graphics.so.2.0)
==6759==    by 0x404F191: sf::Sprite::Render(sf::RenderTarget&, sf::Renderer&) const (in /usr/local/lib/libsfml-graphics.so.2.0)
==6759==    by 0x4033F57: sf::Drawable::Draw(sf::RenderTarget&, sf::Renderer&) const (in /usr/local/lib/libsfml-graphics.so.2.0)
==6759==    by 0x4395FFFF: ???


Seems this is the problem, just tried something and it crashed with any drawable not just textures/sprites