three-d icon indicating copy to clipboard operation
three-d copied to clipboard

Headless on windows

Open melMass opened this issue 1 year ago • 2 comments

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

melMass avatar Dec 27 '23 23:12 melMass

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 🙂

asny avatar Jan 25 '24 08:01 asny

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");

N3xed avatar Apr 01 '24 12:04 N3xed