asny / three-d

2D/3D renderer - makes it simple to draw stuff across platforms (including web)
MIT License
1.29k stars 109 forks source link

Headless on windows #429

Closed melMass closed 2 weeks ago

melMass commented 9 months ago

Hi,

I'm trying to the headless render example but I get the following:

glutin error: GetClassInfoExW function failed: Class does not exist. (os error 1411)

I changed the HeadlessError enum to get more info about the error by adding {0}:

pub enum HeadlessError {
    #[error("glutin error: {0}")]
    GlutinCreationError(#[from] glutin_029::CreationError),
    #[error("glutin error: {0}")]
    GlutinContextError(#[from] glutin_029::ContextError),
    ...
  }
Thanks
asny commented 8 months ago

three-d just uses the glutin crate for creating a context and the error definitely originates from that crate, so I would suggest you post this question on their GH instead 🙂

N3xed commented 6 months ago

Here's a workaround using the glfw and glow crate (modified from the gl_headless crate):

let mut glfw = glfw::init(|err, desc| panic!("glfw error [{}]: {}", err, desc))
.expect("failed to initialize glfw");

glfw.window_hint(glfw::WindowHint::ContextVersion(4, 6));
glfw.window_hint(glfw::WindowHint::OpenGlProfile(
    glfw::OpenGlProfileHint::Core,
));
glfw.window_hint(glfw::WindowHint::OpenGlForwardCompat(true));
glfw.window_hint(glfw::WindowHint::Visible(false));

let (mut wnd, events) = glfw
    .create_window(1, 1, env!("CARGO_PKG_NAME"), glfw::WindowMode::Windowed)
    .expect("failed to create glfw window");

let ctx = three_d::Context::from_gl_context(unsafe {
    Arc::new(glow::Context::from_loader_function(|s| {
        wnd.get_proc_address(s) as *const _
    }))
})
.expect("failed to create OpenGL context");