forked from AGL/AGL_Simple_Impl
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!();
|
||||
|
|
75
src/main.rs
75
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,36 +13,73 @@ 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,
|
||||
b: 255,
|
||||
a: 255,
|
||||
});
|
||||
{
|
||||
xyz.clear(RGBA {
|
||||
r: 255,
|
||||
g: 255,
|
||||
b: 255,
|
||||
a: 255,
|
||||
});
|
||||
|
||||
xyz.put_pixel(
|
||||
Point { x: 34, y: 43 },
|
||||
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,
|
||||
},
|
||||
);
|
||||
}
|
||||
xyz.put_line(
|
||||
Point { x: 3, y: 30 },
|
||||
Point { x: 324, y: 50 },
|
||||
1,
|
||||
RGBA {
|
||||
r: 123,
|
||||
g: 123,
|
||||
b: 123,
|
||||
a: 123,
|
||||
r: 0,
|
||||
g: 0,
|
||||
b: 0,
|
||||
a: 0,
|
||||
},
|
||||
);
|
||||
|
||||
xyz.put_pixel(
|
||||
Point { x: 346, y: 199 },
|
||||
xyz.put_line(
|
||||
Point { x: 0, y: 0 },
|
||||
Point { x: 300, y: 200 },
|
||||
1,
|
||||
RGBA {
|
||||
r: 255,
|
||||
r: 0,
|
||||
g: 0,
|
||||
b: 0,
|
||||
a: 123,
|
||||
a: 0,
|
||||
},
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in a new issue