aboutsummaryrefslogtreecommitdiff
path: root/examples/render-quad/src
diff options
context:
space:
mode:
Diffstat (limited to 'examples/render-quad/src')
-rw-r--r--examples/render-quad/src/main.rs37
1 files changed, 31 insertions, 6 deletions
diff --git a/examples/render-quad/src/main.rs b/examples/render-quad/src/main.rs
index 9cc7310..8d6d439 100644
--- a/examples/render-quad/src/main.rs
+++ b/examples/render-quad/src/main.rs
@@ -21,9 +21,11 @@ extern crate stockton_render;
extern crate winit;
extern crate simple_logger;
extern crate rand;
+extern crate image;
use stockton_render::draw::{RenderingContext, UVPoint};
use stockton_types::{Vector2, Vector3};
+use image::load_from_memory;
use winit::{
event::{Event, WindowEvent},
@@ -36,19 +38,40 @@ fn main() {
simple_logger::init().unwrap();
// Create the renderer.
-
let event_loop = EventLoop::new();
let window = WindowBuilder::new().build(&event_loop).unwrap();
let mut ctx = RenderingContext::new(&window).unwrap();
- ctx.vert_buffer[0] = UVPoint(Vector2::new(-0.5, -0.5), Vector3::new(1.0, 0.0, 0.0), Vector2::new(0.0, 0.0));
- ctx.vert_buffer[1] = UVPoint(Vector2::new(0.5, -0.5), Vector3::new(0.0, 1.0, 0.0), Vector2::new(1.0, 0.0));
- ctx.vert_buffer[2] = UVPoint(Vector2::new(0.5, 0.5), Vector3::new(0.0, 0.0, 1.0), Vector2::new(1.0, 1.0));
- ctx.vert_buffer[3] = UVPoint(Vector2::new(-0.5, 0.5), Vector3::new(1.0, 0.0, 1.0), Vector2::new(0.0, 1.0));
+ // Load 2 test textures
+ ctx.add_texture(
+ load_from_memory(include_bytes!("../data/test1.png"))
+ .expect("Couldn't load test texture 1")
+ .into_rgba())
+ .unwrap();
+ ctx.add_texture(
+ load_from_memory(include_bytes!("../data/test2.png"))
+ .expect("Couldn't load test texture 2")
+ .into_rgba())
+ .unwrap();
+
+ // First quad with test1
+ ctx.vert_buffer[0] = UVPoint(Vector2::new(-1.0, -1.0), Vector3::new(1.0, 0.0, 0.0), Vector2::new(0.0, 0.0), 0);
+ ctx.vert_buffer[1] = UVPoint(Vector2::new(0.0, -1.0), Vector3::new(0.0, 1.0, 0.0), Vector2::new(1.0, 0.0), 0);
+ ctx.vert_buffer[2] = UVPoint(Vector2::new(0.0, 0.0), Vector3::new(0.0, 0.0, 1.0), Vector2::new(1.0, 1.0), 0);
+ ctx.vert_buffer[3] = UVPoint(Vector2::new(-1.0, 0.0), Vector3::new(1.0, 0.0, 1.0), Vector2::new(0.0, 1.0), 0);
ctx.index_buffer[0] = (0, 1, 2);
ctx.index_buffer[1] = (0, 2, 3);
+ // Second quad with test2
+ ctx.vert_buffer[4] = UVPoint(Vector2::new(0.0, -1.0), Vector3::new(1.0, 0.0, 0.0), Vector2::new(0.0, 0.0), 1);
+ ctx.vert_buffer[5] = UVPoint(Vector2::new(1.0, -1.0), Vector3::new(0.0, 1.0, 0.0), Vector2::new(1.0, 0.0), 1);
+ ctx.vert_buffer[6] = UVPoint(Vector2::new(1.0, 0.0), Vector3::new(0.0, 0.0, 1.0), Vector2::new(1.0, 1.0), 1);
+ ctx.vert_buffer[7] = UVPoint(Vector2::new(0.0, 0.0), Vector3::new(1.0, 0.0, 1.0), Vector2::new(0.0, 1.0), 1);
+
+ ctx.index_buffer[2] = (4, 5, 6);
+ ctx.index_buffer[3] = (4, 7, 6);
+
event_loop.run(move |event, _, flow| {
*flow = ControlFlow::Poll;
@@ -72,7 +95,9 @@ fn main() {
let mouse_x: f32 = ((position.x / win_size.width as f64) * 2.0 - 1.0) as f32;
let mouse_y: f32 = ((position.y / win_size.height as f64) * 2.0 - 1.0) as f32;
- ctx.vert_buffer[0] = UVPoint(Vector2::new(mouse_x, mouse_y), Vector3::new(1.0, 0.0, 0.0), Vector2::new(0.0, 0.0));
+ // Move a vertex from each quad
+ ctx.vert_buffer[2] = UVPoint(Vector2::new(mouse_x, mouse_y), Vector3::new(1.0, 0.0, 0.0), Vector2::new(1.0, 1.0), 0);
+ ctx.vert_buffer[7] = UVPoint(Vector2::new(mouse_x, mouse_y), Vector3::new(1.0, 0.0, 0.0), Vector2::new(0.0, 1.0), 1);
}
Event::MainEventsCleared => {