A simple example implementation of AGL
This commit is contained in:
commit
2a9841df5e
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
/target
|
1364
Cargo.lock
generated
Normal file
1364
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
10
Cargo.toml
Normal file
10
Cargo.toml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
[package]
|
||||||
|
name = "agl_simple_impl"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
mini_gl_fb = "0.9.0"
|
||||||
|
able_graphics_library = {git = "https://git.ablecorp.us:443/Able/able_graphics_library.git"}
|
65
src/graphics_api_impl.rs
Normal file
65
src/graphics_api_impl.rs
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
#![allow(dead_code, unused)]
|
||||||
|
|
||||||
|
use able_graphics_library::{AglApi, FrameBuffer, Point, HEIGHT, RGBA, WIDTH};
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Copy)]
|
||||||
|
pub struct GraphicsRenderer {
|
||||||
|
pub buff: FrameBuffer,
|
||||||
|
}
|
||||||
|
impl GraphicsRenderer {
|
||||||
|
pub fn new() -> GraphicsRenderer {
|
||||||
|
let rgba = RGBA {
|
||||||
|
r: 0,
|
||||||
|
g: 0,
|
||||||
|
b: 0,
|
||||||
|
a: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
let buffer = [rgba; WIDTH * HEIGHT];
|
||||||
|
|
||||||
|
Self { buff: buffer }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AglApi for GraphicsRenderer {
|
||||||
|
fn put_line(&mut self, coords_start: Point, coords_end: Point, thickness: u32, color: RGBA) {
|
||||||
|
todo!();
|
||||||
|
}
|
||||||
|
fn put_rect(&mut self, coords_start: Point, coords_end: Point, color: RGBA) {
|
||||||
|
todo!();
|
||||||
|
}
|
||||||
|
fn put_circle(&mut self, coords: Point, radius: u32) {
|
||||||
|
todo!();
|
||||||
|
}
|
||||||
|
fn put_pixel(&mut self, coords: Point, color: RGBA) {
|
||||||
|
let coordinates = coords.x + (WIDTH as u16).wrapping_mul(coords.y);
|
||||||
|
|
||||||
|
self.buff[coordinates as usize] = color;
|
||||||
|
}
|
||||||
|
fn put_triangle(
|
||||||
|
&mut self,
|
||||||
|
coords_1: Point,
|
||||||
|
coords_2: Point,
|
||||||
|
coords_3: Point,
|
||||||
|
thickness: u32,
|
||||||
|
color: RGBA,
|
||||||
|
) {
|
||||||
|
todo!();
|
||||||
|
}
|
||||||
|
fn paint_cursor(&mut self, coords: Point) {
|
||||||
|
todo!();
|
||||||
|
}
|
||||||
|
fn hide_cursor() {
|
||||||
|
todo!();
|
||||||
|
}
|
||||||
|
fn show_cursor() {
|
||||||
|
todo!();
|
||||||
|
}
|
||||||
|
/// Actually move the double buffer to the single buffer and "update" the screen
|
||||||
|
fn draw(&mut self) {}
|
||||||
|
fn clear(&mut self, color: RGBA) {
|
||||||
|
for x in 0..600 * 400 {
|
||||||
|
self.buff[x as usize] = color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
53
src/main.rs
Normal file
53
src/main.rs
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
use able_graphics_library::{AglApi, HEIGHT, WIDTH};
|
||||||
|
use able_graphics_library::{Point, RGBA};
|
||||||
|
use graphics_api_impl::GraphicsRenderer;
|
||||||
|
mod graphics_api_impl;
|
||||||
|
|
||||||
|
extern crate mini_gl_fb;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mut xyz = GraphicsRenderer::new();
|
||||||
|
|
||||||
|
// Create the event loop and framebuffer
|
||||||
|
let (mut event_loop, mut fb) = mini_gl_fb::gotta_go_fast("AGL", WIDTH as f64, HEIGHT as f64);
|
||||||
|
|
||||||
|
// Fill the buffer with something
|
||||||
|
let mut buffer = vec![[0, 0, 0, 0]; WIDTH * HEIGHT];
|
||||||
|
|
||||||
|
// Use cool fancy drawing api
|
||||||
|
xyz.clear(RGBA {
|
||||||
|
r: 255,
|
||||||
|
g: 255,
|
||||||
|
b: 255,
|
||||||
|
a: 255,
|
||||||
|
});
|
||||||
|
|
||||||
|
xyz.put_pixel(
|
||||||
|
Point { x: 34, y: 43 },
|
||||||
|
RGBA {
|
||||||
|
r: 123,
|
||||||
|
g: 123,
|
||||||
|
b: 123,
|
||||||
|
a: 123,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
xyz.put_pixel(
|
||||||
|
Point { x: 346, y: 199 },
|
||||||
|
RGBA {
|
||||||
|
r: 255,
|
||||||
|
g: 0,
|
||||||
|
b: 0,
|
||||||
|
a: 123,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
// update pixels
|
||||||
|
for x in 0..600 * 400 {
|
||||||
|
buffer[x] = [xyz.buff[x].r, xyz.buff[x].g, xyz.buff[x].b, xyz.buff[x].a]
|
||||||
|
}
|
||||||
|
|
||||||
|
fb.update_buffer(&buffer);
|
||||||
|
fb.persist(&mut event_loop);
|
||||||
|
// Show the window until the user decides to quit (close button, or Esc)
|
||||||
|
}
|
Reference in a new issue