summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Jensen2023-05-22 20:19:18 +0200
committerGabriel Jensen2023-05-22 20:19:18 +0200
commitad4f8d453c7ffcec38853090766e6170c4cc49d4 (patch)
tree715dc0483a5f2e7b6801abf532e48133355e10c7
parent4505770fd5758ce222ce9aecef09b6fd695c7f35 (diff)
Animate screen;HEADmaster
-rw-r--r--CHANGELOG.txt2
-rw-r--r--source/dw.rs10
-rw-r--r--source/dw/app.rs3
-rw-r--r--source/dw/app/inigfx.rs16
-rw-r--r--source/dw/app/lop.rs13
-rw-r--r--source/dw/app/shader/main.vert.glsl4
6 files changed, 32 insertions, 16 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index a98dcf8..903cc54 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -4,6 +4,8 @@
* Free resources;
+* Animate screen;
+
# 0.2.0
* Embed shaders;
diff --git a/source/dw.rs b/source/dw.rs
index 70ac3f8..e4be423 100644
--- a/source/dw.rs
+++ b/source/dw.rs
@@ -1,12 +1,12 @@
// Copyright 2023 Gabriel Jensen.
-pub struct VerTyp {
- pub maj: u64,
- pub min: u64,
- pub pat: u64,
+pub struct Vertyp<T> {
+ pub maj: T,
+ pub min: T,
+ pub pat: T,
}
-pub const VER: VerTyp = VerTyp {
+pub const VER: Vertyp::<u64> = Vertyp::<u64> {
maj: 0x0,
min: 0x3,
pat: 0x0,
diff --git a/source/dw/app.rs b/source/dw/app.rs
index 3fbc61f..b71be85 100644
--- a/source/dw/app.rs
+++ b/source/dw/app.rs
@@ -2,7 +2,7 @@
extern crate glfw;
-use gl::types::GLuint;
+use gl::types::{GLint, GLuint};
use glfw::{Glfw, Window, WindowEvent};
use std::sync::atomic::AtomicBool;
use std::sync::mpsc::Receiver;
@@ -11,6 +11,7 @@ pub struct Gfx {
evt: Receiver<(f64, WindowEvent)>,
glfw: Glfw,
shdprg: GLuint,
+ uni: GLint,
win: Window,
}
diff --git a/source/dw/app/inigfx.rs b/source/dw/app/inigfx.rs
index d137c5a..ab21245 100644
--- a/source/dw/app/inigfx.rs
+++ b/source/dw/app/inigfx.rs
@@ -6,7 +6,8 @@ use crate::dw::app::{App, Gfx};
extern crate gl;
extern crate glfw;
-use gl::load_with;
+use gl::{GetUniformLocation, load_with};
+use gl::types::{GLchar, GLint};
use glfw::{Context, FAIL_ON_ERRORS, init, SwapInterval, WindowHint};
use std::ffi::c_void;
@@ -31,11 +32,16 @@ impl App {
let shdprg = self.getshdprg();
+ let uni: GLint = unsafe {
+ GetUniformLocation(shdprg, b"scl\x00".as_ptr() as *const GLchar)
+ };
+
return Gfx {
- evt: evt,
- glfw: glfw,
- shdprg:shdprg,
- win: win,
+ evt: evt,
+ glfw: glfw,
+ shdprg: shdprg,
+ uni: uni,
+ win: win,
};
}
}
diff --git a/source/dw/app/lop.rs b/source/dw/app/lop.rs
index 0a8f36b..1ffe764 100644
--- a/source/dw/app/lop.rs
+++ b/source/dw/app/lop.rs
@@ -6,7 +6,7 @@ use crate::dw::app::Gfx;
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, Viewport};
+use gl::{ARRAY_BUFFER, BindBuffer, BufferData, BindVertexArray, BufferSubData, Clear, ClearColor, COLOR_BUFFER_BIT, DrawArrays, EnableVertexAttribArray, FALSE, FLOAT, GenBuffers, GenVertexArrays, STREAM_DRAW, TRIANGLES, Uniform1f, UseProgram, VertexAttribPointer, Viewport};
use gl::types::{GLfloat, GLsizeiptr, GLuint};
use glfw::Context;
use std::ffi::c_void;
@@ -19,9 +19,9 @@ impl App {
eprintln!("entering main loop");
let vtx: [GLfloat; 0x9] = [
- -0.707,-0.707, -0.707,
- -0.707, 0.707, -0.707,
- 0.707,-0.707, -0.707,
+ -1.0,-1.0,0.0,
+ 1.0,-1.0,0.0,
+ -1.0, 1.0,0.0,
];
let mut vao: GLuint = 0x0;
@@ -40,6 +40,8 @@ impl App {
EnableVertexAttribArray(0x0);
}
+ gfx.glfw.set_time(0.0);
+
while !gfx.win.should_close() {
unsafe {
if GOTINT.load(Ordering::Relaxed) {
@@ -61,6 +63,9 @@ impl App {
BufferSubData(ARRAY_BUFFER, 0x0, size_of_val(& vtx) as GLsizeiptr, addr_of!(vtx) as *const c_void);
UseProgram(gfx.shdprg);
+
+ Uniform1f(gfx.uni,(gfx.glfw.get_time()/16.0).powf(2.0) as f32);
+
BindVertexArray(vao);
DrawArrays(TRIANGLES, 0x0, 0x3*0x1);
}
diff --git a/source/dw/app/shader/main.vert.glsl b/source/dw/app/shader/main.vert.glsl
index 16df6f0..0ab36c8 100644
--- a/source/dw/app/shader/main.vert.glsl
+++ b/source/dw/app/shader/main.vert.glsl
@@ -2,6 +2,8 @@
in vec3 pos;
+uniform float scl;
+
void main(void) {
- gl_Position = vec4(pos.x, pos.y, pos.z, 1.0f);
+ gl_Position = vec4(pos.x*scl, pos.y*scl, pos.z*scl, 1.0f);
}