Skip to content

Instantly share code, notes, and snippets.

@brendanzab
Created September 21, 2012 06:36
Show Gist options
  • Save brendanzab/3760038 to your computer and use it in GitHub Desktop.
Save brendanzab/3760038 to your computer and use it in GitHub Desktop.
import glfw3::*;
fn run(init_fn: &fn(), update_fn: &fn(tpf: f64), render_fn: &fn(), cleanup_fn: &fn()) {
init(init_fn, cleanup_fn);
mainloop(update_fn, render_fn, cleanup_fn);
cleanup(cleanup_fn);
}
fn init(init_fn: &fn(), cleanup_fn: &fn()) {
init_fn();
if(glfwInit() == 0) {
cleanup(cleanup_fn);
fail(~"glfwInit() failed\n");
}
}
fn mainloop(update_fn: &fn(tpf: f64), render_fn: &fn(), cleanup_fn: &fn()) {
do task::task().sched_mode(task::PlatformThread).spawn {
let mut window = glfwCreateWindow(300, 300, GLFW_WINDOWED, ~"Hello, I am a window.");
if (ptr::is_null(window.ptr)) {
cleanup(cleanup_fn);
io::println(~"Error: " + glfwErrorString(glfwGetError()));
fail(~"glfwOpenWindow() failed\n");
}
glfwSwapInterval(1);
let mut running = true;
while running {
glfwPollEvents();
if (glfwGetKey(&window, GLFW_KEY_ESC) == GLFW_PRESS || glfwGetWindowParam(&window, GLFW_CLOSE_REQUESTED) != 0) {
running = false;
}
update_fn(0f64);
render_fn();
glfwSwapBuffers(&window);
}
}
}
fn cleanup(cleanup_fn: &fn()) {
cleanup_fn();
glfwTerminate();
}
./src/owindow/app.rs:32:20: 32:30 error: not a sendable value
./src/owindow/app.rs:32 cleanup(cleanup_fn);
^~~~~~~~~~
./src/owindow/app.rs:45:12: 45:21 error: not a sendable value
./src/owindow/app.rs:45 update_fn(0f64);
^~~~~~~~~
./src/owindow/app.rs:47:12: 47:21 error: not a sendable value
./src/owindow/app.rs:47 render_fn();
^~~~~~~~~
error: aborting due to 3 previous errors
use app;
void main() {
app::run(&init, &update, &render, &cleanup);
}
fn init() {}
fn update(tpf: f64) {}
fn render() {}
fn cleanup() {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment