Last active
August 26, 2025 12:55
-
-
Save vojd/d7c4b2929c8b985826f471b965eb15c2 to your computer and use it in GitHub Desktop.
Simple OpenGL window in Rust
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[dependencies] | |
gl = "*" | |
glutin = "0.26" | |
winit = "0.24" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate gl; | |
extern crate glutin; | |
extern crate winit; | |
use glutin::ContextBuilder; | |
use winit::{ | |
event::{Event, WindowEvent}, | |
event_loop::{ControlFlow, EventLoop}, | |
window::WindowBuilder, | |
}; | |
fn main() { | |
let event_loop = EventLoop::new(); | |
let window = WindowBuilder::new(); | |
let window_context = ContextBuilder::new() | |
.build_windowed(window, &event_loop) | |
.unwrap(); | |
let context = unsafe { window_context.make_current().unwrap() }; | |
gl::load_with(|s| context.get_proc_address(s) as *const _); | |
event_loop.run(move |event, _, control_flow| { | |
match event { | |
Event::WindowEvent { | |
event: WindowEvent::CloseRequested, | |
.. | |
} => { | |
println!("Bye now..."); | |
*control_flow = ControlFlow::Exit | |
} | |
Event::RedrawRequested(_) => { | |
unsafe { | |
gl::ClearColor(0.2, 0.5, 0.2, 1.0); | |
gl::Clear(gl::COLOR_BUFFER_BIT); | |
} | |
context.swap_buffers().unwrap(); | |
} | |
_ => (), | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't need three layers of step-by-steps before they let me draw a pixel :( This, on the other hand, is perfect. My exasperated gratitude! ❤️