Jump to content
  • Advertisement
Sign in to follow this  
Jamie_Edwards

OpenGL call failed in RenderTarget.cpp (SFML2)

This topic is 908 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys,

So I'm now using CodeLite to develop my SFML game, and also reading from the SFML Game Development book and have hit a little bit of a hitch in the third chapter called "World".

This is the github for the chapter: https://github.com/SFML/SFML-Game-Development-Book/tree/master/03_World

Now onto my error... I've copied what's both in the book and the github word for word in terms of code (I've added extra functions here and there to break the code into more understandable parts for me).

Now it all comes out error and warning free, but when I go to run the program I get a black window and the following runtime error:

 
An internal OpenGL call failed in RenderTarget.cpp(418).
Expression:
   glViewport(viewport.left, top, viewport.width, viewport.height)
Error description:
   GL_INVALID_VALUE
   A numeric argument is out of range.

Now I've looked around the internet and found out that that error tends to lead to an out-of-date graphics card... But I've a very new Lenovo IdeaPad Flex 10 running Ubuntu 15.10.

Also when I do the following in the main Game class:

sf::Texture m_texture;
sf::Sprite m_sprite;

m_texture.loadFromFile("/Path/To/Texture/Resource.png");

m_sprite.setTexture(m_texture);

m_window.clear();
m_window.draw(m_sprite);
m_window.display();

And that single sprite displays fine.

 

I also placed the following into my Game::run() function to check the major version of OpenGL my graphics card can provide:

sf::ContextSettings settings = m_window.getSettings();
    std::cout << settings.majorVersion << "." << settings.minorVersion << std::endl;
 

and it came out with a value of 3.0.

 

 I don't understand what could be going wrong... Any ideas?

Share this post


Link to post
Share on other sites
Advertisement

It is more than just your card.   It is combination of the card and drivers used on the system, the system's settings, and the configuration values.

 

Assuming you've got it installed, use glxinfo to figure out what version of OpenGL you've got.  

 

Run the command:  glxinfo | grep -i opengl

 

That should list your graphics card information and the OpenGL version currently in use by the running system.

Share this post


Link to post
Share on other sites

It is more than just your card.   It is combination of the card and drivers used on the system, the system's settings, and the configuration values.

 

Assuming you've got it installed, use glxinfo to figure out what version of OpenGL you've got.  

 

Run the command:  glxinfo | grep -i opengl

 

That should list your graphics card information and the OpenGL version currently in use by the running system.

 

This is what I get from that:

jamie@jamie:~$ glxinfo | grep -i opengl
OpenGL vendor string: Intel Open Source Technology Center
OpenGL renderer string: Mesa DRI Intel(R) Bay Trail 
OpenGL core profile version string: 3.3 (Core Profile) Mesa 11.0.2
OpenGL core profile shading language version string: 3.30
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 3.0 Mesa 11.0.2
OpenGL shading language version string: 1.30
OpenGL context flags: (none)
OpenGL extensions:
OpenGL ES profile version string: OpenGL ES 3.0 Mesa 11.0.2
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.00
OpenGL ES profile extensions:

Share this post


Link to post
Share on other sites

I think you're going down the wrong track here.

 

glViewport is documented to cause a GL_INVALID_VALUE error if either the width or height you give it are negative, and this is the only case for which glViewport is documented to cause this error.  I'd suggest that you use a debugger, set a breakpoint, and examine the values of viewport.width and viewport.height to determine if this is the case: first rule is to check the obvious documented causes before assuming that drivers/GL_VERSIONs/etc are at fault.

 

If this is the cause then the viewport will be left at it's default, which is the dimensions of the window.  Hence the fact that everything can seem to work despite giving glViewport invalid values.

Share this post


Link to post
Share on other sites

This is what I get from that:

jamie@jamie:~$ glxinfo | grep -i opengl
...
OpenGL version string: 3.0 Mesa 11.0.2

So 3.0 is the correct version.

So to answer the question

and it came out with a value of 3.0. I don't understand what could be going wrong... Any ideas?

That is the version your system is using. Nothing is "wrong", although it might be unexpected to you. Your configuration is set to use OpenGL version 3.0.

If you want something newer you'll need to update your system's drivers or other configuration values. There are many different OpenGL drivers available on Linux systems with a wide range of configuration options.

 

You'll need to research what combinations work with your hardware and be prepared to undo whatever changes you did if you accidentally mess something up.

Share this post


Link to post
Share on other sites

I think you're going down the wrong track here.

 

glViewport is documented to cause a GL_INVALID_VALUE error if either the width or height you give it are negative, and this is the only case for which glViewport is documented to cause this error.  I'd suggest that you use a debugger, set a breakpoint, and examine the values of viewport.width and viewport.height to determine if this is the case: first rule is to check the obvious documented causes before assuming that drivers/GL_VERSIONs/etc are at fault.

 

If this is the cause then the viewport will be left at it's default, which is the dimensions of the window.  Hence the fact that everything can seem to work despite giving glViewport invalid values.

 

If  that's the case then in my game class I have the following:

void Game::render() {
    m_window.clear();

    m_world.draw();

    m_window.setView(m_window.getDefaultView());

    m_window.display();
}

And in my World class:

World::World(sf::RenderWindow &window) :
m_window(window),
m_worldView(window.getDefaultView()),
...
m_scrollSpeed(-50.0f),
...
{
    ...

    m_worldView.setCenter(m_spawnPosition);
}

World::update(sf::Time dt) {
    // Scroll the world 
    m_worldView.move(0.0f, m_scrollSpeed * dt.asSeconds());
    ...
}

World::draw() {
    m_window.setView(m_worldView);
    ....
}

m_scrollSpeed is the only thing I know of that is in negative values apart from the players escorting aircraft.

Share this post


Link to post
Share on other sites

 

This is what I get from that:

jamie@jamie:~$ glxinfo | grep -i opengl
...
OpenGL version string: 3.0 Mesa 11.0.2

So 3.0 is the correct version.

So to answer the question

and it came out with a value of 3.0. I don't understand what could be going wrong... Any ideas?

That is the version your system is using. Nothing is "wrong", although it might be unexpected to you. Your configuration is set to use OpenGL version 3.0.

If you want something newer you'll need to update your system's drivers or other configuration values. There are many different OpenGL drivers available on Linux systems with a wide range of configuration options.

 

You'll need to research what combinations work with your hardware and be prepared to undo whatever changes you did if you accidentally mess something up.

 

How would my drivers be an issue if, as I've already mentioned, I can get textures onto the screen if I completely bypass everything and create everything within my Game class?

Share this post


Link to post
Share on other sites


If  that's the case then in my game class I have the following:

<snip>
And in my World class:

<snip>

Pasting your code here isn't what mhagain is suggesting.

The suggestion is to set a breakpoint and inspect the actual values when the code is being executed, to verify that they are actually valid when the error occurs.

Have you done this?

 

Actually, is debugging with breakpoints something you've done before? Since this is in For Beginners, your experience level is hard to guess.

Share this post


Link to post
Share on other sites

 


If  that's the case then in my game class I have the following:

<snip>
And in my World class:

<snip>

Pasting your code here isn't what mhagain is suggesting.

The suggestion is to set a breakpoint and inspect the actual values when the code is being executed, to verify that they are actually valid when the error occurs.

Have you done this?

 

Actually, is debugging with breakpoints something you've done before? Since this is in For Beginners, your experience level is hard to guess.

 

I have, but because I've moved over from WIndows originally and used VSC++, it was a lot easier to set break points and see it as it goes on there.

 

I'm now using Ubuntu 15.10 and CodeLite... So I'll try and give it a go, and post my findings...

 

EDIT:-

 

Ok, so here's what I'm seeing:

 

World::m_worldView:

m_viewport:
     left: 4.5...
     top: 6.1...
     width: 0
     height: -nan(0x7fdfd0)

Do you know what that means?

Edited by Jamie_Edwards

Share this post


Link to post
Share on other sites

Hmmm, looks like whatever you're passing into your glViewport call is getting trashed, stomped on, or is just plain old uninitialized.  Whichever, it's definitely the cause of your error anyway.  Next step is for you to find where those values are coming from.  I see that you've got m_worldView(window.getDefaultView()) so window.getDefaultView() looks a good first place to check.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!