DOOM on Glium
or how I learned to stop worrying and love OpenGL
Hi, I’m Cristi!
I do ML stuff at re:infer
Rule 34 of Programming Languages
Rule 34 of Programming Languages
If it exists, then DOOM runs on it.
- Johannes Carmackael
Hacker News new | threads | comments
[...] difficult to port code [...] to Rust [...]. There is a port of Doom to Rust. It has a lot of unsafe code, because Doom's internal memory structures are not directly compatible with Rust's. Such problems will recur as big packages with delicate internals are ported over to Rust.
Animats (458 days ago)
First Version
Second Version
GL Fixed-Function Pipeline (ca. 1997)
Vertex Data
Culling Clipping
Attributes
Transforming & Lighting
Primitive Data
Rasterisation
Alpha/Depth/Stencil Tests
Alpha Blending
Eyeballs
Texture Data
GL Fixed-Function Pipeline (ca. 1997)
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(modelview_matrix);
glEnable(GL_TEXTURE_2D); // and many more
glBindTexture(GL_TEXTURE_2D, my_texture);
glBegin(GL_TRIANGLES);
for (int i=0; i<n; ++i) {
glVertex3f(x[i], y[i], z[i]);
glColor3f(r[i], g[i], b[i]);
}
glEnd();
Modern OpenGL (another lie)
Vertex Shader
Data (buffers)
Fragment Shader
Tests & Blending
Eyeballs
Data (buffers)
Geometry Shader
Modern OpenGL
shader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(shader, 1, source, strlen(source));
glCompileShader(shader)
int result;
glShaderiv(shader, GL_COMPILE_STATUS, &result)
if (result == 0) {
int log_length;
glShaderiv(shader, GL_INFO_LOG_LENGTH, &log_length);
char* buffer = malloc(log_length + 1);
glGetShaderInfoLog(shader, log_length, NULL, buffer);
}
OpenGL API: Resource Management
OpenGL API: Drawing
OpenGL API: Giant State Machine
glium
glium
Glium: Stateless API
Glium: Strong, Static Typing
Glium: Strong, Static Typing
#[repr(C)]�#[derive(Copy, Clone)]�pub struct StaticVertex {� pub a_pos: [f32; 3],� pub a_atlas_uv: [f32; 2],� pub a_tile_uv: [f32; 2],� pub a_tile_size: [f32; 2],� pub a_scroll_rate: f32,� pub a_row_height: f32,� pub a_num_frames: u8,� pub a_light: u8,�}
let vertices: Vec<StaticVertex> = vec![];
vertices.push(StaticVertex {/* ... */});�// ...
�let buffer: VertexBuffer<StaticVertex> =
VertexBuffer::immutable(
window.facade(), &vertices)
Modern OpenGL
shader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(shader, 1, source, strlen(source));
glCompileShader(shader)
int result;
glShaderiv(shader, GL_COMPILE_STATUS, &result)
if (result == 0) {
int log_length;
glShaderiv(shader, GL_INFO_LOG_LENGTH, &log_length);
char* buffer = malloc(log_length + 1);
glGetShaderInfoLog(shader, log_length, NULL, buffer);
}
Glium: Resource Management
Program::new(self.window.facade(),� ProgramCreationInput::SourceCode {� vertex_shader: &vertex_src,� fragment_shader: &fragment_src,� ..Default::default()� })
Glium: Multi-threading
Glium: Rust Philosophy
Glium: Rust Philosophy
Glium: Rust Philosophy
Glium: Rust Philosophy