1

我正在开发一个屏幕外渲染程序,我使用 crateglium来做到这一点。我遵循了screenshot.rs的例子,这个例子运行良好。

然后我做了一些改变:

原始代码是

fn main() {
    // building the display, ie. the main object
    let event_loop = glutin::EventsLoop::new();
    let wb = glutin::WindowBuilder::new().with_visible(true);
    let cb = glutin::ContextBuilder::new();
    let display = glium::Display::new(wb, cb, &event_loop).unwrap();

    // building the vertex buffer, which contains all the vertices that we will draw

我将这些代码分组为一个函数:

fn main() {
    // building the display, ie. the main object
    let event_loop = glutin::EventsLoop::new();
    let display = build_display((128,128), &event_loop);

    // building the vertex buffer, which contains all the vertices that we will draw
pub fn build_display(size: (u32, u32), event_loop: &glutin::EventsLoop) -> glium::Display {
    let version = parse_version(); //this will return `OpenGL 3.3`
    let wb = glutin::WindowBuilder::new()
        .with_visibility(false)
        .with_dimensions(glutin::dpi::LogicalSize::from(size));
    let cb = glutin::ContextBuilder::new()
        .with_gl(version);
    glium::Display::new(wb, cb, &event_loop).unwrap()
}

经过这次修改,程序仍然运行良好。所以我继续添加无头上下文:

fn main() {
    // building the display, ie. the main object
    let event_loop = glutin::EventsLoop::new();
    let display = build_display_headless((128,128), &event_loop);

    // building the vertex buffer, which contains all the vertices that we will draw
pub fn build_display_headless(size: (u32, u32), event_loop: &glutin::EventsLoop) -> glium::HeadlessRenderer {

    let version = parse_version();  // this will return `OpenGL 3.3`
    let ctx = glutin::ContextBuilder::new()
        .with_gl(version)
        .build_headless(&event_loop, glutin::dpi::PhysicalSize::from(size))
        .expect("1");
    //let ctx = unsafe { ctx.make_current().expect("3") };
    glium::HeadlessRenderer::new(ctx).expect("4")
}

但这一次,该程序不起作用。运行过程中没有恐慌,但输出的图像是黑色的,并且它的大小不是 128x128 而是 800x600。

我试图删除,libEGL.dll因此由于 crate 的文档glutin,该函数.build_headless将构建一个窗口并将其隐藏,就像我的函数build_display一样。然而,这也失败了。那么是什么原因造成的呢?

4

0 回答 0