aboutsummaryrefslogtreecommitdiffstats
path: root/examples/support
diff options
context:
space:
mode:
authorTomaka17 <pierre.krieger1708@gmail.com>2014-09-12 10:20:15 +0200
committerTomaka17 <pierre.krieger1708@gmail.com>2014-09-12 10:20:15 +0200
commit451b754e79373fc9c9d43d3127f4caa41408ee68 (patch)
treebdf50e5ba838346f55b2a7ae089206233a8730d4 /examples/support
parent3cad622ee846600bbb5bd38992113198fd9737d7 (diff)
downloadglutin-451b754e79373fc9c9d43d3127f4caa41408ee68.tar.gz
glutin-451b754e79373fc9c9d43d3127f4caa41408ee68.zip
Add triangle to example
Diffstat (limited to 'examples/support')
-rw-r--r--examples/support/mod.rs46
1 files changed, 45 insertions, 1 deletions
diff --git a/examples/support/mod.rs b/examples/support/mod.rs
index 4495f17..1dddfc3 100644
--- a/examples/support/mod.rs
+++ b/examples/support/mod.rs
@@ -3,8 +3,15 @@ extern crate gl_generator;
use gl_init;
+#[cfg(not(target_os = "android"))]
mod gl {
- generate_gl_bindings!("gl", "core", "4.5", "struct")
+ generate_gl_bindings!("gl", "core", "1.1", "struct")
+}
+
+#[cfg(target_os = "android")]
+mod gl {
+ pub use self::Gles1 as Gl;
+ generate_gl_bindings!("gles1", "core", "1.1", "struct")
}
pub struct Context {
@@ -25,8 +32,45 @@ pub fn load(window: &gl_init::Window) -> Context {
}
impl Context {
+ #[cfg(not(target_os = "android"))]
pub fn draw_frame(&self, color: (f32, f32, f32, f32)) {
self.gl.ClearColor(color.0, color.1, color.2, color.3);
self.gl.Clear(gl::COLOR_BUFFER_BIT);
+
+ self.gl.Begin(gl::TRIANGLES);
+ self.gl.Color3f(1.0, 0.0, 0.0);
+ self.gl.Vertex2f(-0.5, -0.5);
+ self.gl.Color3f(0.0, 1.0, 0.0);
+ self.gl.Vertex2f(0.0, 0.5);
+ self.gl.Color3f(0.0, 0.0, 1.0);
+ self.gl.Vertex2f(0.5, -0.5);
+ self.gl.End();
+ }
+
+ #[cfg(target_os = "android")]
+ pub fn draw_frame(&self, color: (f32, f32, f32, f32)) {
+ self.gl.ClearColor(color.0, color.1, color.2, color.3);
+ self.gl.Clear(gl::COLOR_BUFFER_BIT);
+
+ let vertex_data: [f32, ..15] = [
+ -0.5, -0.5, 1.0, 0.0, 0.0,
+ 0.0, 0.5, 0.0, 1.0, 0.0,
+ 0.5, -0.5, 0.0, 0.0, 1.0
+ ];
+
+ self.gl.EnableClientState(gl::VERTEX_ARRAY);
+ self.gl.EnableClientState(gl::COLOR_ARRAY);
+
+ unsafe {
+ use std::mem;
+ self.gl.VertexPointer(2, gl::FLOAT, (mem::size_of::<f32>() * 5) as i32,
+ mem::transmute(vertex_data.as_slice().as_ptr()));
+ self.gl.ColorPointer(3, gl::FLOAT, (mem::size_of::<f32>() * 5) as i32,
+ mem::transmute(vertex_data.as_slice().as_ptr().offset(2)));
+ }
+
+ self.gl.DrawArrays(gl::TRIANGLES, 0, 3);
+ self.gl.DisableClientState(gl::VERTEX_ARRAY);
+ self.gl.DisableClientState(gl::COLOR_ARRAY);
}
}