Forking Around
This commit is contained in:
@@ -30,7 +30,7 @@ CPMAddPackage(NAME ReWindow
|
||||
URL https://git.redacted.cc/Redacted/ReWindow/archive/Prerelease-32.zip)
|
||||
|
||||
CPMAddPackage(NAME JGL
|
||||
URL https://git.redacted.cc/josh/JGL/archive/Prerelease-53.zip)
|
||||
URL https://git.redacted.cc/josh/JGL/archive/Prerelease-54.zip)
|
||||
|
||||
CPMAddPackage(NAME JUI
|
||||
URL https://git.redacted.cc/josh/ReJUI/archive/Prerelease-5.16.zip)
|
||||
|
29
main.cpp
29
main.cpp
@@ -1,4 +1,5 @@
|
||||
#include <iostream>
|
||||
#include <JGL/logger/logger.h>
|
||||
#include <ReWindow/types/Window.h>
|
||||
#include <JUI/Widgets/Scene.hpp>
|
||||
#include <JUI/Widgets/Window.hpp>
|
||||
@@ -23,9 +24,18 @@ public:
|
||||
JUI::Scene* scene;
|
||||
JUI::CommandLine* console;
|
||||
JGL::Shader shader;
|
||||
float accumulated_time;
|
||||
|
||||
ReShaderProgram() : ReWindow::OpenGLWindow("ReShader", 1080, 720, 2, 1) {
|
||||
shader = Shader(std::filesystem::path("../shaders/test.vert.glsl"), std::filesystem::path("../shaders/test.frag.glsl"));
|
||||
Shader::OnCompilationErrorMessage += [this] (std::string type, std::string infoLog) {
|
||||
auto log_lines = string_expand(infoLog, '\n');
|
||||
console->Log(type, Colors::Red);
|
||||
for (auto line : log_lines) {
|
||||
console->Log(line, Colors::Red);
|
||||
}
|
||||
};
|
||||
|
||||
accumulated_time = 0;
|
||||
}
|
||||
|
||||
void ReloadShader()
|
||||
@@ -53,7 +63,6 @@ public:
|
||||
ReloadShader();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
bool Open() override
|
||||
@@ -73,6 +82,8 @@ public:
|
||||
scene = new JUI::Scene();
|
||||
CreateMenu();
|
||||
|
||||
shader = Shader(std::filesystem::path("../shaders/test.vert.glsl"), std::filesystem::path("../shaders/test.frag.glsl"));
|
||||
|
||||
return true;
|
||||
}
|
||||
void PropagateWindowSize() {
|
||||
@@ -83,6 +94,13 @@ public:
|
||||
}
|
||||
void Update(float elapsed) {
|
||||
scene->Update(elapsed);
|
||||
|
||||
accumulated_time += elapsed;
|
||||
|
||||
Vector2 u_res = Vector2(GetSize().x, GetSize().y);
|
||||
|
||||
shader.SetVector2("u_resolution", u_res);
|
||||
shader.SetFloat("u_time", accumulated_time);
|
||||
}
|
||||
void Draw() {
|
||||
Shader::UseDefault();
|
||||
@@ -92,14 +110,17 @@ public:
|
||||
|
||||
|
||||
shader.Use();
|
||||
JGL::J2D::FillRect(Colors::White, {0, 0}, Vector2(GetSize().x, GetSize().y));
|
||||
JGL::J2D::Begin();
|
||||
|
||||
JGL::J2D::FillRect(Colors::Gray, {0, 0}, Vector2(GetSize().x, GetSize().y));
|
||||
JGL::J2D::End();
|
||||
Shader::UseDefault();
|
||||
scene->Draw();
|
||||
|
||||
}
|
||||
void OnRefresh(float elapsed) override {
|
||||
Update(elapsed);
|
||||
PropagateWindowSize();
|
||||
Update(elapsed);
|
||||
Draw();
|
||||
this->SwapBuffers();
|
||||
}
|
||||
|
@@ -4,47 +4,20 @@
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
attribute vec4 gl_Color;
|
||||
|
||||
uniform vec2 u_resolution;
|
||||
uniform float u_time;
|
||||
|
||||
vec3 rgb2hsb( in vec3 c ){
|
||||
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
|
||||
vec4 p = mix(vec4(c.bg, K.wz),
|
||||
vec4(c.gb, K.xy),
|
||||
step(c.b, c.g));
|
||||
vec4 q = mix(vec4(p.xyw, c.r),
|
||||
vec4(c.r, p.yzx),
|
||||
step(p.x, c.r));
|
||||
float d = q.x - min(q.w, q.y);
|
||||
float e = 1.0e-10;
|
||||
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)),
|
||||
d / (q.x + e),
|
||||
q.x);
|
||||
}
|
||||
vec3 colorA = vec3(0.649,0.241,0.912);
|
||||
vec3 colorB = vec3(0.000,0.833,0.224);
|
||||
|
||||
// Function from Iñigo Quiles
|
||||
// https://www.shadertoy.com/view/MsS3Wc
|
||||
vec3 hsb2rgb( in vec3 c ){
|
||||
vec3 rgb = clamp(abs(mod(c.x*6.0+vec3(0.0,4.0,2.0),
|
||||
6.0)-3.0)-1.0,
|
||||
0.0,
|
||||
1.0 );
|
||||
rgb = rgb*rgb*(3.0-2.0*rgb);
|
||||
return c.z * mix(vec3(1.0), rgb, c.y);
|
||||
}
|
||||
|
||||
void main(){
|
||||
vec2 st = gl_FragCoord.xy/u_resolution;
|
||||
void main() {
|
||||
vec3 color = vec3(0.0);
|
||||
|
||||
// We map x (0.0 - 1.0) to the hue (0.0 - 1.0)
|
||||
// And the y (0.0 - 1.0) to the brightness
|
||||
color = hsb2rgb(vec3(st.x,1.0,st.y));
|
||||
float pct = abs(sin(u_time));
|
||||
|
||||
// Mix uses pct (a value from 0-1) to
|
||||
// mix the two colors
|
||||
color = mix(colorA, colorB, pct);
|
||||
|
||||
gl_FragColor = vec4(color,1.0);
|
||||
|
||||
|
||||
gl_FragColor = gl_Color;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user