custom shader
This commit is contained in:
parent
a797b13b8e
commit
d639db711f
27
assets/test.frag
Normal file
27
assets/test.frag
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#version 330
|
||||||
|
|
||||||
|
// Input vertex attributes (from vertex shader)
|
||||||
|
in vec3 vertexPos;
|
||||||
|
in vec2 fragTexCoord;
|
||||||
|
in vec4 fragColor;
|
||||||
|
|
||||||
|
// Input uniform values
|
||||||
|
uniform sampler2D texture0;
|
||||||
|
uniform sampler2D texture1;
|
||||||
|
uniform vec4 colDiffuse;
|
||||||
|
|
||||||
|
uniform float divider = 0.5;
|
||||||
|
|
||||||
|
out vec4 finalColor;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
// // Texel color fetching from texture sampler
|
||||||
|
// vec4 texelColor0 = texture(texture0, fragTexCoord);
|
||||||
|
// vec4 texelColor1 = texture(texture1, fragTexCoord);
|
||||||
|
|
||||||
|
// float x = fract(fragTexCoord.s);
|
||||||
|
// float final = smoothstep(divider - 0.1, divider + 0.1, x);
|
||||||
|
|
||||||
|
finalColor = vec4(fragTexCoord, 0.0, 1.0);
|
||||||
|
}
|
||||||
26
assets/test.vert
Normal file
26
assets/test.vert
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#version 330
|
||||||
|
|
||||||
|
// Input vertex attributes
|
||||||
|
in vec3 vertexPosition;
|
||||||
|
in vec2 vertexTexCoord;
|
||||||
|
in vec3 vertexNormal;
|
||||||
|
in vec4 vertexColor;
|
||||||
|
|
||||||
|
// Input uniform values
|
||||||
|
uniform mat4 mvp;
|
||||||
|
|
||||||
|
// Output vertex attributes (to fragment shader)
|
||||||
|
out vec2 fragTexCoord;
|
||||||
|
out vec4 fragColor;
|
||||||
|
|
||||||
|
// NOTE: Add your custom variables here
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
// Send vertex attributes to fragment shader
|
||||||
|
fragTexCoord = vertexTexCoord;
|
||||||
|
fragColor = vertexColor;
|
||||||
|
|
||||||
|
// Calculate final vertex position
|
||||||
|
gl_Position = mvp * vec4(vertexPosition, 1.0);
|
||||||
|
}
|
||||||
15
build.zig
15
build.zig
@ -5,7 +5,7 @@ pub fn build(b: *std.Build) void {
|
|||||||
const optimize = b.standardOptimizeOption(.{});
|
const optimize = b.standardOptimizeOption(.{});
|
||||||
|
|
||||||
const assets = b.addInstallDirectory(.{
|
const assets = b.addInstallDirectory(.{
|
||||||
.source_dir = .{ .src_path = .{ .owner = b, .sub_path = "assets" } },
|
.source_dir = b.path("assets"),
|
||||||
.install_dir = .bin,
|
.install_dir = .bin,
|
||||||
.install_subdir = "assets",
|
.install_subdir = "assets",
|
||||||
});
|
});
|
||||||
@ -61,7 +61,7 @@ pub fn build(b: *std.Build) void {
|
|||||||
.imports = &.{
|
.imports = &.{
|
||||||
.{ .name = "shared", .module = shared },
|
.{ .name = "shared", .module = shared },
|
||||||
},
|
},
|
||||||
}),
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
const server = b.addExecutable(.{
|
const server = b.addExecutable(.{
|
||||||
@ -76,6 +76,17 @@ pub fn build(b: *std.Build) void {
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// client.addCSourceFile(.{ .file = b.path("src/kb/kb_text_shape.h"), .language = .c, .flags = &.{"-DKB_TEXT_SHAPE_IMPLEMENTATION"} });
|
||||||
|
|
||||||
|
client.root_module.addCSourceFile(.{ .file = b.path("src/kb/kb_text_shape.h"), .language = .c, .flags = &.{"-DKB_TEXT_SHAPE_IMPLEMENTATION"} });
|
||||||
|
|
||||||
|
const kb_text_shape = b.addTranslateC(.{
|
||||||
|
.root_source_file = b.path("src/kb/kb_text_shape.h"),
|
||||||
|
.target = target,
|
||||||
|
.optimize = optimize,
|
||||||
|
});
|
||||||
|
client.root_module.addImport("kb", kb_text_shape.createModule());
|
||||||
|
|
||||||
const zmath = b.dependency("zmath", .{});
|
const zmath = b.dependency("zmath", .{});
|
||||||
client.root_module.addImport("zmath", zmath.module("root"));
|
client.root_module.addImport("zmath", zmath.module("root"));
|
||||||
server.root_module.addImport("zmath", zmath.module("root"));
|
server.root_module.addImport("zmath", zmath.module("root"));
|
||||||
|
|||||||
@ -4,9 +4,8 @@ const znet = @import("znet");
|
|||||||
const rl = @import("raylib");
|
const rl = @import("raylib");
|
||||||
const bufzilla = @import("bufzilla");
|
const bufzilla = @import("bufzilla");
|
||||||
|
|
||||||
const c = @cImport(@cInclude("../kb/kb_text_shape.h"));
|
|
||||||
|
|
||||||
const shared = @import("shared");
|
const shared = @import("shared");
|
||||||
|
const kb = @import("kb");
|
||||||
|
|
||||||
const client = @import("client.zig");
|
const client = @import("client.zig");
|
||||||
const entity = @import("entity.zig");
|
const entity = @import("entity.zig");
|
||||||
@ -40,6 +39,16 @@ pub fn main() !void {
|
|||||||
rl.initWindow(1280, 720, "zzz");
|
rl.initWindow(1280, 720, "zzz");
|
||||||
defer rl.closeWindow();
|
defer rl.closeWindow();
|
||||||
|
|
||||||
|
// kbts_shape_context *Context = kbts_CreateShapeContext(0, 0);
|
||||||
|
|
||||||
|
_ = kb.kbts_CreateShapeContext(null, null);
|
||||||
|
|
||||||
|
const shader = try rl.loadShader(null, "assets/test.frag");
|
||||||
|
|
||||||
|
const img = rl.genImageColor(32, 32, .blank);
|
||||||
|
const tx = try rl.loadTextureFromImage(img);
|
||||||
|
rl.unloadImage(img);
|
||||||
|
|
||||||
const host = try znet.Host.init(.{
|
const host = try znet.Host.init(.{
|
||||||
.addr = null,
|
.addr = null,
|
||||||
.peer_limit = 1,
|
.peer_limit = 1,
|
||||||
@ -168,7 +177,7 @@ pub fn main() !void {
|
|||||||
|
|
||||||
rl.beginDrawing();
|
rl.beginDrawing();
|
||||||
|
|
||||||
const connected_text = "Connected";
|
// const connected_text = "Connected";
|
||||||
//const not_connected_text = "Not Connected";
|
//const not_connected_text = "Not Connected";
|
||||||
|
|
||||||
// switch (peer.state()) {
|
// switch (peer.state()) {
|
||||||
@ -177,13 +186,23 @@ pub fn main() !void {
|
|||||||
// }
|
// }
|
||||||
//@divFloor(rl.getScreenWidth(), 2) - @divFloor(rl.measureText(connected_text, f.baseSize), 2), 50
|
//@divFloor(rl.getScreenWidth(), 2) - @divFloor(rl.measureText(connected_text, f.baseSize), 2), 50
|
||||||
|
|
||||||
const font_size : i32 = 180;
|
|
||||||
const text_size = rl.Vector2{.x = @floatFromInt(rl.measureText(connected_text, font_size)), .y = font_size};//rl.measureTextEx(try rl.getFontDefault(), connected_text, font_size, font_size / 10);
|
|
||||||
const pos = rl.Vector2{.x = 0, .y = 0};
|
|
||||||
rl.drawText(connected_text, pos.x, pos.y, font_size, .white);
|
|
||||||
rl.drawRectangleLines(pos.x, pos.y, @intFromFloat(text_size.x), @intFromFloat(text_size.y), .red);
|
|
||||||
|
|
||||||
std.log.info("text size: {}", .{text_size});
|
rl.beginShaderMode(shader);
|
||||||
|
|
||||||
|
// const font_size : i32 = 180;
|
||||||
|
// const text_size = rl.Vector2{.x = @floatFromInt(rl.measureText(connected_text, font_size)), .y = font_size};//rl.measureTextEx(try rl.getFontDefault(), connected_text, font_size, font_size / 10);
|
||||||
|
// const pos = rl.Vector2{.x = 0, .y = 0};
|
||||||
|
// rl.drawText(connected_text, pos.x, pos.y, font_size, .white);
|
||||||
|
// rl.drawRectangleLines(pos.x, pos.y, @intFromFloat(text_size.x), @intFromFloat(text_size.y), .red);
|
||||||
|
// rl.drawRectangle(pos.x, pos.y, rl.getScreenWidth(), rl.getScreenHeight(), .white);
|
||||||
|
rl.drawTexturePro(tx,
|
||||||
|
rl.Rectangle{.x = 0, .y = 0, .width = 32, .height = 32},
|
||||||
|
rl.Rectangle{.x = 100, .y = 100, .width = 500, .height = 500},
|
||||||
|
.{.x = 0, .y = 0},
|
||||||
|
0,
|
||||||
|
.white);
|
||||||
|
rl.endShaderMode();
|
||||||
|
|
||||||
//rl.drawLineV(.{.x = @floatFromInt(@divFloor(rl.getScreenWidth(), 2)), .y = 0}, .{.x = @floatFromInt(@divFloor(rl.getScreenWidth(), 2)), .y = @floatFromInt(rl.getScreenHeight())}, .red);
|
//rl.drawLineV(.{.x = @floatFromInt(@divFloor(rl.getScreenWidth(), 2)), .y = 0}, .{.x = @floatFromInt(@divFloor(rl.getScreenWidth(), 2)), .y = @floatFromInt(rl.getScreenHeight())}, .red);
|
||||||
|
|
||||||
//rl.drawText("Congrats! You created your first window!", rl.getMouseX(), rl.getMouseY(), 20, .white);
|
//rl.drawText("Congrats! You created your first window!", rl.getMouseX(), rl.getMouseY(), 20, .white);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user