summaryrefslogtreecommitdiff
path: root/source/dw
diff options
context:
space:
mode:
Diffstat (limited to 'source/dw')
-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
4 files changed, 25 insertions, 11 deletions
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);
}