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

Author Topic: SFML Render error  (Read 9387 times)

0 Members and 1 Guest are viewing this topic.

Limaaron

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
SFML Render error
« 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
    }
}
 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: SFML Render error
« Reply #1 on: October 01, 2020, 10:07:56 am »
What version of SFML are you using?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Limaaron

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: SFML Render error
« Reply #2 on: October 01, 2020, 02:08:19 pm »
I'm using latest version SFML 2.5.1.


eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: SFML Render error
« Reply #3 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:
  • Missing semicolon after the window member variable definition
  • Missing semicolon at the end of the class definition
  • Missing class "namespace" prefix TestSF for the constructor
  • Not dereferencing the shape instance when passing it to the draw function

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. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Limaaron

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: SFML Render error
« Reply #4 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
I haven't touched this code since 2018 and this problem still exists. ;)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: SFML Render error
« Reply #5 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).
« Last Edit: August 04, 2023, 08:27:09 am by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Limaaron

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: SFML Render error
« Reply #6 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 :-\

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: SFML Render error
« Reply #7 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/
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

perkele

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: SFML Render error
« Reply #8 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?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: SFML Render error
« Reply #9 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
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/