Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to fix problem when function pointer is not loaded #103

Closed
bvssvni opened this issue Dec 10, 2014 · 10 comments
Closed

How to fix problem when function pointer is not loaded #103

bvssvni opened this issue Dec 10, 2014 · 10 comments

Comments

@bvssvni
Copy link
Member

bvssvni commented Dec 10, 2014

OpenGL uses a function pointer loader system to enable the API for use in applications. This means you need to call gl::load_with(|s| window.get_proc_address(s)); or similar.

The SDL2 and GLFW back-ends for Piston loads the functions when initializing a new window. You are most likely getting this error because you attempt to call an OpenGL function before the window is created, or you are working directly against the back-end. It might also be the case that you are using another back-end where what is happening is uncertain. In any case, the problem is that the gl-rs library must load the function pointers before you can use it.

Try to initialize the window first, or load the function pointers manually.

For SDL2 you call:

// Load the OpenGL function pointers
gl::load_with(|s| unsafe {
    transmute(sdl2::video::gl_get_proc_address(s))
});

For GLFW you call:

// Load the OpenGL function pointers
gl::load_with(|s| window.get_proc_address(s));

Running an old version of OpenGL

It might be the case that you are loading an old version of OpenGL that does not support shaders. In that case, you can not use opengl_graphics because it requires GLSL shader support to work. You can fork opengl_graphics and modify the source to use the old fixed rendering pipeline. If there is a way to make this work with opengl_graphics, then contributions are welcome.

Setting the wrong version of OpenGL

If you pass a shader_version::OpenGL to the constructor, the window must be initialized with the same version, as seen here. The major and minor version must match the ones that is used to pick the compatible shader. Make sure that the same shader_version::OpenGL is passed to the window.

@abonander
Copy link
Contributor

If you're getting the wrong version of OpenGL with SDL2, make sure you're setting the version and profile attributes as seen here.

sdl2_window will load the OpenGL functions and create a context for you.

@freiguy1
Copy link

I'm using glutin and getting this error:

thread '<main>' panicked at 'gl function was not loaded', C:\Temp\wermz\target\debug\build\gl-9653698dd50d604e\out/bindings.rs:22460
An unknown error occurred

I've only openGL 1.1 installed on windows 7. However, this is a virtual machine and I'm not seeing a way to update openGL. Also I'm using glutin instead of SDL2 or GLFW. This is the relevant code:

fn main() {
    let opengl = OpenGL::_3_2;

    let mut windowSettings = WindowSettings::new(
        "spinning-square",
        [200, 200])
        .opengl(opengl)
        .exit_on_esc(true);

    // Create an Glutin window.
    let window = Window::new(windowSettings);

    // Create a new game and run it.
    let mut app = App {
        gl: GlGraphics::new(opengl),
        rotation: 0.0
    };
...

In the code, you'll see openGL version _3_2, but this is because I'm not seeing _1_1 as an option. Is there any way to get my application running on this VM?

Thanks!

@abonander
Copy link
Contributor

Which VM software are you using?

@freiguy1
Copy link

Actually, this is a VM hosted by my employer. Regrettably, I'm not sure what software is running it, and I doubt I have much capability to have them modify my instance.

@abonander
Copy link
Contributor

The problem is, you're getting WGL which is the software implementation of OpenGL 1.1 that comes with Windows. It only supports the old fixed pipeline and doesn't work with modern OpenGL applications.

It is likely that you have to install the guest OS additions package for your VM software to enable graphics acceleration. You'll probably need to consult your VM server's sysadmin because it depends highly on which VM suite you're running and how it's set up.

@freiguy1
Copy link

Ok, this is sort of what I was expecting. Thanks!

@Thomasdezeeuw
Copy link

This also happens when you try to create a Texture before creating a window, which sees a little weird to me, but creating the window first fixed it for me.

@real-felix
Copy link

real-felix commented Dec 12, 2017

Hi, I updated to piston2d-opengl_graphics 0.48.0 and now this happens again. I first do:

let window = WindowSettings::new("my title", size)
    .opengl(version)
    .samples(samples)
    .vsync(true)
    .build()
    .expect("Cannot initialize the window: ");

And then:

let gl = GlGraphics::new(version);

This panics with the message:

undefinedthread 'main' panicked at '
    OpenGL function pointers must be loaded before creating the `Gl` backend!
    For more info, see the following issue on GitHub:
    https://github.com/PistonDevelopers/opengl_graphics/issues/103
', ~/.cargo/registry/src/github.com-1ecc6299db9ec823/piston2d-opengl_graphics-0.48.0/src/back_end.rs:315:8

I only updated my Cargo.toml from:

piston_window = "0.70.0"
piston2d-opengl_graphics = "0.46.0"
pistoncore-sdl2_window = "0.44.0"
conrod = { version = "0.55.0", features = ["piston"] }

to:

piston_window = "0.73.0"
piston2d-opengl_graphics = "0.49.0"
pistoncore-sdl2_window = "0.47.0"
conrod = { version = "0.57.0", features = ["piston"] }

@filippo-orru
Copy link

Have this issue as well. Can't get my game to work after updating Cargo.toml dependencies. There seems to be a mismatch between the different crates. For example:
When calling viewport() on the Renderargs returned by the eventloop, my opengl.draw(viewport, closure) doesn't work as they use different versions of Viewport. One from graphics::Viewport and another in the same file as the Renderargs (probably piston::input::viewport::Viewport but I'm not sure)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants
@freiguy1 @bvssvni @Thomasdezeeuw @abonander @real-felix @filippo-orru and others