mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 07:46:12 +03:00
awful text rendering
This commit is contained in:
@ -1,10 +1,11 @@
|
||||
#version 330 core
|
||||
|
||||
layout (location = 0) in vec4 vertex; // <vec2 pos, vec2 tex>
|
||||
out vec2 TexCoords;
|
||||
|
||||
uniform mat4 projection;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(vertex.xy, 0.0, 1.0);
|
||||
gl_Position = projection * vec4(vertex.xy, 0.0, 1.0);
|
||||
TexCoords = vertex.zw;
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ chars: CharList,
|
||||
vao: gl.VertexArray = undefined,
|
||||
vbo: gl.Buffer = undefined,
|
||||
program: gl.Program = undefined,
|
||||
projection: gb.gbMat4 = undefined,
|
||||
|
||||
const CharList = std.ArrayListUnmanaged(Char);
|
||||
const Char = struct {
|
||||
@ -114,11 +115,7 @@ pub fn init(alloc: std.mem.Allocator) !TextRenderer {
|
||||
@embedFile("../shaders/text.f.glsl"),
|
||||
);
|
||||
|
||||
// Our project
|
||||
var proj: gb.gbMat4 = undefined;
|
||||
gb.gb_mat4_ortho2d(&proj, 0, 640, 0, 480);
|
||||
|
||||
return TextRenderer{
|
||||
var res = TextRenderer{
|
||||
.alloc = alloc,
|
||||
.ft = ft,
|
||||
.face = face,
|
||||
@ -126,7 +123,14 @@ pub fn init(alloc: std.mem.Allocator) !TextRenderer {
|
||||
.program = program,
|
||||
.vao = vao,
|
||||
.vbo = vbo,
|
||||
.projection = undefined,
|
||||
};
|
||||
|
||||
// Update the initialize size so we have some projection. We
|
||||
// expect this will get updated almost immediately.
|
||||
try res.setScreenSize(3000, 1666);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
pub fn deinit(self: *TextRenderer) void {
|
||||
@ -141,6 +145,19 @@ pub fn deinit(self: *TextRenderer) void {
|
||||
self.* = undefined;
|
||||
}
|
||||
|
||||
pub fn setScreenSize(self: *TextRenderer, w: i32, h: i32) !void {
|
||||
gb.gb_mat4_ortho2d(
|
||||
&self.projection,
|
||||
0,
|
||||
@intToFloat(f32, w),
|
||||
0,
|
||||
@intToFloat(f32, h),
|
||||
);
|
||||
|
||||
try self.program.use();
|
||||
try self.program.setUniform("projection", self.projection);
|
||||
}
|
||||
|
||||
pub fn render(
|
||||
self: TextRenderer,
|
||||
text: []const u8,
|
||||
|
@ -4,6 +4,7 @@ const std = @import("std");
|
||||
const assert = std.debug.assert;
|
||||
const log = std.log.scoped(.opengl);
|
||||
|
||||
const gb = @import("../gb_math.zig");
|
||||
const c = @import("c.zig");
|
||||
const Shader = @import("Shader.zig");
|
||||
const errors = @import("errors.zig");
|
||||
@ -76,6 +77,12 @@ pub inline fn setUniform(p: Program, n: [:0]const u8, value: anytype) !void {
|
||||
switch (@TypeOf(value)) {
|
||||
@Vector(3, f32) => c.glUniform3f(loc, value[0], value[1], value[2]),
|
||||
@Vector(4, f32) => c.glUniform4f(loc, value[0], value[1], value[2], value[3]),
|
||||
gb.gbMat4 => c.glUniformMatrix4fv(
|
||||
loc,
|
||||
1,
|
||||
c.GL_FALSE,
|
||||
@ptrCast([*c]const f32, &value),
|
||||
),
|
||||
else => unreachable,
|
||||
}
|
||||
try errors.getError();
|
||||
|
Reference in New Issue
Block a user