An Internal OpenGL call failed in Textures.cpp (the SFML one) (524) : GL_INVALID OPERATION, the specified operation is not allowed in the current state.
In SFML Source Code, line 524 (is this the line number in the error ?) it's about a function testing whether texture is repeated or not. It doesn't matter if I make the texture repeatable or not.
My main code :
///creating window and stuff like that
///.....
Model cube("Shaders/texture.vert", "Shaders/texture.frag", "cube.obj");
sf::Texture texture;
texture.loadFromFile("grass.jpg");
texture.setRepeated(true);
///... loading other things
///Main loop
///Rendering part of the loop :
while(running)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
cube.display(projection, modelview, &texture);
window.display();
}
cube displaying method :
void Model::display(glm::mat4 const &projection, glm::mat4 const &modelview, sf::Texture *text)
{
glUseProgram(m_shader.getProgramID());
glBindVertexArray(m_VAO);
glUniformMatrix4fv(glGetUniformLocation(m_shader.getProgramID(), "projection"), 1, GL_FALSE, value_ptr(projection));
glUniformMatrix4fv(glGetUniformLocation(m_shader.getProgramID(), "modelview"), 1, GL_FALSE, value_ptr(modelview));
sf::Texture::bind(text);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glDrawArrays(GL_TRIANGLES, 0, 36);
sf::Texture::bind(NULL);
glBindVertexArray(0);
glUseProgram(0);
}
It does run perfectly (even repeating textures work if I enable them)... But I get an error in console, and I have no idea why...
If I bind the texture in main function (before calling display() and relasing just after), it yeld exactly the same result as expected, but my error is in line 560 instead of 524 (in source code, 560 is the end of the bind function though)
If you want to check sourcecode of texture .cpp of GitHub :
////////////////////////////////////////////////////////////
bool Texture::isRepeated() const
{
return m_isRepeated;
} ////////////////////////////////////////////////////THIS IS LINE 524
////////////////////////////////////////////////////////////
void Texture::bind(const Texture* texture, CoordinateType coordinateType)
{
ensureGlContext();
if (texture && texture->m_texture)
{
// Bind the texture
glCheck(glBindTexture(GL_TEXTURE_2D, texture->m_texture));
// Check if we need to define a special texture matrix
if ((coordinateType == Pixels) || texture->m_pixelsFlipped)
{
GLfloat matrix[16] = {1.f, 0.f, 0.f, 0.f,
0.f, 1.f, 0.f, 0.f,
0.f, 0.f, 1.f, 0.f,
0.f, 0.f, 0.f, 1.f};
// If non-normalized coordinates (= pixels) are requested, we need to
// setup scale factors that convert the range [0 .. size] to [0 .. 1]
if (coordinateType == Pixels)
{
matrix[0] = 1.f / texture->m_actualSize.x;
matrix[5] = 1.f / texture->m_actualSize.y;
}
// If pixels are flipped we must invert the Y axis
if (texture->m_pixelsFlipped)
{
matrix[5] = -matrix[5];
matrix[13] = static_cast<float>(texture->m_size.y) / texture->m_actualSize.y;
}
// Load the matrix /////////////////////////////////////LINE 560 !
glCheck(glMatrixMode(GL_TEXTURE));
glCheck(glLoadMatrixf(matrix));
// Go back to model-view mode (sf::RenderTarget relies on it)
glCheck(glMatrixMode(GL_MODELVIEW));
}
}
else
{
// Bind no texture
glCheck(glBindTexture(GL_TEXTURE_2D, 0));
// Reset the texture matrix
glCheck(glMatrixMode(GL_TEXTURE));
glCheck(glLoadIdentity());
// Go back to model-view mode (sf::RenderTarget relies on it)
glCheck(glMatrixMode(GL_MODELVIEW));
}
}
Maybe a comaptibility between modern and old OpenGL ? Maybe I should use sf::Image to load textures and create my own OpenGL Texture instead of binding with sf::Texture ? (Is this deprecated ? Have I done something wrong ?)
The strangest thing is that my program runs perfectly with this though.