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 logAn 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
}
}