You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Trac3r-rust/src/main.rs

149 lines
4.2 KiB

6 years ago
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_mut)]
6 years ago
6 years ago
extern crate cgmath;
extern crate image;
6 years ago
extern crate nalgebra as na;
extern crate rand;
6 years ago
extern crate sfml;
extern crate time;
use sfml::graphics::*;
6 years ago
use sfml::graphics::{
Color, RenderTarget, RenderWindow,
};
use sfml::system::*;
6 years ago
use sfml::window::{Event, Key, Style};
6 years ago
use sfml::window::mouse::*;
use sfml::window::mouse;
6 years ago
use vulkano::sync;
use std::sync::Arc;
use std::{fs, mem, iter, ptr};
use std::path::PathBuf;
use std::result;
6 years ago
use crate::input::Input;
use crate::slider::Slider;
6 years ago
use crate::timer::Timer;
use na::DimAdd;
use std::time::{SystemTime, Duration};
use shade_runner as sr;
use std::ffi::CStr;
use std::ptr::write;
use vulkano::buffer::{BufferUsage, CpuAccessibleBuffer, DeviceLocalBuffer, ImmutableBuffer, BufferAccess};
use vulkano::command_buffer::AutoCommandBufferBuilder;
use vulkano::descriptor::descriptor_set::PersistentDescriptorSet;
use vulkano::device::{Device, DeviceExtensions};
use vulkano::instance::{Instance, InstanceExtensions, PhysicalDevice};
use vulkano::pipeline::ComputePipeline;
use vulkano::sync::GpuFuture;
6 years ago
6 years ago
mod slider;
mod timer;
mod input;
mod vkprocessor;
fn main() {
let instance = Instance::new(None, &InstanceExtensions::none(), None).unwrap();
let mut processor = vkprocessor::VkProcessor::new(&instance);
6 years ago
processor.compile_kernel(String::from("simple-edge.compute"));
processor.load_buffers(String::from("test2.png"));
processor.run_kernel();
6 years ago
processor.read_image();
processor.save_image();
6 years ago
let mut window = RenderWindow::new(
(900, 900),
6 years ago
"Custom drawable",
Style::CLOSE,
&Default::default(),
);
6 years ago
let mut timer = Timer::new();
let mut input = Input::new();
let font = Font::from_file("resources/fonts/sansation.ttf").unwrap();
let xy = processor.xy;
let mut bg_texture = Texture::new(xy.0, xy.1).unwrap();
6 years ago
bg_texture.update_from_pixels(processor.read_image().as_slice(), xy.0, xy.1, 0, 0);
let mut background_sprite = Sprite::with_texture(&bg_texture);
background_sprite.set_position((0., 0.));
let mut slider = Slider::new(40.0, None);
let mut selected_colors = Vec::new();
selected_colors.push(RectangleShape::with_size(Vector2f::new(30.0, 30.0)));
let step_size: f32 = 0.005;
let mut elapsed_time: f32;
let mut delta_time: f32;
6 years ago
let mut accumulator_time: f32 = 0.0;
let mut current_time: f32 = timer.elap_time();
6 years ago
6 years ago
let mut mouse_xy = Vector2i::new(0,0);
6 years ago
while window.is_open() {
6 years ago
6 years ago
while let Some(event) = window.poll_event() {
match event {
6 years ago
Event::Closed => return,
Event::KeyPressed { code, .. } => {
if code == Key::Escape {
return;
}
},
Event::MouseButtonPressed { button, x, y } => {
6 years ago
mouse_xy = mouse::desktop_position();
},
Event::MouseWheelScrolled { wheel, delta, x, y } => {
if delta > 0.0 {
6 years ago
background_sprite.set_scale(background_sprite.get_scale()*Vector2f::new(1.1,1.1));
} else {
6 years ago
background_sprite.set_scale(background_sprite.get_scale()*Vector2f::new(0.9,0.9));
}
},
6 years ago
_ => {}
}
6 years ago
input.ingest(&event)
}
if input.is_mousebutton_held(Button::Left) {
6 years ago
let delta = mouse_xy - mouse::desktop_position();
mouse_xy = mouse::desktop_position();
println!("{:?}", delta);
background_sprite.set_position(
background_sprite.position() - Vector2f::new(delta.x as f32, delta.y as f32)
);
}
6 years ago
6 years ago
elapsed_time = timer.elap_time();
6 years ago
delta_time = elapsed_time - current_time;
current_time = elapsed_time;
if delta_time > 0.02 {
delta_time = 0.02;
6 years ago
}
6 years ago
accumulator_time += delta_time;
6 years ago
6 years ago
while (accumulator_time - step_size) >= step_size {
accumulator_time -= step_size;
}
6 years ago
6 years ago
window.clear(&Color::BLACK);
7 years ago
window.draw(&background_sprite);
window.draw(&slider);
6 years ago
window.display();
6 years ago
}
}