SFML community forums

General => General discussions => Topic started by: Limaaron on October 01, 2020, 04:16:08 am

Title: SFML Render error
Post by: Limaaron on October 01, 2020, 04:16:08 am

I started learning SFML in 2018 and when i learn sfml, i noticed this.
if you declare sf::RenderWindow in the library and try to pass a pointer sf::Drawable or reference you get this error.


regardless of static or dynamic linking.


debug log
Code: [Select]
An internal OpenGL call failed in RenderTarget.cpp(301).
Expression:
 glVertexPointer(2, GL_FLOAT, sizeof(Vertex), data + 0)
Error description:
 GL_INVALID_OPERATION
 The specified operation is not allowed in the current state.


An internal OpenGL call failed in RenderTarget.cpp(302).
Expression:
 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), data +
Error description:
 GL_INVALID_OPERATION
 The specified operation is not allowed in the current state.


An internal OpenGL call failed in RenderTarget.cpp(711).
Expression:
 glDrawArrays(mode, static_cast<GLint>(firstVertex), static_cast<GLsizei>(vertexCount))
Error description:
 GL_INVALID_OPERATION
 The specified operation is not allowed in the current state.


An internal OpenGL call failed in Texture.cpp(782).
Expression:
 glBindTexture(GL_TEXTURE_2D, 0)
Error description:
 GL_INVALID_OPERATION
 The specified operation is not allowed in the current state.


An internal OpenGL call failed in Texture.cpp(785).
Expression:
 glMatrixMode(GL_TEXTURE)
Error description:
 GL_INVALID_OPERATION
 The specified operation is not allowed in the current state.


An internal OpenGL call failed in Texture.cpp(786).
Expression:
 glLoadIdentity()
Error description:
 GL_INVALID_OPERATION
 The specified operation is not allowed in the current state.


An internal OpenGL call failed in Texture.cpp(789).
Expression:
 glMatrixMode(GL_MODELVIEW)
Error description:
 GL_INVALID_OPERATION
 The specified operation is not allowed in the current state.


An internal OpenGL call failed in RenderTarget.cpp(152).
Expression:
 glClearColor(color.r / 255.f, color.g / 255.f, color.b / 255.f, color.a / 255.f)
Error description:
 GL_INVALID_OPERATION
 The specified operation is not allowed in the current state.


An internal OpenGL call failed in RenderTarget.cpp(153).
Expression:
 glClear(GL_COLOR_BUFFER_BIT)
Error description:
 GL_INVALID_OPERATION
 The specified operation is not allowed in the current state.


An internal OpenGL call failed in RenderTextureImplFBO.cpp(208).
Expression:
 GLEXT_glBindFramebuffer(GLEXT_GL_FRAMEBUFFER, 0)
Error description:
 GL_INVALID_OPERATION
 The specified operation is not allowed in the current state.


testSF.dll

class TestSF
{
    sf::RenderWindow window
public:
    TestSF();


    sf::RenderWindow* getWindow();
    void draw(sf::Drawable *drawable);
}


TestSF()
    : window(sf::VideoMode(600,400), "Test")
{


}


sf::RenderWindow* TestSF::getWindow()
{
    return &window;
}


void TestSF::draw(sf::Drawable *drawable)
{
    sf::Event event;
    while (window.pollEvent(event))
    {
         if (event.type == sf::Event::Closed)
             window.close();
    }
    window.clear();
    window.draw(*drawable);
    window.display();
}
 

test.exe
#include <SFML/Graphics.hpp>
#include <testsf.hpp>

int main(void)
{
    TestSF test; // ok
    sf::RenderWindow *window = test.getWindow(); // ok
   
    sf::CircleShape shape(100.f); // ok
    shape.setFillColor(sf::Color::Green); //ok
   
    while (window->isOpen()) // ok
    {
        test.draw(shape); // error here
    }
}
 

but if i add sf::Context in main function the error disappears.

test.exe
#include <SFML/Graphics.hpp>
#include <testsf.hpp>

int main(void)
{
    sf::ContextSettings settings;
    sf::Context ctx(settings, 600, 400);
    TestSF test; // ok
    sf::RenderWindow *window = test.getWindow(); // ok
   
    sf::CircleShape shape(100.f); // ok
    shape.setFillColor(sf::Color::Green); //ok
   
    while (window->isOpen()) // ok
    {
        test.draw(shape); // ok
    }
}
 
Title: Re: SFML Render error
Post by: eXpl0it3r on October 01, 2020, 10:07:56 am
What version of SFML are you using?
Title: Re: SFML Render error
Post by: Limaaron on October 01, 2020, 02:08:19 pm
I'm using latest version SFML 2.5.1.

Title: Re: SFML Render error
Post by: eXpl0it3r on October 01, 2020, 03:47:10 pm
The example code you've given contains some errors, as such I wonder whether you've actually given the code that you tested, or whether you've cut out some things.

After fixing your code, it works fine without additional context defined.

Mistakes I found:

The last one could be the issue you're running into, but should also be highlighted in your compiler at least as warning.

test.draw(&shape); vs test.draw(shape);

When you provide code, always make sure you've actually used the same code to verify the issue first. ;)
Title: Re: SFML Render error
Post by: Limaaron on October 01, 2020, 04:55:16 pm
Sorry, i wrote this code at night and but I tested it in 2018.
I make video with this problem https://www.youtube.com/watch?v=dc_QY5km1CM
I haven't touched this code since 2018 and this problem still exists. ;)
Title: Re: SFML Render error
Post by: eXpl0it3r on October 01, 2020, 07:43:28 pm
Aand you accidentally forgot to mention that you're integrating Qt in your application and create QApplication instance... ;D

Also your actual application uses references instead of pointers, which is a better design ;)

The Qt class might be creating its own OpenGL context which then interferes with SFML's OpenGL context.
Try calling window.setActive(true).
Title: Re: SFML Render error
Post by: Limaaron on October 01, 2020, 08:33:36 pm
i know that qt can create OpenGL context, but i try in other project without qt and i also tried using window.setActive(true); result the same :-\
Title: Re: SFML Render error
Post by: eXpl0it3r on October 01, 2020, 08:37:59 pm
Try the master branch of SFML. If you don't want to build from source you can also find pre-built binaries here: https://artifacts.sfml-dev.org/by-branch/master/
Title: Re: SFML Render error
Post by: perkele on December 29, 2021, 09:19:33 am
I get the same issue if I try to create the window or context with
sf::ContextSettings::Core
. I'm guessing you're not meant to use SFML rendering with a core GL context? Or is this a bug?
Title: Re: SFML Render error
Post by: eXpl0it3r on December 29, 2021, 01:28:13 pm
You can't use a core context with the SFML graphics module, but you need a compatibility context, as the graphics module uses OpenGL 2.1 or so