adding in a simple line algorithm
This commit is contained in:
parent
5ca212986e
commit
0c86164b08
|
@ -1,6 +1,7 @@
|
|||
#![allow(dead_code, unused)]
|
||||
|
||||
use able_graphics_library::{AglApi, FrameBuffer, Point, HEIGHT, RGBA, WIDTH};
|
||||
use mini_gl_fb::glutin::platform::unix::x11::ffi::XK_R10;
|
||||
|
||||
#[derive(Clone, Debug, Copy)]
|
||||
pub struct GraphicsRenderer {
|
||||
|
@ -23,7 +24,25 @@ impl GraphicsRenderer {
|
|||
|
||||
impl AglApi for GraphicsRenderer {
|
||||
fn put_line(&mut self, coords_start: Point, coords_end: Point, thickness: u32, color: RGBA) {
|
||||
todo!();
|
||||
// Wikipedia's naive line drawing algorithm
|
||||
let x1 = coords_start.x;
|
||||
let y1 = coords_start.y;
|
||||
|
||||
let x2 = coords_end.x;
|
||||
let y2 = coords_end.y;
|
||||
|
||||
let dx = x2 - x1;
|
||||
let dy = y2 - y1;
|
||||
|
||||
for x in x1..x2 {
|
||||
let y = y1 + dy * (x - x1) / dx;
|
||||
|
||||
let coordinates = x + (WIDTH as u16) * y;
|
||||
|
||||
self.buff[coordinates as usize] = color;
|
||||
}
|
||||
|
||||
// todo!();
|
||||
}
|
||||
fn put_rect(&mut self, coords_start: Point, coords_end: Point, color: RGBA) {
|
||||
todo!();
|
||||
|
|
43
src/main.rs
43
src/main.rs
|
@ -1,6 +1,10 @@
|
|||
use able_graphics_library::{AglApi, HEIGHT, WIDTH};
|
||||
use able_graphics_library::{Point, RGBA};
|
||||
use graphics_api_impl::GraphicsRenderer;
|
||||
use mini_gl_fb::{
|
||||
config,
|
||||
glutin::{dpi::LogicalSize, event_loop::EventLoop},
|
||||
};
|
||||
mod graphics_api_impl;
|
||||
|
||||
extern crate mini_gl_fb;
|
||||
|
@ -9,12 +13,25 @@ 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);
|
||||
// mini_gl_fb::gotta_go_fast( );
|
||||
|
||||
let mut event_loop = EventLoop::new();
|
||||
|
||||
let mut fb = mini_gl_fb::get_fancy(
|
||||
config! {
|
||||
window_title: String::from("AGL"),
|
||||
window_size: LogicalSize::new(WIDTH as f64, HEIGHT as f64),
|
||||
buffer_size: Some(LogicalSize::new(WIDTH as u32, HEIGHT as u32)),
|
||||
resizable: true
|
||||
},
|
||||
&event_loop,
|
||||
);
|
||||
|
||||
// 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,
|
||||
|
@ -41,6 +58,30 @@ fn main() {
|
|||
a: 123,
|
||||
},
|
||||
);
|
||||
}
|
||||
xyz.put_line(
|
||||
Point { x: 3, y: 30 },
|
||||
Point { x: 324, y: 50 },
|
||||
1,
|
||||
RGBA {
|
||||
r: 0,
|
||||
g: 0,
|
||||
b: 0,
|
||||
a: 0,
|
||||
},
|
||||
);
|
||||
|
||||
xyz.put_line(
|
||||
Point { x: 0, y: 0 },
|
||||
Point { x: 300, y: 200 },
|
||||
1,
|
||||
RGBA {
|
||||
r: 0,
|
||||
g: 0,
|
||||
b: 0,
|
||||
a: 0,
|
||||
},
|
||||
);
|
||||
|
||||
// update pixels
|
||||
for x in 0..600 * 400 {
|
||||
|
|
Reference in a new issue