Skip to content

Commit

Permalink
refactor and simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
glowcoil committed May 17, 2020
1 parent 1a41e73 commit a7ba203
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 655 deletions.
28 changes: 3 additions & 25 deletions examples/example.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ochre::{Color, Graphics, Path, Vec2};
use ochre::{Color, Path, Vec2, Renderer};

fn main() {
let mut events_loop = glutin::EventsLoop::new();
Expand All @@ -12,33 +12,11 @@ fn main() {

gl::load_with(|symbol| context.get_proc_address(symbol) as *const _);

let mut graphics = Graphics::new(800.0, 600.0);
let mut renderer = Renderer::new();

let mut running = true;
while running {
graphics.clear(Color::rgba(0.1, 0.15, 0.2, 1.0));
graphics.begin_frame();
graphics.set_color(Color::rgba(1.0, 1.0, 1.0, 1.0));
let rect = Path::rect_fill(Vec2::new(0.0, 0.0), Vec2::new(10.0, 10.0));
graphics.draw_mesh(&rect);
graphics.set_color(Color::rgba(0.5, 0.25, 1.0, 0.75));
let mut path = Path::new();
path.move_to(Vec2::new(400.0, 300.0))
.quadratic_to(Vec2::new(500.0, 200.0), Vec2::new(400.0, 100.0))
.cubic_to(Vec2::new(350.0, 150.0), Vec2::new(100.0, 250.0), Vec2::new(400.0, 300.0));
graphics.draw_mesh(&path.fill_convex());
graphics.set_color(Color::rgba(0.0, 0.5, 1.0, 0.5));
let mut path = Path::new();
path.move_to(Vec2::new(600.0, 300.0))
.arc_to(50.0, Vec2::new(600.0, 400.0))
.arc_to(50.0, Vec2::new(600.0, 300.0));
graphics.draw_mesh(&path.fill_convex());
graphics.set_color(Color::rgba(0.8, 0.5, 0.0, 1.0));
let round_rect = Path::round_rect_fill(Vec2::new(100.0, 10.0), Vec2::new(100.0, 100.0), 20.0);
graphics.draw_mesh(&round_rect);
graphics.end_frame();
graphics.draw_texture_test();
graphics.draw_trapezoids_test();
renderer.clear([1.0, 1.0, 1.0, 1.0]);

context.swap_buffers().unwrap();

Expand Down
144 changes: 0 additions & 144 deletions src/graphics.rs

This file was deleted.

17 changes: 15 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
pub mod geom;
pub mod graphics;
pub mod path;
pub mod render;

pub use geom::*;
pub use graphics::*;
pub use path::*;
pub use render::*;

#[derive(Copy, Clone, Debug)]
pub struct Color {
pub r: f32, pub g: f32, pub b: f32, pub a: f32,
}

impl Color {
pub fn new(r: f32, g: f32, b: f32, a: f32) -> Color {
Color { r, g, b, a }
}

pub fn premultiply(r: f32, g: f32, b: f32, a: f32) -> Color {
Color { r: a * r, g: a * g, b: a * b, a }
}
}
Loading

0 comments on commit a7ba203

Please sign in to comment.