housekeeping for assignment 2a
This commit is contained in:
parent
62a1e102cd
commit
9484e91166
11 changed files with 18 additions and 112 deletions
7
assignment-2a-rust/Cargo.lock
generated
7
assignment-2a-rust/Cargo.lock
generated
|
@ -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"
|
|
|
@ -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"
|
|
|
@ -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
|
|
||||||
}
|
|
|
@ -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
|
|
||||||
}
|
|
|
@ -1,3 +0,0 @@
|
||||||
pub fn init() {
|
|
||||||
|
|
||||||
}
|
|
|
@ -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)
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,10 +0,0 @@
|
||||||
use std::path::Path;
|
|
||||||
|
|
||||||
use glfw::Glfw;
|
|
||||||
|
|
||||||
pub fn init_shader(
|
|
||||||
glfw: &Glfw,
|
|
||||||
vs_path: impl AsRef<Path>,
|
|
||||||
fs_path: impl AsRef<Path>,
|
|
||||||
) {
|
|
||||||
}
|
|
|
@ -35,10 +35,11 @@ add_subdirectory(ext/glfw)
|
||||||
# Make a list of all the source files
|
# Make a list of all the source files
|
||||||
set(
|
set(
|
||||||
SOURCES
|
SOURCES
|
||||||
src/main.cpp
|
ext/glad/src/glad.c
|
||||||
|
|
||||||
|
src/HW2a.cpp
|
||||||
src/controls.cpp
|
src/controls.cpp
|
||||||
src/util.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)
|
# Make a list of all the header files (optional-- only necessary to make them appear in IDE)
|
||||||
|
|
|
@ -11,10 +11,6 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define DEBUG_ON \
|
|
||||||
0 // repetitive of the debug flag in the shader loading code, included here
|
|
||||||
// for clarity only
|
|
||||||
|
|
||||||
#include "shaders.h"
|
#include "shaders.h"
|
||||||
|
|
||||||
#include "controls.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
|
// sanity check that your matrix contents are what you expect them to be
|
||||||
spdlog::debug(
|
spdlog::debug("M = [{} {} {} {}\n"
|
||||||
"M = [{} {} {} {}\n {} {} {} {}\n {} {} {} {}\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],
|
" {} {} {} {}]\n",
|
||||||
M[14], M[3], M[7], M[11], M[15]);
|
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
|
// send the updated model transformation matrix to the GPU
|
||||||
glUniformMatrix4fv(m_location, 1, GL_FALSE, M);
|
glUniformMatrix4fv(m_location, 1, GL_FALSE, M);
|
0
assignment-2a/src/state.cpp
Normal file
0
assignment-2a/src/state.cpp
Normal file
9
assignment-2a/src/state.h
Normal file
9
assignment-2a/src/state.h
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#ifndef STATE_H_
|
||||||
|
#define STATE_H_
|
||||||
|
|
||||||
|
/// The state of the program
|
||||||
|
struct State {
|
||||||
|
int mouse_x, mouse_y;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in a new issue