summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--shaders/test.fs103
-rw-r--r--src/main.zig32
2 files changed, 132 insertions, 3 deletions
diff --git a/shaders/test.fs b/shaders/test.fs
new file mode 100644
index 0000000..44a912e
--- /dev/null
+++ b/shaders/test.fs
@@ -0,0 +1,103 @@
+#version 330
+/*
+//if ((pix % 3) == 2)
+//black pixel
+//else
+//get color of floor(pix / 3)
+//end
+
+//uniform vec2 resolution;
+//uniform sampler2D backbuffer;
+//
+//void main( void ) {
+// vec2 position = ( gl_FragCoord.xy / resolution.xy );
+// vec4 color = texture2D(backbuffer, position);
+// // ... do something with it ...
+//}
+
+
+// Input vertex attributes (from vertex shader)
+in vec2 fragTexCoord;
+in vec4 fragColor;
+
+// Input uniform values
+uniform sampler2D texture0;
+uniform vec4 colDiffuse;
+
+// Output fragment color
+out vec4 finalColor;
+
+// NOTE: Add here your custom variables
+
+// NOTE: Render size values should be passed from code
+uniform float renderWidth = 800;
+uniform float renderHeight = 450;
+
+float radius = 250.0;
+float angle = 0.8;
+
+uniform vec2 center = vec2(200.0, 200.0);
+
+void main()
+{
+ //vec2 newcoord = vec2(fragTexCoord.x + 10, fragTexCoord.y + 10);
+ //vec2 position = ( mod(gl_FragCoord.x,3), mod(gl_FragCoord.y, 3) );
+ //if ( position.x == 2 ) || ( position.y == 2 )
+ //{
+ // gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );
+ //}
+ //else
+ //{
+ // vec2 position_new = (floor(gl_FragCoord.xy));
+ // gl_FragColor = texture2D(texture0, position_new);
+ //}
+ //gl_FragColor = vec4(0.5, 0.5, 0.5, 1.0);
+
+ vec2 p = fragTexCoord;
+ p.x = fragTexCoord.x + 100000;
+
+
+ gl_FragColor = texture(texture0, p);
+}
+*/
+
+
+// Input vertex attributes (from vertex shader)
+in vec2 fragTexCoord;
+in vec4 fragColor;
+
+// Input uniform values
+uniform sampler2D texture0;
+uniform vec4 colDiffuse;
+
+// Output fragment color
+out vec4 finalColor;
+
+// NOTE: Add here your custom variables
+vec2 textureResolution = vec2(64.0*3.0, 32.0*3.0);
+vec2 onePixel = vec2(1.0, 1.0) / textureResolution;
+vec2 pixelCoor = fragTexCoord * textureResolution;
+
+void main()
+{
+ vec4 texelColor = vec4(0.0, 0.0, 0.0, 0.0);
+ // Texel color fetching from texture sampler
+ if ((mod(floor(pixelCoor.x), 3) == 2.0) || (mod(floor(pixelCoor.y), 3) == 2.0))
+ {
+ texelColor = vec4(0.0, 0.0, 0.0, 1.0);
+ }
+ else {
+ pixelCoor.y = -pixelCoor.y;
+ pixelCoor = pixelCoor / 3.0;
+ texelColor = texture(texture0, (pixelCoor /textureResolution));
+ }
+//if ((pix % 3) == 2)
+//black pixel
+//else
+//get color of floor(pix / 3)
+//end
+
+ // NOTE: Implement here your fragment shader code
+
+ finalColor = texelColor*colDiffuse;
+}
diff --git a/src/main.zig b/src/main.zig
index ad7a8e8..608b67f 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -12,6 +12,12 @@ const screenHeight: u32 = (32 * 10) + 24;
const RndGen = std.rand.DefaultPrng;
var Rnd = RndGen.init(0);
var chip8_screen: ray.RenderTexture = undefined;
+var shader: ray.Shader = undefined;
+var swirl_center_loc: c_int = undefined;
+var renderPoint_renderWidth: c_int = undefined;
+var renderPoint_renderHeight: c_int = undefined;
+
+var swirl_center = [_]u32{ screenWidth / 2, screenHeight / 2 };
const Chip8 = struct {
opcode: u16 = 0,
@@ -148,7 +154,7 @@ var chip8 = Chip8.new();
pub fn main() !void {
setup_graphics();
- defer ray.CloseWindow();
+ defer close_graphics();
var exitWindow: bool = false;
const execute_delay = 4;
var delay: u32 = 0;
@@ -187,10 +193,28 @@ fn get_coords(x: u32, y: u32) u32 {
fn setup_graphics() void {
ray.InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
- chip8_screen = ray.LoadRenderTexture(64, 32);
+ chip8_screen = ray.LoadRenderTexture(64 * 3, 32 * 3);
+ //shader = ray.LoadShader(0, "shaders/glsl330/swirl.fs");
+ shader = ray.LoadShader(0, "shaders/test.fs");
+ //swirl_center_loc = ray.GetShaderLocation(shader, "center");
+ renderPoint_renderHeight = ray.GetShaderLocation(shader, "renderHeight");
+ renderPoint_renderWidth = ray.GetShaderLocation(shader, "renderWidth");
+ var renderVar_renderWidth: f32 = @intToFloat(f32, chip8_screen.texture.width);
+ var renderVar_renderHeight: f32 = @intToFloat(f32, chip8_screen.texture.height);
+ //ray.SetShaderValue(shader, swirl_center_loc, swirlCenter, ray.SHADER_UNIFORM_VEC2);
+ //const shaderwidth: c_ = @intToFloat(c_float, chip8_screen.texture.width
+ //ray.SetShaderValue(shader, renderPoint_renderWidth, &chip8_screen.texture.width, ray.SHADER_UNIFORM_FLOAT);
+ ray.SetShaderValue(shader, renderPoint_renderWidth, &renderVar_renderWidth, ray.SHADER_UNIFORM_FLOAT);
+ ray.SetShaderValue(shader, renderPoint_renderHeight, &renderVar_renderHeight, ray.SHADER_UNIFORM_FLOAT);
+ //ray.SetShaderValue(shader, renderPoint_renderHeight, chip8_screen.texture.height, ray.SHADER_UNIFORM_FLOAT);
ray.SetTargetFPS(60);
}
+fn close_graphics() void {
+ ray.UnloadShader(shader);
+ ray.CloseWindow();
+}
+
fn update_screen(screen: *ray.RenderTexture, pixels: [2048]bool) void {
ray.ClearBackground(ray.RAYWHITE);
ray.BeginTextureMode(screen.*);
@@ -206,12 +230,14 @@ fn update_screen(screen: *ray.RenderTexture, pixels: [2048]bool) void {
ray.DrawRectangleRec(ray.Rectangle{ .x = @intToFloat(f32, @mod(index, 64)), .y = @intToFloat(f32, (index / 64)), .width = 1, .height = 1 }, ray.Color{ .r = on, .g = on, .b = on, .a = 255 });
}
ray.EndTextureMode();
+ ray.BeginShaderMode(shader);
ray.DrawTexturePro(
screen.texture,
- ray.Rectangle{ .x = 0, .y = 0, .width = 64, .height = -32 },
+ ray.Rectangle{ .x = 0, .y = 0, .width = @intToFloat(f32, screen.texture.width), .height = @intToFloat(f32, screen.texture.height) },
ray.Rectangle{ .x = 0, .y = 24, .width = 64 * 10, .height = 32 * 10 },
ray.Vector2{ .x = 0, .y = 0 },
0,
ray.WHITE,
);
+ ray.EndShaderMode();
}