Last active
December 25, 2015 03:09
-
-
Save jsanders/6908022 to your computer and use it in GitHub Desktop.
GLUT hello world implementations in c++ (for reference) and rust (as an attempt). The rust version seems close to working, but it hangs after the window comes up...
This file contains 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
// Compile with `g++ -framework GLUT glut_hello_world.cpp` | |
#include <GLUT/glut.h> | |
void display(void) { } | |
int main(int argc, char** argv) { | |
glutInit(&argc, argv); | |
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); | |
glutInitWindowSize(500, 500); | |
glutInitWindowPosition(100, 100); | |
glutCreateWindow("Hello, world!"); | |
glutDisplayFunc(display); | |
glutMainLoop(); | |
return 0; | |
} |
This file contains 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
// Compile with `rustc glut_hello_world.rs` | |
use std::libc::{c_int, c_char}; | |
use std::ptr::{null, to_unsafe_ptr}; | |
use std::cast::transmute; | |
#[link_args = "-framework GLUT"] | |
extern { | |
fn glutInit(argc: *c_int, argv: **u8); | |
fn glutInitDisplayMode(mode: c_int); | |
fn glutInitWindowSize(width: c_int, height: c_int); | |
fn glutInitWindowPosition(top: c_int, left: c_int); | |
fn glutCreateWindow(title: *c_char); | |
fn glutDisplayFunc(callback: &fn()); | |
fn glutMainLoop(); | |
} | |
static GLUT_RGB: c_int = 0x0000; | |
static GLUT_DOUBLE: c_int = 0x0002; | |
static GLUT_DEPTH: c_int = 0x0010; | |
fn display() { } | |
#[fixed_stack_segment] | |
fn main() { | |
unsafe { | |
let args = std::os::args(); | |
let argc = args.len() as c_int; | |
let argc_p = to_unsafe_ptr(&argc); | |
let mut argv = do args.map |arg| { | |
arg.to_c_str().unwrap() as *u8 | |
}; | |
argv.push(null::<u8>()); | |
let argv_p = transmute(to_unsafe_ptr(&argv)); | |
glutInit(argc_p, argv_p); | |
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); | |
glutInitWindowSize(500, 500); | |
glutInitWindowPosition(100, 100); | |
glutCreateWindow("Hello, world!".to_c_str().unwrap()); | |
glutDisplayFunc(display); | |
glutMainLoop(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment