prepping to start shader work
This commit is contained in:
parent
8e89927525
commit
8e3d1b14e0
@ -16,6 +16,7 @@ thiserror = "1.0"
|
||||
chrono = "0.4"
|
||||
rust-embed = "6.2.0"
|
||||
raylib = "3.5"
|
||||
# cgmath = "0.18"
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
|
8
game/assets/configs/application.json
Normal file
8
game/assets/configs/application.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "Unnamed game",
|
||||
"authors": [
|
||||
{
|
||||
"github": "ewpratten"
|
||||
}
|
||||
]
|
||||
}
|
38
game/assets/shaders/pixelart.fs
Normal file
38
game/assets/shaders/pixelart.fs
Normal file
@ -0,0 +1,38 @@
|
||||
#version 330
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
in vec2 fragTexCoord;
|
||||
in vec4 fragColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// Viewport dimensions
|
||||
const vec2 viewport = vec2(1080.0, 720.0);
|
||||
|
||||
// Pixel scaling
|
||||
const vec2 pixelScale = vec2(2.0, 2.0);
|
||||
|
||||
void main()
|
||||
{
|
||||
|
||||
// Calculate the distance to merge pixels
|
||||
float dx = pixelScale.x * (1.0 / viewport.x);
|
||||
float dy = pixelScale.y * (1.0 / viewport.y);
|
||||
|
||||
// Get the base UV coordinate of the pixel
|
||||
vec2 baseUV = fragTexCoord;
|
||||
|
||||
// Calculate a UV for this new blocky pixel
|
||||
vec2 pixelatedUV = vec2(dx * floor(baseUV.x / dx), dy * floor(baseUV.y / dy));
|
||||
|
||||
// Rebuild the texture with the new UVs
|
||||
vec3 tc = texture(texture0, pixelatedUV).rgb;
|
||||
|
||||
// Build the final pixel
|
||||
finalColor = vec4(tc, 1.0);
|
||||
}
|
@ -1,10 +1,12 @@
|
||||
use discord_sdk::activity::ActivityBuilder;
|
||||
use raylib::prelude::*;
|
||||
use tracing::error;
|
||||
use utilities::{
|
||||
datastore::StaticGameData,
|
||||
discord::{DiscordConfig, DiscordRpcClient},
|
||||
game_config::GameConfig,
|
||||
math::rotate_vector,
|
||||
};
|
||||
use raylib::prelude::*;
|
||||
|
||||
#[macro_use]
|
||||
extern crate thiserror;
|
||||
@ -15,30 +17,41 @@ mod utilities;
|
||||
|
||||
/// The game entrypoint
|
||||
pub async fn game_begin() {
|
||||
// Load the general config for the game
|
||||
let game_config = GameConfig::load(
|
||||
StaticGameData::get("configs/application.json").expect("Failed to load application.json"),
|
||||
)
|
||||
.expect("Could not load general game config data");
|
||||
|
||||
// Attempt to connect to a locally running Discord instance for rich presence access
|
||||
let discord_config = DiscordConfig::load(
|
||||
StaticGameData::get("configs/discord.json").expect("Failed to load discord.json"),
|
||||
)
|
||||
.expect("Could not load Discord config data");
|
||||
let discord_rpc =
|
||||
match DiscordRpcClient::new(discord_config.app_id, discord_sdk::Subscriptions::ACTIVITY)
|
||||
.await
|
||||
{
|
||||
Ok(client) => Some(client),
|
||||
Err(err) => {
|
||||
error!("Could not connect to or find a locally running Discord instance.");
|
||||
error!("Discord connection error: {:?}", err);
|
||||
None
|
||||
}
|
||||
};
|
||||
// let discord_rpc =
|
||||
// match DiscordRpcClient::new(discord_config.app_id, discord_sdk::Subscriptions::ACTIVITY)
|
||||
// .await
|
||||
// {
|
||||
// Ok(client) => Some(client),
|
||||
// Err(err) => {
|
||||
// error!("Could not connect to or find a locally running Discord instance.");
|
||||
// error!("Discord connection error: {:?}", err);
|
||||
// None
|
||||
// }
|
||||
// };
|
||||
|
||||
if let Some(rpc) = discord_rpc {
|
||||
rpc.set_rich_presence(ActivityBuilder::default().details("Testing...")).await.unwrap();
|
||||
}
|
||||
// if let Some(rpc) = discord_rpc {
|
||||
// rpc.set_rich_presence(ActivityBuilder::default().details("Testing..."))
|
||||
// .await
|
||||
// .unwrap();
|
||||
// }
|
||||
|
||||
let (mut rl, thread) = raylib::init()
|
||||
.size(640, 480)
|
||||
.title("Hello, World")
|
||||
.title(&game_config.name)
|
||||
.vsync()
|
||||
.msaa_4x()
|
||||
.resizable()
|
||||
.build();
|
||||
|
||||
while !rl.window_should_close() {
|
||||
@ -46,5 +59,14 @@ pub async fn game_begin() {
|
||||
|
||||
d.clear_background(Color::WHITE);
|
||||
d.draw_text("Hello, world!", 12, 12, 20, Color::BLACK);
|
||||
|
||||
let angle = (d.get_time() as f32 * 80.0).to_radians();
|
||||
let screen_center = Vector2::new(d.get_screen_width() as f32 / 2.0, d.get_screen_height() as f32 / 2.0);
|
||||
let top = rotate_vector(Vector2::new(0.0, -100.0), angle) + screen_center;
|
||||
let right = rotate_vector(Vector2::new(100.0, 0.0), angle) + screen_center;
|
||||
let left = rotate_vector(Vector2::new(-100.0, 0.0), angle) + screen_center;
|
||||
|
||||
d.draw_triangle(top, left, right, Color::BLACK);
|
||||
d.draw_fps(10, 100);
|
||||
}
|
||||
}
|
||||
|
21
game/src/utilities/game_config.rs
Normal file
21
game/src/utilities/game_config.rs
Normal file
@ -0,0 +1,21 @@
|
||||
//! Contains the general configuration data for the game
|
||||
|
||||
use rust_embed::EmbeddedFile;
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct Author {
|
||||
pub github: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct GameConfig {
|
||||
pub name: String,
|
||||
pub authors: Vec<Author>,
|
||||
}
|
||||
|
||||
impl GameConfig {
|
||||
/// Load from a file
|
||||
pub fn load(file: EmbeddedFile) -> Result<Self, serde_json::Error> {
|
||||
serde_json::from_slice(&file.data)
|
||||
}
|
||||
}
|
9
game/src/utilities/math.rs
Normal file
9
game/src/utilities/math.rs
Normal file
@ -0,0 +1,9 @@
|
||||
use raylib::math::Vector2;
|
||||
|
||||
/// Rotate a vector by an angle
|
||||
pub fn rotate_vector(vector: Vector2, angle_rad: f32) -> Vector2 {
|
||||
return Vector2 {
|
||||
x: (vector.x * angle_rad.cos()) - (vector.y * angle_rad.sin()),
|
||||
y: (vector.y * angle_rad.cos()) + (vector.x * angle_rad.sin()),
|
||||
};
|
||||
}
|
@ -1,2 +1,4 @@
|
||||
pub mod discord;
|
||||
pub mod datastore;
|
||||
pub mod datastore;
|
||||
pub mod game_config;
|
||||
pub mod math;
|
Reference in New Issue
Block a user