aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authortomaka <pierre.krieger1708@gmail.com>2015-08-07 22:55:54 +0200
committertomaka <pierre.krieger1708@gmail.com>2015-08-07 22:55:54 +0200
commite90f377b9fbab23a140029e71ef57933b266c473 (patch)
treed2bed381d044db5412dbf965c8a4ae17585ff391 /examples
parent90e62083d686ed9c878beb348e9b54853242eab0 (diff)
parent9261408cc8d2ba54ddea0c9ddd43560e03d45bdc (diff)
downloadglutin-e90f377b9fbab23a140029e71ef57933b266c473.tar.gz
glutin-e90f377b9fbab23a140029e71ef57933b266c473.zip
Merge pull request #565 from tomaka/correct-example
Use modern GL code for the examples
Diffstat (limited to 'examples')
-rw-r--r--examples/cursor.rs2
-rw-r--r--examples/fullscreen.rs1
-rw-r--r--examples/grabbing.rs2
-rw-r--r--examples/multiwindow.rs6
-rw-r--r--examples/support/mod.rs104
-rw-r--r--examples/transparent.rs3
-rw-r--r--examples/window.rs2
7 files changed, 71 insertions, 49 deletions
diff --git a/examples/cursor.rs b/examples/cursor.rs
index d15deff..b0ec16a 100644
--- a/examples/cursor.rs
+++ b/examples/cursor.rs
@@ -17,7 +17,7 @@ fn main() { println!("This example requires glutin to be compiled with the `wind
#[cfg(feature = "window")]
fn main() {
- let window = glutin::WindowBuilder::new().with_gl_profile(glutin::GlProfile::Compatibility).build().unwrap();
+ let window = glutin::WindowBuilder::new().build().unwrap();
window.set_title("A fantastic window!");
unsafe { window.make_current() };
diff --git a/examples/fullscreen.rs b/examples/fullscreen.rs
index 707fd7d..de4c449 100644
--- a/examples/fullscreen.rs
+++ b/examples/fullscreen.rs
@@ -35,7 +35,6 @@ fn main() {
};
let window = glutin::WindowBuilder::new()
- .with_gl_profile(glutin::GlProfile::Compatibility)
.with_title("Hello world!".to_string())
.with_fullscreen(monitor)
.build()
diff --git a/examples/grabbing.rs b/examples/grabbing.rs
index a0a8fda..0572686 100644
--- a/examples/grabbing.rs
+++ b/examples/grabbing.rs
@@ -16,7 +16,7 @@ fn main() { println!("This example requires glutin to be compiled with the `wind
#[cfg(feature = "window")]
fn main() {
- let window = glutin::WindowBuilder::new().with_gl_profile(glutin::GlProfile::Compatibility).build().unwrap();
+ let window = glutin::WindowBuilder::new().build().unwrap();
window.set_title("glutin - Cursor grabbing test");
unsafe { window.make_current() };
diff --git a/examples/multiwindow.rs b/examples/multiwindow.rs
index 074fe14..18299f8 100644
--- a/examples/multiwindow.rs
+++ b/examples/multiwindow.rs
@@ -16,9 +16,9 @@ fn main() { println!("This example requires glutin to be compiled with the `wind
#[cfg(feature = "window")]
fn main() {
- let window1 = glutin::WindowBuilder::new().with_gl_profile(glutin::GlProfile::Compatibility).build().unwrap();
- let window2 = glutin::WindowBuilder::new().with_gl_profile(glutin::GlProfile::Compatibility).build().unwrap();
- let window3 = glutin::WindowBuilder::new().with_gl_profile(glutin::GlProfile::Compatibility).build().unwrap();
+ let window1 = glutin::WindowBuilder::new().build().unwrap();
+ let window2 = glutin::WindowBuilder::new().build().unwrap();
+ let window3 = glutin::WindowBuilder::new().build().unwrap();
let t1 = thread::spawn(move || {
run(window1, (0.0, 1.0, 0.0, 1.0));
diff --git a/examples/support/mod.rs b/examples/support/mod.rs
index 01eeb7b..7e9aa4f 100644
--- a/examples/support/mod.rs
+++ b/examples/support/mod.rs
@@ -1,19 +1,15 @@
#![cfg(feature = "window")]
use std::ffi::CStr;
+use std::mem;
+use std::ptr;
use glutin;
-#[cfg(not(target_os = "android"))]
mod gl {
+ pub use self::Gles2 as Gl;
include!(concat!(env!("OUT_DIR"), "/test_gl_bindings.rs"));
}
-#[cfg(target_os = "android")]
-mod gl {
- pub use self::Gles1 as Gl;
- include!(concat!(env!("OUT_DIR"), "/test_gles1_bindings.rs"));
-}
-
pub struct Context {
gl: gl::Gl
}
@@ -28,30 +24,47 @@ pub fn load(window: &glutin::Window) -> Context {
println!("OpenGL version {}", version);
+ unsafe {
+ let vs = gl.CreateShader(gl::VERTEX_SHADER);
+ gl.ShaderSource(vs, 1, [VS_SRC.as_ptr() as *const i8].as_ptr(), ptr::null());
+ gl.CompileShader(vs);
+
+ let fs = gl.CreateShader(gl::FRAGMENT_SHADER);
+ gl.ShaderSource(fs, 1, [FS_SRC.as_ptr() as *const i8].as_ptr(), ptr::null());
+ gl.CompileShader(fs);
+
+ let program = gl.CreateProgram();
+ gl.AttachShader(program, vs);
+ gl.AttachShader(program, fs);
+ gl.LinkProgram(program);
+ gl.UseProgram(program);
+
+ let mut vb = mem::uninitialized();
+ gl.GenBuffers(1, &mut vb);
+ gl.BindBuffer(gl::ARRAY_BUFFER, vb);
+ gl.BufferData(gl::ARRAY_BUFFER,
+ (VERTEX_DATA.len() * mem::size_of::<f32>()) as gl::types::GLsizeiptr,
+ VERTEX_DATA.as_ptr() as *const _, gl::STATIC_DRAW);
+
+ /*let mut vao = mem::uninitialized();
+ gl.GenVertexArrays(1, &mut vao);
+ gl.BindVertexArray(vao);*/
+ let pos_attrib = gl.GetAttribLocation(program, b"position\0".as_ptr() as *const _);
+ let color_attrib = gl.GetAttribLocation(program, b"color\0".as_ptr() as *const _);
+ gl.VertexAttribPointer(pos_attrib as gl::types::GLuint, 2, gl::FLOAT, 0,
+ 5 * mem::size_of::<f32>() as gl::types::GLsizei,
+ ptr::null());
+ gl.VertexAttribPointer(color_attrib as gl::types::GLuint, 3, gl::FLOAT, 0,
+ 5 * mem::size_of::<f32>() as gl::types::GLsizei,
+ (2 * mem::size_of::<f32>()) as *const () as *const _);
+ gl.EnableVertexAttribArray(pos_attrib as gl::types::GLuint);
+ gl.EnableVertexAttribArray(color_attrib as gl::types::GLuint);
+ }
+
Context { gl: gl }
}
impl Context {
- #[cfg(not(target_os = "android"))]
- pub fn draw_frame(&self, color: (f32, f32, f32, f32)) {
- unsafe {
- 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();
-
- self.gl.Flush();
- }
- }
-
- #[cfg(target_os = "android")]
pub fn draw_frame(&self, color: (f32, f32, f32, f32)) {
use std::mem;
@@ -59,26 +72,37 @@ impl Context {
self.gl.ClearColor(color.0, color.1, color.2, color.3);
self.gl.Clear(gl::COLOR_BUFFER_BIT);
- self.gl.EnableClientState(gl::VERTEX_ARRAY);
- self.gl.EnableClientState(gl::COLOR_ARRAY);
-
- self.gl.VertexPointer(2, gl::FLOAT, (mem::size_of::<f32>() * 5) as i32,
- mem::transmute(VERTEX_DATA.as_ptr()));
- self.gl.ColorPointer(3, gl::FLOAT, (mem::size_of::<f32>() * 5) as i32,
- mem::transmute(VERTEX_DATA.as_ptr().offset(2)));
-
self.gl.DrawArrays(gl::TRIANGLES, 0, 3);
- self.gl.DisableClientState(gl::VERTEX_ARRAY);
- self.gl.DisableClientState(gl::COLOR_ARRAY);
-
- self.gl.Flush();
}
}
}
-#[cfg(target_os = "android")]
static 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
];
+
+const VS_SRC: &'static [u8] = b"
+#version 100
+
+lowp attribute vec2 position;
+lowp attribute vec3 color;
+
+lowp varying vec3 v_color;
+
+void main() {
+ gl_Position = vec4(position, 0.0, 1.0);
+ v_color = color;
+}
+\0";
+
+const FS_SRC: &'static [u8] = b"
+#version 100
+
+lowp varying vec3 v_color;
+
+void main() {
+ gl_FragColor = vec4(v_color, 1.0);
+}
+\0";
diff --git a/examples/transparent.rs b/examples/transparent.rs
index fa6a8de..7635b3f 100644
--- a/examples/transparent.rs
+++ b/examples/transparent.rs
@@ -19,8 +19,7 @@ fn resize_callback(width: u32, height: u32) {
#[cfg(feature = "window")]
fn main() {
- let mut window = glutin::WindowBuilder::new().with_gl_profile(glutin::GlProfile::Compatibility)
- .with_decorations(false)
+ let mut window = glutin::WindowBuilder::new().with_decorations(false)
.with_transparency(true)
.build().unwrap();
window.set_title("A fantastic window!");
diff --git a/examples/window.rs b/examples/window.rs
index f686a51..8204b95 100644
--- a/examples/window.rs
+++ b/examples/window.rs
@@ -19,7 +19,7 @@ fn resize_callback(width: u32, height: u32) {
#[cfg(feature = "window")]
fn main() {
- let mut window = glutin::WindowBuilder::new().with_gl_profile(glutin::GlProfile::Compatibility).build().unwrap();
+ let mut window = glutin::WindowBuilder::new().build().unwrap();
window.set_title("A fantastic window!");
window.set_window_resize_callback(Some(resize_callback as fn(u32, u32)));
unsafe { window.make_current() };