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

Author Topic: [OpenGL 4] Internal error with sf::texture  (Read 4267 times)

0 Members and 1 Guest are viewing this topic.

bisthebis

  • Newbie
  • *
  • Posts: 19
    • View Profile
[OpenGL 4] Internal error with sf::texture
« on: December 14, 2015, 05:51:31 pm »
Quote
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 :
(click to show/hide)


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.

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: [OpenGL 4] Internal error with sf::texture
« Reply #1 on: December 14, 2015, 07:15:10 pm »
You should really look in the source that actually corresponds to the version of the library you are using. I went ahead and checked which version it could be, and it looks like you have to be using 2.3.1 since there is no other version with a glCheck on line 524.

In 2.3.1, line 524 is as follows:
glCheck(glBindTexture(GL_TEXTURE_2D, texture->m_texture));
The reason why it looks like the check is failing on this call is because of the way OpenGL reports errors. It only reports the first error that has occurred since the last time glGetError() was called. This means that if any prior OpenGL function calls, whether in SFML or your own code (you don't seem to check for errors yourself), fail with an error, it will only be picked up by the next glCheck. Since I also know that SFML wraps all of it's OpenGL calls in glCheck, they would be immediately detected. This means that this error can only be a result of one of your own calls. Check your own OpenGL calls for errors and we can work from there.

On a side note, if you are using an OpenGL 3.2+ context and have the core profile bit set, you will not be able to use any sfml-graphics objects (Texture, Shader, etc.) in your code. They rely on legacy functions which have been removed in the core profile.

Food for thought: Maybe SFML's glCheck should clear out the OpenGL error flag (with a second glGetError()) prior to executing the call as well. This prevents any misleading reports from happening. Whether the user checks their own code for errors should be left up to them.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

bisthebis

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: [OpenGL 4] Internal error with sf::texture
« Reply #2 on: December 14, 2015, 07:41:33 pm »
Maybe I should indeed test more my code... When everything works fine I tend to forget security  ;D
Is there an other way to check these errors withou pasting sfml code ?
I've found (by spammin sf::Texture::bind(NULL) wherever there could be an error in the previous line), and I found out that the problem came by using glBindVertexArray... But I don't get what error it could be, because there's no problem in the VAO creation tested by sf::Texture::bind(NULL) spamming) neither just after...
Only the first time I bind it to use it do I get an error.
Any tips ? (I'm gonna look for VAO related things)
Quote
On a side note, if you are using an OpenGL 3.2+ context and have the core profile bit set, you will not be able to use any sfml-graphics objects (Texture, Shader, etc.) in your code. They rely on legacy functions which have been removed in the core profile.

So you'd suggest me to create my own texture wrapper instead of using sf::Texture::bind() ?

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: [OpenGL 4] Internal error with sf::texture
« Reply #3 on: December 14, 2015, 10:20:19 pm »
You know there is a function called glGetError() right? You might want to read its documentation.

So you'd suggest me to create my own texture wrapper instead of using sf::Texture::bind()?
You should know this yourself. If you don't understand what I said, then don't bother. Just ignore what I said.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

bisthebis

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: [OpenGL 4] Internal error with sf::texture
« Reply #4 on: December 15, 2015, 10:31:51 am »
I just learned about glGetError yesterday. Looks like the tutorials I've been follwoing aren't doing enough work about error-handling.

bisthebis

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: [OpenGL 4] Internal error with sf::texture
« Reply #5 on: December 15, 2015, 11:39:05 am »
It definitely looks like sf::Texture file-loading was causing the issue...
I've written my own Texture class (which DOES handle error, this time :D) and I still get the error when binding VAO. But if I delete the lines when I load a sf::Texture (which I don't use anyway, since I've made my own Texture class) the issue disappear.