rust-windowing/glutin

Windows OpenGL context creation only loads version 1.1

Nautilus-1021 opened this issue · 11 comments

I am doing a "screensaver" with OpenGL, so when the application starts, it immediately requests borderless fullscreen. For that, I am using WindowBuilder::with_fullscreen(). After that the application requests for an OpenGL context with version 3.3 but on Windows it only gets a context version 1.1. I tested the application on Linux and it works. I know that on Windows, getting a context with a higher version than 1.1 needs more configuration, and I did everything (as far as I know) that is mandatory for OpenGL in Windows. Since I am only getting a OpenGL 1.1 context, when I try to call glGenerateMipmap, it crashes because the function is not loaded.

Here is the code: https://github.com/Nautilus-1021/DVD-Screen-Saver-Rust

Does it work with the example?

I ran the example and it works on my computer, if that's what you want to know.

No I mean, which version it picks? It should say so, like

Picked a config with 16 samples
Running on Mesa Intel(R) Arc(tm) A750 Graphics (DG2)
OpenGL Version 4.6 (Core Profile) Mesa 24.0.1
Shaders version on 4.60

I'm pretty sure you don't create window before the display stuff, so I'd suggest to look into how glutin example/glutin-winit structures the code for windows, since it's special.

It says:

Picked a config with 16 samples
Running on NVIDIA GeForce GTX 1650/PCIe/SSE2
OpenGL Version 3.3.0 NVIDIA 551.61
Shaders version on 3.30 NVIDIA via Cg compiler

But in my program it says:

[GLUTIN] OpenGL Version: <Unknown>
[GLOW] Running on OpenGL 1.1 (Rev.0)
[GLOW] Driver:

I use Glow to generate OpenGL bindings, and for debugging I print the context version by Glutin and by Glow.

Also I already read the example and compared line by line the code, and I don't think the error is in my code. I initialize the display with the window builder argument:
let display_builder = DisplayBuilder::new().with_window_builder(Some(window_builder));
and I also build the ContextAttributes with the window as argument:
let context_attributes = ContextAttributesBuilder::new().with_context_api(ContextApi::OpenGl(Some(Version::new(3, 3)))).with_profile(GlProfile::Core).build(raw_wnd);.

Maybe I'm wrong, so if you have time, you can look at my code, it isn't very big.

I ran my program on my Linux laptop and it works and says:

[GLUTIN] OpenGL Version: <Unknown>
[GLOW] Running on OpenGL 4.6 (Rev.1)
[GLOW] Driver: (Core Profile) Mesa 23.3.5-manjaro1.1

See https://github.com/rust-windowing/glutin/blob/master/glutin-winit/src/lib.rs#L111

You must create window for display.

If example works (it clearly does) it's not glutin issue, since 1.1 could be obtained if and only if you don't pass the window for the display itself, because it's that default windows fallback when you don't have window, so it doesn't know what to pick.

Oh, and you also need the context to be current when loading symbols, but it's all documented in loader.

I debugged my code, especially the part where I create the display, and Glutin actually creates the window before the display, because I pass a WindowBuilder as argument to the DisplayBuilder, so it builds my window before the display. And for your second comment, here is the code where I load the symbols:

let glutin_ctx = not_current_context.make_current(&gl_surface).unwrap();

let ContextApi::OpenGl(gl_version) = glutin_ctx.context_api() else {
  panic!("Not OpenGL !");
};
println!("[GLUTIN] OpenGL Version: {}", gl_version.map(|version| { format!("{}.{}", version.major, version.minor) }).unwrap_or("<Unknown>".to_owned()));

let ctx = unsafe {glow::Context::from_loader_function_cstr(|func_name| {gl_display.get_proc_address(func_name)})};

So I really don't know what I did wrong.

I can't really help with knowing all the code, because clearly example from glutin worked correctly.

Ok it was actually my fault.

Did you know that creating a OpenGL context with a 0 sample config on Windows will make a context restricted to builtin functions ? Me no.

We create it like that in alacritty, I'd be surprised.