From 9484e911667b226239e78bcff174adce0c4388f0 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Fri, 7 Apr 2023 00:04:19 -0500 Subject: [PATCH] housekeeping for assignment 2a --- assignment-2a-rust/Cargo.lock | 7 ---- assignment-2a-rust/Cargo.toml | 10 ----- assignment-2a-rust/shaders/fshader2a.glsl | 9 ---- assignment-2a-rust/shaders/vshader2a.glsl | 12 ------ assignment-2a-rust/src/init.rs | 3 -- assignment-2a-rust/src/main.rs | 50 ----------------------- assignment-2a-rust/src/shaders.rs | 10 ----- assignment-2a/CMakeLists.txt | 5 ++- assignment-2a/src/{main.cpp => HW2a.cpp} | 15 +++---- assignment-2a/src/state.cpp | 0 assignment-2a/src/state.h | 9 ++++ 11 files changed, 18 insertions(+), 112 deletions(-) delete mode 100644 assignment-2a-rust/Cargo.lock delete mode 100644 assignment-2a-rust/Cargo.toml delete mode 100644 assignment-2a-rust/shaders/fshader2a.glsl delete mode 100644 assignment-2a-rust/shaders/vshader2a.glsl delete mode 100644 assignment-2a-rust/src/init.rs delete mode 100644 assignment-2a-rust/src/main.rs delete mode 100644 assignment-2a-rust/src/shaders.rs rename assignment-2a/src/{main.cpp => HW2a.cpp} (94%) create mode 100644 assignment-2a/src/state.cpp create mode 100644 assignment-2a/src/state.h diff --git a/assignment-2a-rust/Cargo.lock b/assignment-2a-rust/Cargo.lock deleted file mode 100644 index eceedd4..000000000 --- a/assignment-2a-rust/Cargo.lock +++ /dev/null @@ -1,7 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "assignment-2a-rust" -version = "0.1.0" diff --git a/assignment-2a-rust/Cargo.toml b/assignment-2a-rust/Cargo.toml deleted file mode 100644 index bff45c4..000000000 --- a/assignment-2a-rust/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "assignment-2a-rust" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -anyhow = "1.0.70" -glfw = "0.51.0" diff --git a/assignment-2a-rust/shaders/fshader2a.glsl b/assignment-2a-rust/shaders/fshader2a.glsl deleted file mode 100644 index 75e4086..000000000 --- a/assignment-2a-rust/shaders/fshader2a.glsl +++ /dev/null @@ -1,9 +0,0 @@ -// fragment shader template - -#version 150 -in vec4 vcolor; -out vec4 color; - -void main() { - color = vcolor; // set output color to interpolated color from vshader -} diff --git a/assignment-2a-rust/shaders/vshader2a.glsl b/assignment-2a-rust/shaders/vshader2a.glsl deleted file mode 100644 index ee0ebc3..000000000 --- a/assignment-2a-rust/shaders/vshader2a.glsl +++ /dev/null @@ -1,12 +0,0 @@ -// vertex shader template - -#version 150 -in vec4 vertex_position; -in vec4 vertex_color; -out vec4 vcolor; -uniform mat4 M; - -void main() { - gl_Position = M * vertex_position; // update vertex position using M - vcolor = vertex_color; // pass vertex color to fragment shader -} diff --git a/assignment-2a-rust/src/init.rs b/assignment-2a-rust/src/init.rs deleted file mode 100644 index e00a639..000000000 --- a/assignment-2a-rust/src/init.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub fn init() { - -} diff --git a/assignment-2a-rust/src/main.rs b/assignment-2a-rust/src/main.rs deleted file mode 100644 index e8c0ccc..000000000 --- a/assignment-2a-rust/src/main.rs +++ /dev/null @@ -1,50 +0,0 @@ -extern crate glfw; - -mod init; -mod shaders; - -use anyhow::{Context as _, Result}; -use glfw::{Action, Context, Key, OpenGlProfileHint, WindowHint}; - -fn main() -> Result<()> { - let mut glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap(); - - // Ask for OpenGL 3.2 - glfw.window_hint(WindowHint::ContextVersionMajor(3)); - glfw.window_hint(WindowHint::ContextVersionMajor(2)); - glfw.window_hint(WindowHint::OpenGlProfile(OpenGlProfileHint::Core)); - glfw.window_hint(WindowHint::OpenGlForwardCompat(true)); - - // Use GLFW to open a window within which to display your graphics - let (mut window, events) = glfw - .create_window(300, 300, "Hello this is window", glfw::WindowMode::Windowed) - .context("Failed to create GLFW window.")?; - - // Tells the system to wait for the rendered frame to finish updating - // before swapping buffers; can help to avoid tearing - glfw.set_swap_interval(glfw::SwapInterval::Sync(1)); - - // Create the shaders and perform other one-time initializations - init::init(); - - window.set_key_polling(true); - window.make_current(); - - while !window.should_close() { - glfw.poll_events(); - for (_, event) in glfw::flush_messages(&events) { - handle_window_event(&mut window, event); - } - } - - Ok(()) -} - -fn handle_window_event(window: &mut glfw::Window, event: glfw::WindowEvent) { - match event { - glfw::WindowEvent::Key(Key::Escape, _, Action::Press, _) => { - window.set_should_close(true) - } - _ => {} - } -} diff --git a/assignment-2a-rust/src/shaders.rs b/assignment-2a-rust/src/shaders.rs deleted file mode 100644 index 782a077..000000000 --- a/assignment-2a-rust/src/shaders.rs +++ /dev/null @@ -1,10 +0,0 @@ -use std::path::Path; - -use glfw::Glfw; - -pub fn init_shader( - glfw: &Glfw, - vs_path: impl AsRef, - fs_path: impl AsRef, -) { -} diff --git a/assignment-2a/CMakeLists.txt b/assignment-2a/CMakeLists.txt index e115069..6381383 100755 --- a/assignment-2a/CMakeLists.txt +++ b/assignment-2a/CMakeLists.txt @@ -35,10 +35,11 @@ add_subdirectory(ext/glfw) # Make a list of all the source files set( SOURCES - src/main.cpp + ext/glad/src/glad.c + + src/HW2a.cpp src/controls.cpp src/util.cpp - ext/glad/src/glad.c ) # Make a list of all the header files (optional-- only necessary to make them appear in IDE) diff --git a/assignment-2a/src/main.cpp b/assignment-2a/src/HW2a.cpp similarity index 94% rename from assignment-2a/src/main.cpp rename to assignment-2a/src/HW2a.cpp index 1a8a5ee..68f81db 100755 --- a/assignment-2a/src/main.cpp +++ b/assignment-2a/src/HW2a.cpp @@ -11,10 +11,6 @@ #include #include -#define DEBUG_ON \ - 0 // repetitive of the debug flag in the shader loading code, included here - // for clarity only - #include "shaders.h" #include "controls.h" @@ -192,11 +188,12 @@ int main(int argc, char **argv) { } // sanity check that your matrix contents are what you expect them to be - spdlog::debug( - "M = [{} {} {} {}\n {} {} {} {}\n {} {} {} {}\n {} {} " - "{} {}]\n", - M[0], M[4], M[8], M[12], M[1], M[5], M[9], M[13], M[2], M[6], M[10], - M[14], M[3], M[7], M[11], M[15]); + spdlog::debug("M = [{} {} {} {}\n" + " {} {} {} {}\n" + " {} {} {} {}\n" + " {} {} {} {}]\n", + M[0], M[4], M[8], M[12], M[1], M[5], M[9], M[13], M[2], M[6], + M[10], M[14], M[3], M[7], M[11], M[15]); // send the updated model transformation matrix to the GPU glUniformMatrix4fv(m_location, 1, GL_FALSE, M); diff --git a/assignment-2a/src/state.cpp b/assignment-2a/src/state.cpp new file mode 100644 index 000000000..e69de29 diff --git a/assignment-2a/src/state.h b/assignment-2a/src/state.h new file mode 100644 index 000000000..2045bf1 --- /dev/null +++ b/assignment-2a/src/state.h @@ -0,0 +1,9 @@ +#ifndef STATE_H_ +#define STATE_H_ + +/// The state of the program +struct State { + int mouse_x, mouse_y; +}; + +#endif