chore: renamed the resources directory to res
4
.gitignore
vendored
|
@ -1,2 +1,4 @@
|
|||
/Cargo.lock
|
||||
/target
|
||||
/build.rs
|
||||
/build.rs
|
||||
/src/main.rs
|
||||
|
|
64
README.md
|
@ -3,9 +3,9 @@ a free and open source games framework
|
|||
|
||||
> [!WARNING]
|
||||
> This project is in early development and is not yet ready for use.
|
||||
>
|
||||
>
|
||||
> It could be potentially used to make something very basic in a very hacky way, but it is not a good experience.
|
||||
>
|
||||
>
|
||||
> Installation is manual as of right now but if it reaches an acceptable state I will publish the crate on crates.
|
||||
>
|
||||
> There is a plan for a project creation tool that will automate the project setup process.
|
||||
|
@ -20,7 +20,7 @@ project
|
|||
│ build.rs
|
||||
│ crates
|
||||
│ └── comet
|
||||
│ resources
|
||||
│ res
|
||||
│ └── shaders
|
||||
│ └── textures
|
||||
│ └── sounds
|
||||
|
@ -29,15 +29,15 @@ project
|
|||
```
|
||||
|
||||
```toml
|
||||
# Cargo.toml
|
||||
# Cargo.toml
|
||||
# ...
|
||||
[dependencies]
|
||||
comet = { path = "path/of/the/comet/crate" }
|
||||
comet = { path = "path/of/the/comet/crate" }
|
||||
# ...
|
||||
```
|
||||
|
||||
```rust
|
||||
// main.rs example
|
||||
// main.rs example
|
||||
use comet::prelude::*;
|
||||
|
||||
struct GameState {}
|
||||
|
@ -50,17 +50,17 @@ impl GameState {
|
|||
|
||||
// This function will be called once before the event loop starts
|
||||
fn setup(app: &mut App, renderer: &mut Renderer2D) {}
|
||||
// This function will be called every tick
|
||||
// This function will be called every tick
|
||||
fn update(app: &mut App, renderer: &mut Renderer2D, dt: f32) {}
|
||||
|
||||
fn main() {
|
||||
fn main() {
|
||||
App::new() // Generate a basic 2D app
|
||||
.with_preset(App2D) // Pre-registers the `Transform2D` component in the scene
|
||||
.with_title("Comet App") // Sets the window title
|
||||
.with_icon(r"resources/textures/comet_icon.png") // Sets the window icon
|
||||
.with_icon(r"res/textures/comet_icon.png") // Sets the window icon
|
||||
.with_size(1920, 1080) // Sets the window size
|
||||
.with_game_state(GameState::new()) // Adds a custom game state struct
|
||||
.run::<Renderer2D>(setup, update) // Starts app with the given
|
||||
.run::<Renderer2D>(setup, update) // Starts app with the given
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -75,41 +75,41 @@ use std::path::PathBuf;
|
|||
|
||||
fn main() -> Result<()> {
|
||||
// Watch resource directories for changes
|
||||
println!("cargo:rerun-if-changed=resources/materials/*");
|
||||
println!("cargo:rerun-if-changed=resources/objects/*");
|
||||
println!("cargo:rerun-if-changed=resources/textures/*");
|
||||
println!("cargo:rerun-if-changed=resources/shaders/*");
|
||||
println!("cargo:rerun-if-changed=resources/data/*");
|
||||
println!("cargo:rerun-if-changed=resources/sounds/*");
|
||||
println!("cargo:rerun-if-changed=resources/fonts/*");
|
||||
|
||||
println!("cargo:rerun-if-changed=res/materials/*");
|
||||
println!("cargo:rerun-if-changed=res/objects/*");
|
||||
println!("cargo:rerun-if-changed=res/textures/*");
|
||||
println!("cargo:rerun-if-changed=res/shaders/*");
|
||||
println!("cargo:rerun-if-changed=res/data/*");
|
||||
println!("cargo:rerun-if-changed=res/sounds/*");
|
||||
println!("cargo:rerun-if-changed=res/fonts/*");
|
||||
|
||||
let profile = env::var("PROFILE")?;
|
||||
let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR")?);
|
||||
let target_dir = manifest_dir.join("target").join(&profile);
|
||||
|
||||
let dest_resources_dir = target_dir.join("resources");
|
||||
|
||||
|
||||
let dest_resources_dir = target_dir.join("res");
|
||||
|
||||
std::fs::create_dir_all(&dest_resources_dir)?;
|
||||
|
||||
|
||||
let mut copy_options = CopyOptions::new();
|
||||
copy_options.overwrite = true;
|
||||
copy_options.copy_inside = true;
|
||||
|
||||
|
||||
let resource_folders = vec![
|
||||
"resources/materials/",
|
||||
"resources/objects/",
|
||||
"resources/textures/",
|
||||
"resources/shaders/",
|
||||
"resources/data/",
|
||||
"resources/sounds/",
|
||||
"resources/fonts/",
|
||||
"res/materials/",
|
||||
"res/objects/",
|
||||
"res/textures/",
|
||||
"res/shaders/",
|
||||
"res/data/",
|
||||
"res/sounds/",
|
||||
"res/fonts/",
|
||||
];
|
||||
|
||||
|
||||
let resource_paths: Vec<PathBuf> = resource_folders
|
||||
.iter()
|
||||
.map(|p| manifest_dir.join(p))
|
||||
.collect();
|
||||
|
||||
|
||||
copy_items(&resource_paths, &dest_resources_dir, ©_options)?;
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -1,313 +1,313 @@
|
|||
use crate::camera::{CameraUniform, RenderCamera};
|
||||
use crate::draw_info::DrawInfo;
|
||||
use crate::render_pass::{RenderPassInfo, RenderPassType};
|
||||
use crate::renderer::Renderer;
|
||||
use comet_colors::Color;
|
||||
use comet_ecs::{Camera2D, Component, Position2D, Render, Render2D, Scene, Text, Transform2D};
|
||||
use comet_log::*;
|
||||
use comet_math::{p2, p3, v2, v3};
|
||||
use comet_resources::texture_atlas::TextureRegion;
|
||||
use comet_resources::{graphic_resource_manager::GraphicResourceManager, Texture, Vertex};
|
||||
use comet_structs::ComponentSet;
|
||||
use std::iter;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use std::time::Instant;
|
||||
use wgpu::BufferUsages;
|
||||
use wgpu::core::command::DrawKind::Draw;
|
||||
use wgpu::naga::ShaderStage;
|
||||
use wgpu::util::DeviceExt;
|
||||
use wgpu::BufferUsages;
|
||||
use winit::dpi::PhysicalSize;
|
||||
use winit::window::Window;
|
||||
use comet_colors::Color;
|
||||
use comet_ecs::{Camera2D, Component, Position2D, Render, Render2D, Transform2D, Scene, Text};
|
||||
use comet_log::*;
|
||||
use comet_math::{p2, p3, v2, v3};
|
||||
use comet_resources::{graphic_resource_manager::GraphicResourceManager, Texture, Vertex};
|
||||
use comet_resources::texture_atlas::TextureRegion;
|
||||
use comet_structs::ComponentSet;
|
||||
use crate::camera::{RenderCamera, CameraUniform};
|
||||
use crate::draw_info::DrawInfo;
|
||||
use crate::render_pass::{RenderPassInfo, RenderPassType};
|
||||
use crate::renderer::Renderer;
|
||||
|
||||
pub struct Renderer2D<'a> {
|
||||
surface: wgpu::Surface<'a>,
|
||||
device: wgpu::Device,
|
||||
queue: wgpu::Queue,
|
||||
config: wgpu::SurfaceConfiguration,
|
||||
size: PhysicalSize<u32>,
|
||||
render_pipeline_layout: wgpu::PipelineLayout,
|
||||
universal_render_pipeline: wgpu::RenderPipeline,
|
||||
texture_bind_group_layout: wgpu::BindGroupLayout,
|
||||
dummy_texture_bind_group: wgpu::BindGroup,
|
||||
texture_sampler: wgpu::Sampler,
|
||||
camera: RenderCamera,
|
||||
camera_uniform: CameraUniform,
|
||||
camera_buffer: wgpu::Buffer,
|
||||
camera_bind_group: wgpu::BindGroup,
|
||||
render_pass: Vec<RenderPassInfo>,
|
||||
draw_info: Vec<DrawInfo>,
|
||||
graphic_resource_manager: GraphicResourceManager,
|
||||
delta_time: f32,
|
||||
last_frame_time: Instant,
|
||||
clear_color: wgpu::Color,
|
||||
surface: wgpu::Surface<'a>,
|
||||
device: wgpu::Device,
|
||||
queue: wgpu::Queue,
|
||||
config: wgpu::SurfaceConfiguration,
|
||||
size: PhysicalSize<u32>,
|
||||
render_pipeline_layout: wgpu::PipelineLayout,
|
||||
universal_render_pipeline: wgpu::RenderPipeline,
|
||||
texture_bind_group_layout: wgpu::BindGroupLayout,
|
||||
dummy_texture_bind_group: wgpu::BindGroup,
|
||||
texture_sampler: wgpu::Sampler,
|
||||
camera: RenderCamera,
|
||||
camera_uniform: CameraUniform,
|
||||
camera_buffer: wgpu::Buffer,
|
||||
camera_bind_group: wgpu::BindGroup,
|
||||
render_pass: Vec<RenderPassInfo>,
|
||||
draw_info: Vec<DrawInfo>,
|
||||
graphic_resource_manager: GraphicResourceManager,
|
||||
delta_time: f32,
|
||||
last_frame_time: Instant,
|
||||
clear_color: wgpu::Color,
|
||||
}
|
||||
|
||||
impl<'a> Renderer2D<'a> {
|
||||
pub fn new(window: Arc<Window>, clear_color: Option<impl Color>) -> Renderer2D<'a> {
|
||||
let size = PhysicalSize::<u32>::new(1920, 1080);
|
||||
let size = PhysicalSize::<u32>::new(1920, 1080);
|
||||
|
||||
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
|
||||
backends: wgpu::Backends::PRIMARY,
|
||||
..Default::default()
|
||||
});
|
||||
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
|
||||
backends: wgpu::Backends::PRIMARY,
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
let surface = instance.create_surface(window).unwrap();
|
||||
let surface = instance.create_surface(window).unwrap();
|
||||
|
||||
let adapter = pollster::block_on(instance
|
||||
.request_adapter(&wgpu::RequestAdapterOptions {
|
||||
power_preference: wgpu::PowerPreference::default(),
|
||||
compatible_surface: Some(&surface),
|
||||
force_fallback_adapter: false,
|
||||
}))
|
||||
.unwrap();
|
||||
let adapter = pollster::block_on(instance.request_adapter(&wgpu::RequestAdapterOptions {
|
||||
power_preference: wgpu::PowerPreference::default(),
|
||||
compatible_surface: Some(&surface),
|
||||
force_fallback_adapter: false,
|
||||
}))
|
||||
.unwrap();
|
||||
|
||||
let (device, queue) = pollster::block_on(adapter
|
||||
.request_device(
|
||||
&wgpu::DeviceDescriptor {
|
||||
label: None,
|
||||
required_features: wgpu::Features::empty(),
|
||||
required_limits: wgpu::Limits::default(),
|
||||
memory_hints: Default::default(),
|
||||
},
|
||||
None, // Trace path
|
||||
))
|
||||
.unwrap();
|
||||
let (device, queue) = pollster::block_on(adapter.request_device(
|
||||
&wgpu::DeviceDescriptor {
|
||||
label: None,
|
||||
required_features: wgpu::Features::empty(),
|
||||
required_limits: wgpu::Limits::default(),
|
||||
memory_hints: Default::default(),
|
||||
},
|
||||
None, // Trace path
|
||||
))
|
||||
.unwrap();
|
||||
|
||||
let surface_caps = surface.get_capabilities(&adapter);
|
||||
let surface_format = surface_caps
|
||||
.formats
|
||||
.iter()
|
||||
.copied()
|
||||
.find(|f| f.is_srgb())
|
||||
.unwrap_or(surface_caps.formats[0]);
|
||||
let config = wgpu::SurfaceConfiguration {
|
||||
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
|
||||
format: surface_format,
|
||||
width: size.width,
|
||||
height: size.height,
|
||||
present_mode: surface_caps.present_modes[0],
|
||||
alpha_mode: surface_caps.alpha_modes[0],
|
||||
view_formats: vec![],
|
||||
desired_maximum_frame_latency: 2,
|
||||
};
|
||||
let surface_caps = surface.get_capabilities(&adapter);
|
||||
let surface_format = surface_caps
|
||||
.formats
|
||||
.iter()
|
||||
.copied()
|
||||
.find(|f| f.is_srgb())
|
||||
.unwrap_or(surface_caps.formats[0]);
|
||||
let config = wgpu::SurfaceConfiguration {
|
||||
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
|
||||
format: surface_format,
|
||||
width: size.width,
|
||||
height: size.height,
|
||||
present_mode: surface_caps.present_modes[0],
|
||||
alpha_mode: surface_caps.alpha_modes[0],
|
||||
view_formats: vec![],
|
||||
desired_maximum_frame_latency: 2,
|
||||
};
|
||||
|
||||
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
|
||||
label: Some("Shader"),
|
||||
source: wgpu::ShaderSource::Wgsl(include_str!("base2d.wgsl").into()),
|
||||
});
|
||||
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
|
||||
label: Some("Shader"),
|
||||
source: wgpu::ShaderSource::Wgsl(include_str!("base2d.wgsl").into()),
|
||||
});
|
||||
|
||||
let graphic_resource_manager = GraphicResourceManager::new();
|
||||
let graphic_resource_manager = GraphicResourceManager::new();
|
||||
|
||||
let diffuse_bytes = include_bytes!(r"../../../resources/textures/comet_icon.png");
|
||||
let diffuse_texture =
|
||||
Texture::from_bytes(&device, &queue, diffuse_bytes, "comet_icon.png", false).unwrap();
|
||||
let diffuse_bytes = include_bytes!(r"../../../res/textures/comet_icon.png");
|
||||
let diffuse_texture =
|
||||
Texture::from_bytes(&device, &queue, diffuse_bytes, "comet_icon.png", false).unwrap();
|
||||
|
||||
let texture_bind_group_layout =
|
||||
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||
entries: &[
|
||||
wgpu::BindGroupLayoutEntry {
|
||||
binding: 0,
|
||||
visibility: wgpu::ShaderStages::FRAGMENT,
|
||||
ty: wgpu::BindingType::Texture {
|
||||
multisampled: false,
|
||||
view_dimension: wgpu::TextureViewDimension::D2,
|
||||
sample_type: wgpu::TextureSampleType::Float { filterable: true },
|
||||
},
|
||||
count: None,
|
||||
},
|
||||
wgpu::BindGroupLayoutEntry {
|
||||
binding: 1,
|
||||
visibility: wgpu::ShaderStages::FRAGMENT,
|
||||
ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering),
|
||||
count: None,
|
||||
},
|
||||
],
|
||||
label: Some("texture_bind_group_layout"),
|
||||
});
|
||||
let texture_bind_group_layout =
|
||||
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||
entries: &[
|
||||
wgpu::BindGroupLayoutEntry {
|
||||
binding: 0,
|
||||
visibility: wgpu::ShaderStages::FRAGMENT,
|
||||
ty: wgpu::BindingType::Texture {
|
||||
multisampled: false,
|
||||
view_dimension: wgpu::TextureViewDimension::D2,
|
||||
sample_type: wgpu::TextureSampleType::Float { filterable: true },
|
||||
},
|
||||
count: None,
|
||||
},
|
||||
wgpu::BindGroupLayoutEntry {
|
||||
binding: 1,
|
||||
visibility: wgpu::ShaderStages::FRAGMENT,
|
||||
ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering),
|
||||
count: None,
|
||||
},
|
||||
],
|
||||
label: Some("texture_bind_group_layout"),
|
||||
});
|
||||
|
||||
let camera = RenderCamera::new(1.0, v2::new(2.0, 2.0), v3::new(0.0, 0.0, 0.0));
|
||||
let camera = RenderCamera::new(1.0, v2::new(2.0, 2.0), v3::new(0.0, 0.0, 0.0));
|
||||
|
||||
let mut camera_uniform = CameraUniform::new();
|
||||
camera_uniform.update_view_proj(&camera);
|
||||
let mut camera_uniform = CameraUniform::new();
|
||||
camera_uniform.update_view_proj(&camera);
|
||||
|
||||
let camera_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some("Camera Buffer"),
|
||||
contents: bytemuck::cast_slice(&[camera_uniform]),
|
||||
usage: BufferUsages::UNIFORM | BufferUsages::COPY_DST,
|
||||
});
|
||||
let camera_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some("Camera Buffer"),
|
||||
contents: bytemuck::cast_slice(&[camera_uniform]),
|
||||
usage: BufferUsages::UNIFORM | BufferUsages::COPY_DST,
|
||||
});
|
||||
|
||||
let camera_bind_group_layout =
|
||||
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||
entries: &[wgpu::BindGroupLayoutEntry {
|
||||
binding: 0,
|
||||
visibility: wgpu::ShaderStages::VERTEX,
|
||||
ty: wgpu::BindingType::Buffer {
|
||||
ty: wgpu::BufferBindingType::Uniform,
|
||||
has_dynamic_offset: false,
|
||||
min_binding_size: None,
|
||||
},
|
||||
count: None,
|
||||
}],
|
||||
label: Some("camera_bind_group_layout"),
|
||||
});
|
||||
let camera_bind_group_layout =
|
||||
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||
entries: &[wgpu::BindGroupLayoutEntry {
|
||||
binding: 0,
|
||||
visibility: wgpu::ShaderStages::VERTEX,
|
||||
ty: wgpu::BindingType::Buffer {
|
||||
ty: wgpu::BufferBindingType::Uniform,
|
||||
has_dynamic_offset: false,
|
||||
min_binding_size: None,
|
||||
},
|
||||
count: None,
|
||||
}],
|
||||
label: Some("camera_bind_group_layout"),
|
||||
});
|
||||
|
||||
let camera_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||
layout: &camera_bind_group_layout,
|
||||
entries: &[wgpu::BindGroupEntry {
|
||||
binding: 0,
|
||||
resource: camera_buffer.as_entire_binding(),
|
||||
}],
|
||||
label: Some("camera_bind_group"),
|
||||
});
|
||||
let camera_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||
layout: &camera_bind_group_layout,
|
||||
entries: &[wgpu::BindGroupEntry {
|
||||
binding: 0,
|
||||
resource: camera_buffer.as_entire_binding(),
|
||||
}],
|
||||
label: Some("camera_bind_group"),
|
||||
});
|
||||
|
||||
let render_pipeline_layout =
|
||||
device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
||||
label: Some("Render Pipeline Layout"),
|
||||
bind_group_layouts: &[
|
||||
&texture_bind_group_layout,
|
||||
&camera_bind_group_layout,
|
||||
],
|
||||
push_constant_ranges: &[],
|
||||
});
|
||||
let render_pipeline_layout =
|
||||
device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
||||
label: Some("Render Pipeline Layout"),
|
||||
bind_group_layouts: &[&texture_bind_group_layout, &camera_bind_group_layout],
|
||||
push_constant_ranges: &[],
|
||||
});
|
||||
|
||||
let universal_render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||
label: Some("Render Pipeline"),
|
||||
layout: Some(&render_pipeline_layout),
|
||||
vertex: wgpu::VertexState {
|
||||
module: &shader,
|
||||
entry_point: "vs_main",
|
||||
buffers: &[Vertex::desc()],
|
||||
compilation_options: Default::default(),
|
||||
},
|
||||
fragment: Some(wgpu::FragmentState {
|
||||
module: &shader,
|
||||
entry_point: "fs_main",
|
||||
targets: &[Some(wgpu::ColorTargetState {
|
||||
format: config.format,
|
||||
blend: Some(wgpu::BlendState {
|
||||
color: wgpu::BlendComponent {
|
||||
src_factor: wgpu::BlendFactor::SrcAlpha,
|
||||
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
||||
operation: wgpu::BlendOperation::Add,
|
||||
},
|
||||
alpha: wgpu::BlendComponent {
|
||||
src_factor: wgpu::BlendFactor::One,
|
||||
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
||||
operation: wgpu::BlendOperation::Add,
|
||||
},
|
||||
}),
|
||||
write_mask: wgpu::ColorWrites::ALL,
|
||||
})],
|
||||
compilation_options: Default::default(),
|
||||
}),
|
||||
primitive: wgpu::PrimitiveState {
|
||||
topology: wgpu::PrimitiveTopology::TriangleList,
|
||||
strip_index_format: None,
|
||||
front_face: wgpu::FrontFace::Ccw,
|
||||
cull_mode: Some(wgpu::Face::Back),
|
||||
polygon_mode: wgpu::PolygonMode::Fill,
|
||||
unclipped_depth: false,
|
||||
conservative: false,
|
||||
},
|
||||
depth_stencil: None,
|
||||
multisample: wgpu::MultisampleState {
|
||||
count: 1,
|
||||
mask: !0,
|
||||
alpha_to_coverage_enabled: false,
|
||||
},
|
||||
multiview: None,
|
||||
cache: None,
|
||||
});
|
||||
let universal_render_pipeline =
|
||||
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||
label: Some("Render Pipeline"),
|
||||
layout: Some(&render_pipeline_layout),
|
||||
vertex: wgpu::VertexState {
|
||||
module: &shader,
|
||||
entry_point: "vs_main",
|
||||
buffers: &[Vertex::desc()],
|
||||
compilation_options: Default::default(),
|
||||
},
|
||||
fragment: Some(wgpu::FragmentState {
|
||||
module: &shader,
|
||||
entry_point: "fs_main",
|
||||
targets: &[Some(wgpu::ColorTargetState {
|
||||
format: config.format,
|
||||
blend: Some(wgpu::BlendState {
|
||||
color: wgpu::BlendComponent {
|
||||
src_factor: wgpu::BlendFactor::SrcAlpha,
|
||||
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
||||
operation: wgpu::BlendOperation::Add,
|
||||
},
|
||||
alpha: wgpu::BlendComponent {
|
||||
src_factor: wgpu::BlendFactor::One,
|
||||
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
||||
operation: wgpu::BlendOperation::Add,
|
||||
},
|
||||
}),
|
||||
write_mask: wgpu::ColorWrites::ALL,
|
||||
})],
|
||||
compilation_options: Default::default(),
|
||||
}),
|
||||
primitive: wgpu::PrimitiveState {
|
||||
topology: wgpu::PrimitiveTopology::TriangleList,
|
||||
strip_index_format: None,
|
||||
front_face: wgpu::FrontFace::Ccw,
|
||||
cull_mode: Some(wgpu::Face::Back),
|
||||
polygon_mode: wgpu::PolygonMode::Fill,
|
||||
unclipped_depth: false,
|
||||
conservative: false,
|
||||
},
|
||||
depth_stencil: None,
|
||||
multisample: wgpu::MultisampleState {
|
||||
count: 1,
|
||||
mask: !0,
|
||||
alpha_to_coverage_enabled: false,
|
||||
},
|
||||
multiview: None,
|
||||
cache: None,
|
||||
});
|
||||
|
||||
let mut render_pass: Vec<RenderPassInfo> = Vec::new();
|
||||
/*render_pass.push(RenderPassInfo::new_engine_pass(
|
||||
&device,
|
||||
"Standard Render Pass".to_string(),
|
||||
&texture_bind_group_layout,
|
||||
&diffuse_texture,
|
||||
vec![],
|
||||
vec![],
|
||||
));*/
|
||||
let mut render_pass: Vec<RenderPassInfo> = Vec::new();
|
||||
/*render_pass.push(RenderPassInfo::new_engine_pass(
|
||||
&device,
|
||||
"Standard Render Pass".to_string(),
|
||||
&texture_bind_group_layout,
|
||||
&diffuse_texture,
|
||||
vec![],
|
||||
vec![],
|
||||
));*/
|
||||
|
||||
let clear_color = match clear_color {
|
||||
Some(color) => color.to_wgpu(),
|
||||
None => wgpu::Color {
|
||||
r: 0.0,
|
||||
g: 0.0,
|
||||
b: 0.0,
|
||||
a: 1.0,
|
||||
}
|
||||
};
|
||||
let clear_color = match clear_color {
|
||||
Some(color) => color.to_wgpu(),
|
||||
None => wgpu::Color {
|
||||
r: 0.0,
|
||||
g: 0.0,
|
||||
b: 0.0,
|
||||
a: 1.0,
|
||||
},
|
||||
};
|
||||
|
||||
let texture_sampler = device.create_sampler(&wgpu::SamplerDescriptor {
|
||||
address_mode_u: wgpu::AddressMode::ClampToEdge,
|
||||
address_mode_v: wgpu::AddressMode::ClampToEdge,
|
||||
address_mode_w: wgpu::AddressMode::ClampToEdge,
|
||||
mag_filter: wgpu::FilterMode::Linear,
|
||||
min_filter: wgpu::FilterMode::Linear,
|
||||
mipmap_filter: wgpu::FilterMode::Linear,
|
||||
lod_min_clamp: 0.0,
|
||||
lod_max_clamp: 100.0,
|
||||
compare: None,
|
||||
anisotropy_clamp: 16,
|
||||
border_color: None,
|
||||
..Default::default()
|
||||
});
|
||||
let texture_sampler = device.create_sampler(&wgpu::SamplerDescriptor {
|
||||
address_mode_u: wgpu::AddressMode::ClampToEdge,
|
||||
address_mode_v: wgpu::AddressMode::ClampToEdge,
|
||||
address_mode_w: wgpu::AddressMode::ClampToEdge,
|
||||
mag_filter: wgpu::FilterMode::Linear,
|
||||
min_filter: wgpu::FilterMode::Linear,
|
||||
mipmap_filter: wgpu::FilterMode::Linear,
|
||||
lod_min_clamp: 0.0,
|
||||
lod_max_clamp: 100.0,
|
||||
compare: None,
|
||||
anisotropy_clamp: 16,
|
||||
border_color: None,
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
let empty_texture = device.create_texture(&wgpu::TextureDescriptor {
|
||||
label: Some("Empty Texture"),
|
||||
size: wgpu::Extent3d {
|
||||
width: config.width,
|
||||
height: config.height,
|
||||
depth_or_array_layers: 1,
|
||||
},
|
||||
mip_level_count: 1,
|
||||
sample_count: 1,
|
||||
dimension: wgpu::TextureDimension::D2,
|
||||
format: wgpu::TextureFormat::Bgra8UnormSrgb,
|
||||
usage: wgpu::TextureUsages::COPY_SRC | wgpu::TextureUsages::COPY_DST | wgpu::TextureUsages::TEXTURE_BINDING,
|
||||
view_formats: &[wgpu::TextureFormat::Bgra8UnormSrgb],
|
||||
});
|
||||
let empty_texture = device.create_texture(&wgpu::TextureDescriptor {
|
||||
label: Some("Empty Texture"),
|
||||
size: wgpu::Extent3d {
|
||||
width: config.width,
|
||||
height: config.height,
|
||||
depth_or_array_layers: 1,
|
||||
},
|
||||
mip_level_count: 1,
|
||||
sample_count: 1,
|
||||
dimension: wgpu::TextureDimension::D2,
|
||||
format: wgpu::TextureFormat::Bgra8UnormSrgb,
|
||||
usage: wgpu::TextureUsages::COPY_SRC
|
||||
| wgpu::TextureUsages::COPY_DST
|
||||
| wgpu::TextureUsages::TEXTURE_BINDING,
|
||||
view_formats: &[wgpu::TextureFormat::Bgra8UnormSrgb],
|
||||
});
|
||||
|
||||
let dummy_texture_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||
layout: &texture_bind_group_layout,
|
||||
entries: &[
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 0,
|
||||
resource: wgpu::BindingResource::TextureView(&empty_texture.create_view(&wgpu::TextureViewDescriptor::default())),
|
||||
},
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 1,
|
||||
resource: wgpu::BindingResource::Sampler(&texture_sampler),
|
||||
},
|
||||
],
|
||||
label: Some("dummy_texture_bind_group"),
|
||||
});
|
||||
|
||||
let mut draw_info: Vec<DrawInfo> = Vec::new();
|
||||
let dummy_texture_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||
layout: &texture_bind_group_layout,
|
||||
entries: &[
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 0,
|
||||
resource: wgpu::BindingResource::TextureView(
|
||||
&empty_texture.create_view(&wgpu::TextureViewDescriptor::default()),
|
||||
),
|
||||
},
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 1,
|
||||
resource: wgpu::BindingResource::Sampler(&texture_sampler),
|
||||
},
|
||||
],
|
||||
label: Some("dummy_texture_bind_group"),
|
||||
});
|
||||
|
||||
Self {
|
||||
surface,
|
||||
device,
|
||||
queue,
|
||||
config,
|
||||
size,
|
||||
render_pipeline_layout,
|
||||
universal_render_pipeline,
|
||||
texture_bind_group_layout,
|
||||
dummy_texture_bind_group,
|
||||
texture_sampler,
|
||||
camera,
|
||||
camera_uniform,
|
||||
camera_buffer,
|
||||
camera_bind_group,
|
||||
render_pass,
|
||||
draw_info,
|
||||
graphic_resource_manager,
|
||||
delta_time: 0.0,
|
||||
last_frame_time: Instant::now(),
|
||||
clear_color,
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut draw_info: Vec<DrawInfo> = Vec::new();
|
||||
|
||||
Self {
|
||||
surface,
|
||||
device,
|
||||
queue,
|
||||
config,
|
||||
size,
|
||||
render_pipeline_layout,
|
||||
universal_render_pipeline,
|
||||
texture_bind_group_layout,
|
||||
dummy_texture_bind_group,
|
||||
texture_sampler,
|
||||
camera,
|
||||
camera_uniform,
|
||||
camera_buffer,
|
||||
camera_bind_group,
|
||||
render_pass,
|
||||
draw_info,
|
||||
graphic_resource_manager,
|
||||
delta_time: 0.0,
|
||||
last_frame_time: Instant::now(),
|
||||
clear_color,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,73 +1,73 @@
|
|||
use comet::prelude::*;
|
||||
use winit_input_helper::WinitInputHelper;
|
||||
use comet_input::keyboard::Key;
|
||||
use winit_input_helper::WinitInputHelper;
|
||||
|
||||
fn setup(app: &mut App, renderer: &mut Renderer2D) {
|
||||
// Takes all the textures from resources/textures and puts them into a texture atlas
|
||||
renderer.initialize_atlas();
|
||||
// Takes all the textures from res/textures and puts them into a texture atlas
|
||||
renderer.initialize_atlas();
|
||||
|
||||
let camera = app.new_entity();
|
||||
app.add_component(camera, Transform2D::new());
|
||||
app.add_component(camera, Camera2D::new(v2::new(2.0, 2.0), 1.0, 1));
|
||||
let camera = app.new_entity();
|
||||
app.add_component(camera, Transform2D::new());
|
||||
app.add_component(camera, Camera2D::new(v2::new(2.0, 2.0), 1.0, 1));
|
||||
|
||||
let e1 = app.new_entity();
|
||||
let e1 = app.new_entity();
|
||||
|
||||
app.add_component(e1, Transform2D::new());
|
||||
app.add_component(e1, Transform2D::new());
|
||||
|
||||
let mut renderer2d = Render2D::new();
|
||||
renderer2d.set_texture(r"resources/textures/comet_icon.png");
|
||||
renderer2d.set_visibility(true);
|
||||
let mut renderer2d = Render2D::new();
|
||||
renderer2d.set_texture(r"res/textures/comet_icon.png");
|
||||
renderer2d.set_visibility(true);
|
||||
|
||||
app.add_component(e1, renderer2d);
|
||||
app.add_component(e1, renderer2d);
|
||||
}
|
||||
|
||||
fn update(app: &mut App, renderer: &mut Renderer2D, dt: f32) {
|
||||
handle_input(app, dt);
|
||||
handle_input(app, dt);
|
||||
|
||||
renderer.render_scene_2d(app.scene());
|
||||
renderer.render_scene_2d(app.scene());
|
||||
}
|
||||
|
||||
fn handle_input(app: &mut App, dt: f32) {
|
||||
if app.key_held(Key::KeyW)
|
||||
|| app.key_held(Key::KeyA)
|
||||
|| app.key_held(Key::KeyS)
|
||||
|| app.key_held(Key::KeyD)
|
||||
{
|
||||
update_position(
|
||||
app.input_manager().clone(),
|
||||
app.get_component_mut::<Transform2D>(1).unwrap(),
|
||||
dt
|
||||
);
|
||||
}
|
||||
if app.key_held(Key::KeyW)
|
||||
|| app.key_held(Key::KeyA)
|
||||
|| app.key_held(Key::KeyS)
|
||||
|| app.key_held(Key::KeyD)
|
||||
{
|
||||
update_position(
|
||||
app.input_manager().clone(),
|
||||
app.get_component_mut::<Transform2D>(1).unwrap(),
|
||||
dt,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn update_position(input: WinitInputHelper, transform: &mut Transform2D, dt: f32) {
|
||||
let mut direction = v2::ZERO;
|
||||
let mut direction = v2::ZERO;
|
||||
|
||||
if input.key_held(Key::KeyW) {
|
||||
direction += v2::Y;
|
||||
}
|
||||
if input.key_held(Key::KeyA) {
|
||||
direction -= v2::X;
|
||||
}
|
||||
if input.key_held(Key::KeyS) {
|
||||
direction -= v2::Y;
|
||||
}
|
||||
if input.key_held(Key::KeyD) {
|
||||
direction += v2::X;
|
||||
}
|
||||
if input.key_held(Key::KeyW) {
|
||||
direction += v2::Y;
|
||||
}
|
||||
if input.key_held(Key::KeyA) {
|
||||
direction -= v2::X;
|
||||
}
|
||||
if input.key_held(Key::KeyS) {
|
||||
direction -= v2::Y;
|
||||
}
|
||||
if input.key_held(Key::KeyD) {
|
||||
direction += v2::X;
|
||||
}
|
||||
|
||||
// If check to prevent division by zero and the comet to fly off into infinity...
|
||||
if direction != v2::ZERO {
|
||||
let normalized_dir = direction.normalize();
|
||||
let displacement = normalized_dir * 777.7 * dt;
|
||||
transform.translate(displacement);
|
||||
}
|
||||
// If check to prevent division by zero and the comet to fly off into infinity...
|
||||
if direction != v2::ZERO {
|
||||
let normalized_dir = direction.normalize();
|
||||
let displacement = normalized_dir * 777.7 * dt;
|
||||
transform.translate(displacement);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.with_title("Simple Move 2D")
|
||||
.with_preset(App2D)
|
||||
.run::<Renderer2D>(setup, update);
|
||||
}
|
||||
App::new()
|
||||
.with_title("Simple Move 2D")
|
||||
.with_preset(App2D)
|
||||
.run::<Renderer2D>(setup, update);
|
||||
}
|
||||
|
|
|
@ -1,42 +1,45 @@
|
|||
use comet::prelude::*;
|
||||
|
||||
fn setup(app: &mut App, renderer: &mut Renderer2D) {
|
||||
// Loading the font from the resources/fonts directory with a rendered size of 77px
|
||||
renderer.load_font("./resources/fonts/PressStart2P-Regular.ttf", 77.0);
|
||||
// Loading the font from the res/fonts directory with a rendered size of 77px
|
||||
renderer.load_font("./res/fonts/PressStart2P-Regular.ttf", 77.0);
|
||||
|
||||
// Setting up camera
|
||||
let camera = app.new_entity();
|
||||
|
||||
|
||||
app.add_component(camera, Transform2D::new());
|
||||
app.add_component(camera, Camera2D::new(v2::new(2.0, 2.0), 1.0, 1));
|
||||
|
||||
// Creating the text entity
|
||||
let text = app.new_entity();
|
||||
app.add_component(text, Transform2D::new());
|
||||
app.add_component(text, Text::new(
|
||||
"comet", // The content of the text
|
||||
"./resources/fonts/PressStart2P-Regular.ttf", // The used font (right now exact to the font path)
|
||||
77.0, // Pixel size at which the font will be drawn
|
||||
true, // Should the text be visible
|
||||
sRgba::<f32>::from_hex("#abb2bfff") // Color of the text
|
||||
));
|
||||
app.add_component(
|
||||
text,
|
||||
Text::new(
|
||||
"comet", // The content of the text
|
||||
"./res/fonts/PressStart2P-Regular.ttf", // The used font (right now exact to the font path)
|
||||
77.0, // Pixel size at which the font will be drawn
|
||||
true, // Should the text be visible
|
||||
sRgba::<f32>::from_hex("#abb2bfff"), // Color of the text
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
fn update(app: &mut App, renderer: &mut Renderer2D, dt: f32) {
|
||||
// Getting the windows size
|
||||
let size = renderer.size();
|
||||
|
||||
|
||||
// Recalculating the position of the text every frame to ensure the same relative position
|
||||
let transform = app.get_component_mut::<Transform2D>(1).unwrap();
|
||||
transform.position_mut().set_x(-((size.width-50) as f32));
|
||||
transform.position_mut().set_y((size.height-100) as f32);
|
||||
transform.position_mut().set_x(-((size.width - 50) as f32));
|
||||
transform.position_mut().set_y((size.height - 100) as f32);
|
||||
|
||||
renderer.render_scene_2d(app.scene());
|
||||
}
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
App::new()
|
||||
.with_preset(App2D)
|
||||
.with_title("Simple Text")
|
||||
.run::<Renderer2D>(setup, update);
|
||||
}
|
||||
.with_title("Simple Text")
|
||||
.run::<Renderer2D>(setup, update);
|
||||
}
|
||||
|
|
|
@ -1,32 +1,32 @@
|
|||
use comet::prelude::*;
|
||||
|
||||
fn setup(app: &mut App, renderer: &mut Renderer2D) {
|
||||
// Creating a texture atlas from the provided textures in the vector
|
||||
renderer.set_texture_atlas_by_paths(vec!["./resources/textures/comet_icon.png".to_string()]);
|
||||
// Creating a texture atlas from the provided textures in the vector
|
||||
renderer.set_texture_atlas_by_paths(vec!["./res/textures/comet_icon.png".to_string()]);
|
||||
|
||||
// Creating a camera entity
|
||||
let cam = app.new_entity();
|
||||
app.add_component(cam, Transform2D::new());
|
||||
app.add_component(cam, Camera2D::new(v2::new(2.0, 2.0), 1.0, 1));
|
||||
// Creating a camera entity
|
||||
let cam = app.new_entity();
|
||||
app.add_component(cam, Transform2D::new());
|
||||
app.add_component(cam, Camera2D::new(v2::new(2.0, 2.0), 1.0, 1));
|
||||
|
||||
// Creating a textured entity
|
||||
let e0 = app.new_entity();
|
||||
app.add_component(e0, Transform2D::new());
|
||||
// Creating a textured entity
|
||||
let e0 = app.new_entity();
|
||||
app.add_component(e0, Transform2D::new());
|
||||
|
||||
let mut render = Render2D::new();
|
||||
render.set_visibility(true);
|
||||
render.set_texture("./resources/textures/comet_icon.png");
|
||||
let mut render = Render2D::new();
|
||||
render.set_visibility(true);
|
||||
render.set_texture("./res/textures/comet_icon.png");
|
||||
|
||||
app.add_component(e0, render);
|
||||
app.add_component(e0, render);
|
||||
}
|
||||
|
||||
fn update(app: &mut App, renderer: &mut Renderer2D, dt: f32) {
|
||||
renderer.render_scene_2d(app.scene())
|
||||
renderer.render_scene_2d(app.scene())
|
||||
}
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.with_title("Textured Entity")
|
||||
.with_preset(App2D)
|
||||
.run::<Renderer2D>(setup, update);
|
||||
}
|
||||
App::new()
|
||||
.with_title("Textured Entity")
|
||||
.with_preset(App2D)
|
||||
.run::<Renderer2D>(setup, update);
|
||||
}
|
||||
|
|
Before Width: | Height: | Size: 9.9 KiB After Width: | Height: | Size: 9.9 KiB |
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 4.6 KiB |
Before Width: | Height: | Size: 320 B After Width: | Height: | Size: 320 B |
Before Width: | Height: | Size: 5 KiB After Width: | Height: | Size: 5 KiB |
Before Width: | Height: | Size: 425 B After Width: | Height: | Size: 425 B |
Before Width: | Height: | Size: 6.1 KiB After Width: | Height: | Size: 6.1 KiB |
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 4.5 KiB |
Before Width: | Height: | Size: 736 B After Width: | Height: | Size: 736 B |
Before Width: | Height: | Size: 788 B After Width: | Height: | Size: 788 B |
Before Width: | Height: | Size: 878 B After Width: | Height: | Size: 878 B |
Before Width: | Height: | Size: 5 KiB After Width: | Height: | Size: 5 KiB |