summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/dw.rs2
-rw-r--r--source/dw/app.rs4
-rw-r--r--source/dw/app/getshdprg.rs42
-rw-r--r--source/dw/app/ini.rs8
-rw-r--r--source/dw/app/inigfx.rs14
-rw-r--r--source/dw/app/inisig.rs12
-rw-r--r--source/dw/app/lop.rs48
-rw-r--r--source/dw/app/shader/main.frag.glsl2
-rw-r--r--source/dw/app/shader/main.vert.glsl2
9 files changed, 87 insertions, 47 deletions
diff --git a/source/dw.rs b/source/dw.rs
index 409368e..3905727 100644
--- a/source/dw.rs
+++ b/source/dw.rs
@@ -8,7 +8,7 @@ pub struct VerTyp {
pub const VER: VerTyp = VerTyp {
maj: 0x0,
- min: 0x1,
+ min: 0x2,
pat: 0x0,
};
diff --git a/source/dw/app.rs b/source/dw/app.rs
index 14b2292..ffd44fb 100644
--- a/source/dw/app.rs
+++ b/source/dw/app.rs
@@ -3,12 +3,12 @@
extern crate glfw;
use gl::types::GLuint;
-use glfw::{Glfw,Window,WindowEvent};
+use glfw::{Glfw, Window, WindowEvent};
use std::sync::atomic::AtomicBool;
use std::sync::mpsc::Receiver;
pub struct Gfx {
- evt: Receiver<(f64,WindowEvent)>,
+ evt: Receiver<(f64, WindowEvent)>,
glfw: Glfw,
shdprg: GLuint,
win: Window,
diff --git a/source/dw/app/getshdprg.rs b/source/dw/app/getshdprg.rs
index 76eb5cf..2da6095 100644
--- a/source/dw/app/getshdprg.rs
+++ b/source/dw/app/getshdprg.rs
@@ -1,15 +1,15 @@
// Copyright 2023 Gabriel Jensen.
-use crate::dw::{app::App,datpth};
+use crate::dw::app::App;
extern crate gl;
-use gl::{AttachShader,COMPILE_STATUS,CompileShader,COMPUTE_SHADER,CreateProgram,CreateShader,DeleteShader,FALSE,FRAGMENT_SHADER,GEOMETRY_SHADER,GetShaderInfoLog,GetShaderiv,INFO_LOG_LENGTH,LinkProgram,ShaderSource,TESS_CONTROL_SHADER,TESS_EVALUATION_SHADER,VERTEX_SHADER};
-use gl::types::{GLchar,GLenum,GLint,GLsizei,GLuint};
-use libc::{STDERR_FILENO,write};
-use std::alloc::{alloc,dealloc,Layout};
+use gl::{AttachShader, COMPILE_STATUS, CompileShader, COMPUTE_SHADER, CreateProgram, CreateShader, DeleteShader, FALSE, FRAGMENT_SHADER, GEOMETRY_SHADER, GetShaderInfoLog, GetShaderiv, INFO_LOG_LENGTH, LinkProgram, ShaderSource, TESS_CONTROL_SHADER, TESS_EVALUATION_SHADER, VERTEX_SHADER};
+use gl::types::{GLchar, GLint, GLsizei, GLuint};
+use libc::{STDERR_FILENO, write};
+use std::alloc::{alloc, dealloc, Layout};
use std::ffi::c_void;
-use std::ptr::{addr_of,null};
+use std::ptr::{addr_of, null};
impl App {
pub fn getshdprg(&mut self) -> GLuint {
@@ -25,7 +25,7 @@ impl App {
"tesc" => TESS_CONTROL_SHADER,
"tese" => TESS_EVALUATION_SHADER,
"vert" => VERTEX_SHADER,
- _ => panic!("invalid shader file extension \"{}\"",filext),
+ _ => panic!("invalid shader file extension \"{}\"", filext),
};
let typstr = match typ {
@@ -34,13 +34,7 @@ impl App {
_ => unreachable!(),
};
- let filext = match typ {
- FRAGMENT_SHADER => "frag",
- VERTEX_SHADER => "vert",
- _ => unreachable!(),
- };
-
- eprintln!("compiling {} shader \"{}\"",typstr,nam);
+ eprintln!("compiling {} shader \"{}\"", typstr, nam);
//let src = read(pth).expect("unable to read shader at");
let src = match nam {
@@ -52,26 +46,26 @@ impl App {
unsafe {
let shd = CreateShader(typ);
let srcptr = src.as_ptr();
- ShaderSource(shd,0x1,addr_of!(srcptr) as *const *const GLchar,null::<GLint>());
+ ShaderSource(shd, 0x1, addr_of!(srcptr) as *const *const GLchar, null::<GLint>());
CompileShader(shd);
- let mut sts:GLint = 0x0;
- GetShaderiv(shd,COMPILE_STATUS,&mut sts);
+ let mut sts: GLint = 0x0;
+ GetShaderiv(shd, COMPILE_STATUS, &mut sts);
if sts == FALSE as GLint {
let mut len: GLint = 0x0;
- GetShaderiv(shd,INFO_LOG_LENGTH,&mut len);
+ GetShaderiv(shd, INFO_LOG_LENGTH, &mut len);
- let lay = Layout::from_size_align(len as usize,0x1).unwrap();
+ let lay = Layout::from_size_align(len as usize, 0x1).unwrap();
let log = alloc(lay);
- GetShaderInfoLog(shd,len,null::<GLsizei>() as *mut GLsizei,log as *mut GLchar);
+ GetShaderInfoLog(shd, len, null::<GLsizei>() as *mut GLsizei, log as *mut GLchar);
eprint!("unable able to compile shader:\n");
- write(STDERR_FILENO,log as *const c_void,len as usize);
+ write(STDERR_FILENO, log as *const c_void, len as usize);
eprintln!();
- dealloc(log,lay);
+ dealloc(log, lay);
panic!("unable to compile shader");
}
@@ -85,8 +79,8 @@ impl App {
unsafe {
let prg = CreateProgram();
- AttachShader(prg,frgshd);
- AttachShader(prg,vtxshd);
+ AttachShader(prg, frgshd);
+ AttachShader(prg, vtxshd);
LinkProgram(prg);
DeleteShader(frgshd);
diff --git a/source/dw/app/ini.rs b/source/dw/app/ini.rs
index 5e39556..f498538 100644
--- a/source/dw/app/ini.rs
+++ b/source/dw/app/ini.rs
@@ -1,15 +1,15 @@
// Copyright 2023 Gabriel Jensen.
use crate::dw::app::App;
-use crate::dw::{datpth,VER};
+use crate::dw::{datpth, VER};
extern crate glfw;
impl App {
pub fn ini(&mut self) -> i8 {
- println!("\x1B[0m\x1B[1mDeltaWorld\x1B[0m {}.{}.{} \u{2014} Copyright 2023 \x1B[0m\x1B[1mGabriel Jensen\x1B[0m.\n",VER.maj,VER.min,VER.pat);
+ println!("\x1B[0m\x1B[1mDeltaWorld\x1B[0m {}.{}.{} \u{2014} Copyright 2023 \x1B[0m\x1B[1mGabriel Jensen\x1B[0m.\n", VER.maj, VER.min, VER.pat);
- eprintln!("data directory at \"{}\"",datpth());
+ eprintln!("data directory at \"{}\"", datpth());
self.inisig();
@@ -18,7 +18,7 @@ impl App {
let cod = self.lop(&mut gfx);
println!("goodbye");
- eprintln!("exiting with code {}",cod);
+ eprintln!("exiting with code {}", cod);
return cod;
}
}
diff --git a/source/dw/app/inigfx.rs b/source/dw/app/inigfx.rs
index 9760ded..5444b10 100644
--- a/source/dw/app/inigfx.rs
+++ b/source/dw/app/inigfx.rs
@@ -1,11 +1,13 @@
// Copyright 2023 Gabriel Jensen.
-use crate::dw::app::{App,Gfx};
+use crate::dw::VER;
+use crate::dw::app::{App, Gfx};
extern crate gl;
extern crate glfw;
-use glfw::{Context};
+use gl::load_with;
+use glfw::{Context, SwapInterval};
use std::ffi::c_void;
impl App {
@@ -14,17 +16,19 @@ impl App {
let mut glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap();
eprintln!("creating window");
- glfw.window_hint(glfw::WindowHint::ContextVersion(0x3,0x2));
+ glfw.window_hint(glfw::WindowHint::ContextVersion(0x3, 0x2));
glfw.window_hint(glfw::WindowHint::OpenGlProfile(glfw::OpenGlProfileHint::Core));
glfw.window_hint(glfw::WindowHint::Samples(Some(0x8)));
- let (mut win,evt) = glfw.create_window(0x400,0x300,"dw",glfw::WindowMode::Windowed).expect("unable to create window");
+ let (mut win, evt) = glfw.create_window(0x400, 0x300, format!("DeltaWorld {}.{}.{}", VER.maj, VER.min, VER.pat).as_str(), glfw::WindowMode::Windowed).expect("unable to create window");
win.set_key_polling(true);
win.make_current();
eprintln!("initialising opengl");
- gl::load_with(|nam| glfw.get_proc_address_raw(nam) as *const c_void);
+ load_with(|nam| glfw.get_proc_address_raw(nam) as *const c_void);
+
+ glfw.set_swap_interval(SwapInterval::Sync(0x1));
let shdprg = self.getshdprg();
diff --git a/source/dw/app/inisig.rs b/source/dw/app/inisig.rs
index 12e8061..5c951ab 100644
--- a/source/dw/app/inisig.rs
+++ b/source/dw/app/inisig.rs
@@ -1,18 +1,18 @@
// Copyright 2023 Gabriel Jensen.
-use crate::dw::app::{App,GOTINT};
+use crate::dw::app::{App, GOTINT};
extern crate libc;
-use libc::{c_int,sighandler_t,signal,SIGINT,SIGTERM};
+use libc::{c_int, sighandler_t, signal, SIGINT, SIGTERM};
use std::mem::transmute;
use std::sync::atomic::Ordering;
fn hnd(sig: c_int) {
unsafe {
- signal(sig,transmute::<fn(c_int),sighandler_t>(hnd));
+ signal(sig, transmute::<fn(c_int), sighandler_t>(hnd));
- GOTINT.store(true,Ordering::Relaxed);
+ GOTINT.store(true, Ordering::Relaxed);
}
}
@@ -21,8 +21,8 @@ impl App {
eprintln!("initialising signal handlers");
unsafe {
- signal(SIGINT, transmute::<fn(c_int),sighandler_t>(hnd));
- signal(SIGTERM,transmute::<fn(c_int),sighandler_t>(hnd));
+ signal(SIGINT, transmute::<fn(c_int), sighandler_t>(hnd));
+ signal(SIGTERM, transmute::<fn(c_int), sighandler_t>(hnd));
}
}
}
diff --git a/source/dw/app/lop.rs b/source/dw/app/lop.rs
index 928ddf1..16f6e5a 100644
--- a/source/dw/app/lop.rs
+++ b/source/dw/app/lop.rs
@@ -1,17 +1,45 @@
// Copyright 2023 Gabriel Jensen.
-use crate::dw::app::{App,GOTINT};
+use crate::dw::app::{App, GOTINT};
use crate::dw::app::Gfx;
-//extern crate gl;
+extern crate gl;
extern crate glfw;
+use gl::{ARRAY_BUFFER, BindBuffer, BufferData, BindVertexArray, BufferSubData, Clear, ClearColor, COLOR_BUFFER_BIT, DrawArrays, EnableVertexAttribArray, FALSE, FLOAT, GenBuffers, GenVertexArrays, STREAM_DRAW, TRIANGLES, UseProgram, VertexAttribPointer};
+use gl::types::{GLfloat, GLsizeiptr, GLuint};
+use glfw::Context;
+use std::ffi::c_void;
+use std::mem::{size_of, size_of_val};
+use std::ptr::{addr_of, null};
use std::sync::atomic::Ordering;
impl App {
- pub fn lop(&mut self,gfx: &mut Gfx) -> i8 {
+ pub fn lop(&mut self, gfx: &mut Gfx) -> i8 {
eprintln!("entering main loop");
+ let vtx: [GLfloat; 0x9] = [
+ -1.0, 1.0, 0.0,
+ 1.0, 1.0, 0.0,
+ 0.0, 0.0, 0.0,
+ ];
+
+ let mut vao: GLuint = 0x0;
+ let mut vbo: GLuint = 0x0;
+
+ unsafe {
+ GenVertexArrays(0x1,&mut vao);
+ GenBuffers(0x1,&mut vbo);
+
+ BindVertexArray(vao);
+
+ BindBuffer(ARRAY_BUFFER,vbo);
+ BufferData(ARRAY_BUFFER,size_of_val(& vtx) as GLsizeiptr, addr_of!(vtx) as *const c_void, STREAM_DRAW);
+
+ VertexAttribPointer(0x0, 0x3, FLOAT, FALSE, (0x3*size_of::<GLfloat>()) as i32, null::<c_void>());
+ EnableVertexAttribArray(0x0);
+ }
+
while !gfx.win.should_close() {
unsafe {
if GOTINT.load(Ordering::Relaxed) {
@@ -21,6 +49,20 @@ impl App {
}
gfx.glfw.poll_events();
+
+ unsafe {
+ ClearColor(0.25, 0.0, 0.0, 1.0);
+ Clear(COLOR_BUFFER_BIT);
+
+ BindBuffer(ARRAY_BUFFER, vbo);
+ BufferSubData(ARRAY_BUFFER, 0x0, size_of_val(& vtx) as GLsizeiptr, addr_of!(vtx) as *const c_void);
+
+ UseProgram(gfx.shdprg);
+ BindVertexArray(vao);
+ DrawArrays(TRIANGLES, 0x0, 0x3*0x1);
+ }
+
+ gfx.win.swap_buffers();
}
return -0x45;
diff --git a/source/dw/app/shader/main.frag.glsl b/source/dw/app/shader/main.frag.glsl
index 201ce9f..410b362 100644
--- a/source/dw/app/shader/main.frag.glsl
+++ b/source/dw/app/shader/main.frag.glsl
@@ -3,5 +3,5 @@
out vec4 col;
void main() {
- col = vec4(0.7137f,0.0941f,0.2000f,1.0f);
+ col = vec4(0.7137f, 0.0941f, 0.2000f, 1.0f);
}
diff --git a/source/dw/app/shader/main.vert.glsl b/source/dw/app/shader/main.vert.glsl
index fb6999c..a60e9ca 100644
--- a/source/dw/app/shader/main.vert.glsl
+++ b/source/dw/app/shader/main.vert.glsl
@@ -3,5 +3,5 @@
in vec3 pos;
void main() {
- gl_Position = vec4(pos.x,pos.y,pos.z,1.0f);
+ gl_Position = vec4(pos.x, pos.y, pos.z, 1.0f);
}