Commits

Joseph Marshall committed 19ef7f9

Added an opengl es1 example.

Comments (0)

Files changed (1)

examples/gles1.rs

+use sdl (vers="0.1");
+use gl;
+
+import gl::*;
+
+fn main() {
+    sdl::init([sdl::init_video, sdl::init_timer]);
+
+    let surface = sdl::video::set_video_mode(800, 600, 32, [],
+            [sdl::video::doublebuf, sdl::video::opengl]);
+    assert surface != ptr::null();
+
+    setup();
+
+    let mut running = true;
+    while running {
+        sdl::event::poll_event {|ev|
+            alt ev {
+                sdl::event::quit_event { running = false; }
+                _ {}
+            }
+        }
+
+        draw();
+    }
+
+    sdl::video::free_surface(surface);
+}
+
+
+fn draw() {
+    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+    glLoadIdentity();
+ 
+    glBegin(GL_QUADS);
+        glColor3f(1.0, 0.0, 0.0); glVertex3f(0.0, 0.0, 0.0);
+        glColor3f(1.0, 1.0, 0.0); glVertex3f(100.0, 0.0, 0.0);
+        glColor3f(1.0, 0.0, 1.0); glVertex3f(100.0, 100.0, 0.0);
+        glColor3f(1.0, 1.0, 1.0); glVertex3f(0.0, 100.0, 0.0);
+    glEnd();
+ 
+    GL::SDL_GL_SwapBuffers();
+}
+
+fn setup() {
+    glClearColor(0.5, 1.0, 1.0, 1.0);
+    glClearDepth(1.0f);
+     
+    glViewport(0, 0, 640, 480);
+     
+    glMatrixMode(GL_PROJECTION);
+    glLoadIdentity();
+     
+    glOrtho(0.0, 800.0, 600.0, 0.0, 1.0, -1.0);
+     
+    glMatrixMode(GL_MODELVIEW);
+     
+    glEnable(GL_TEXTURE_2D);
+     
+    glLoadIdentity();
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.