标签: glium

使用Glium中的UniformBuffer将任意大小的对象传递给片段着色器

我在尝试一系列不同的技术时提出了我的问题,但我没有多少经验.可悲的是,我甚至不知道我是否犯了一个愚蠢的逻辑错误,我是否使用了glium箱子错误,我是否搞砸了GLSL等等.无论如何,我设法从头开始一个新的Rust项目,努力寻找一个显示我的问题的最小例子,问题至少在我的电脑上重现.

最小的例子最终难以解释,所以我首先做一个更小的例子来做我想做的事情,虽然通过黑客攻击并限制为128个元素(4倍32位,在a中GLSL uvec4) .从这一点来看,我的问题出现的版本的步骤非常简单.

一个工作版本,简单uniform和位移

程序在屏幕上创建一个矩形,纹理坐标从水平0.0128.0水平.该程序包含一个用于矩形的顶点着色器,以及一个片段着色器,它使用纹理坐标在矩形上绘制垂直条纹:如果纹理坐标(夹到a uint)是奇数,则在纹理坐标为偶数时绘制一种颜色,它绘制另一种颜色.

// GLIUM, the crate I'll use to do "everything OpenGL"
#[macro_use]
extern crate glium;

// A simple struct to hold the vertices with their texture-coordinates.
// Nothing deviating much from the tutorials/crate-documentation.
#[derive(Copy, Clone)]
struct Vertex {
    position: [f32; 2],
    tex_coords: [f32; 2],
}

implement_vertex!(Vertex, position, tex_coords);


// The vertex shader's source. Does nothing special, except passing the …
Run Code Online (Sandbox Code Playgroud)

glsl rust glium

5
推荐指数
1
解决办法
408
查看次数

如何在Rust中导入宏?

我正在努力解决如何从外部箱子导入宏的问题.在我的主要人员中,我正在进口Glium箱子:

#![macro_use]
extern crate glium;

pub use glium::*;

// where my actual main function will be done from
mod part01drawtriangle;

fn main() {
    part01drawtriangle::main();
}
Run Code Online (Sandbox Code Playgroud)

在我的主要功能来自我的另一个文件中,我从该包中调用了一个宏:

pub fn main() {
    implement_vertex!(Vertex, position);
}
Run Code Online (Sandbox Code Playgroud)

构建时,我收到错误消息:

error: macro undefined: 'implement_vertex!'
Run Code Online (Sandbox Code Playgroud)

macros rust glium

5
推荐指数
2
解决办法
4167
查看次数

如何在glium中使用cgmath :: Matrix作为统一参数?

我正在尝试将cgmath库集成到我的第一个实验中glium,但我无法弄清楚如何将我的Matrix4对象传递给draw()调用.

我的uniforms目标是这样定义的:

let uniforms = uniform! {
    matrix: cgmath::Matrix4::from_scale(0.1)
};
Run Code Online (Sandbox Code Playgroud)

这是我的draw电话:

target.draw(&vertex_buffer, &index_slice, &program, &uniforms, &Default::default())
      .unwrap();
Run Code Online (Sandbox Code Playgroud)

无法使用该消息进行编译

error[E0277]: the trait bound `cgmath::Matrix4<{float}>: glium::uniforms::AsUniformValue` is not satisfied
Run Code Online (Sandbox Code Playgroud)

我是Rust的初学者,但我相信我自己也无法实现这个特性,因为它和它的Matrix4类型都与我的分开.

除了手动将矩阵转换为浮点数组数组之外,真的没有更好的选择吗?

rust glium

4
推荐指数
1
解决办法
738
查看次数

无约束类型参数错误

我正在尝试将glium与cgmath接口。按照这个答案,我实现了一个ToArray特征,将的实例转换cgmath::Matrix4为glium可以使用的格式:

pub trait ToArray {
    type Output;
    fn to_array(&self) -> Self::Output;
}

impl<S: cgmath::BaseNum> ToArray for cgmath::Matrix4<S> {
    type Output = [[S; 4]; 4];
    fn to_array(&self) -> Self::Output {
        (*self).into()
    }
}
Run Code Online (Sandbox Code Playgroud)

由于我并不总是Matrix4直接使用,因此我需要对cgmath转换类型进行类似的实现。例如cgmath::Decomposed

impl<S: cgmath::BaseFloat, R: cgmath::Rotation3<S>> ToArray
    for cgmath::Decomposed<cgmath::Vector3<S>, R> {
    type Output = [[S; 4]; 4];
    fn to_array(&self) -> Self::Output {
        cgmath::Matrix4::<S>::from(*self).into()
    }
}
Run Code Online (Sandbox Code Playgroud)

这可行,但是我想避免为所有转换类型重复代码,所以我认为我将为可以转换为的任何东西定义一个通用实现Matrix4

impl<S: cgmath::BaseFloat, T: Into<cgmath::Matrix4<S>>> ToArray for T {
    type Output = …
Run Code Online (Sandbox Code Playgroud)

rust glium

3
推荐指数
1
解决办法
1870
查看次数

在 glium 中设置帧重绘率?

我正在尝试使用 Rust 中的 glium 来制作游戏循环。我的目标是让屏幕每秒重绘 60 次。使用我当前的事件循环代码,只有当窗口大小发生变化时才会重新绘制框架。我在 glutin 文档中读到,我需要在某处调用 request_redraw,但我不确定如何/在哪里。到目前为止,这是我的代码:

event_loop.run(move |event, _target, control_flow| match event {
    Event::LoopDestroyed => return,
    Event::WindowEvent {
        window_id: _window_id,
        event: winevent,
    } => match winevent {
        WindowEvent::Resized(physical_size) => display.gl_window().resize(physical_size),
        WindowEvent::CloseRequested => {
            *control_flow = ControlFlow::Exit;
        }
        _ => {}
    },
    Event::RedrawRequested(_window_id) => {
        let mut target = display.draw();
        target.clear_color_srgb(rng.gen(), rng.gen(), rng.gen(), 1.0);
        target.finish().unwrap();
    }
    _ => {}
});
Run Code Online (Sandbox Code Playgroud)

game-loop rust glium

0
推荐指数
1
解决办法
2203
查看次数

标签 统计

glium ×5

rust ×5

game-loop ×1

glsl ×1

macros ×1