mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
opengl: draw functions
This commit is contained in:
14
src/main.zig
14
src/main.zig
@ -83,9 +83,9 @@ pub fn main() !void {
|
|||||||
|
|
||||||
// Create our bufer or vertices
|
// Create our bufer or vertices
|
||||||
const vertices = [_]f32{
|
const vertices = [_]f32{
|
||||||
-0.5, -0.5, 0.0, 0.0, 0.0, // left
|
-0.8, -0.8, 0.0, 0.0, 0.0, // left
|
||||||
0.5, -0.5, 0.0, 1.0, 0.0, // right
|
0.8, -0.8, 0.0, 1.0, 0.0, // right
|
||||||
0.0, 0.5, 0.0, 0.5, 1.0, // top
|
0.0, 0.8, 0.0, 0.5, 1.0, // top
|
||||||
};
|
};
|
||||||
const vao = try gl.VertexArray.create();
|
const vao = try gl.VertexArray.create();
|
||||||
defer vao.destroy();
|
defer vao.destroy();
|
||||||
@ -112,14 +112,14 @@ pub fn main() !void {
|
|||||||
// Wait for the user to close the window.
|
// Wait for the user to close the window.
|
||||||
while (!window.shouldClose()) {
|
while (!window.shouldClose()) {
|
||||||
// Setup basic OpenGL settings
|
// Setup basic OpenGL settings
|
||||||
gl.c.glClearColor(0.2, 0.3, 0.3, 1.0);
|
gl.clearColor(0.2, 0.3, 0.3, 1.0);
|
||||||
gl.c.glClear(gl.c.GL_COLOR_BUFFER_BIT);
|
gl.clear(gl.c.GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
try program.use();
|
try program.use();
|
||||||
|
|
||||||
gl.c.glBindTexture(gl.c.GL_TEXTURE_2D, tex.id);
|
_ = try tex.bind(gl.c.GL_TEXTURE_2D);
|
||||||
try vao.bind();
|
try vao.bind();
|
||||||
gl.c.glDrawArrays(gl.c.GL_TRIANGLES, 0, 3);
|
try gl.drawArrays(gl.c.GL_TRIANGLES, 0, 3);
|
||||||
|
|
||||||
// const pos = try window.getCursorPos();
|
// const pos = try window.getCursorPos();
|
||||||
// std.log.info("CURSOR: {}", .{pos});
|
// std.log.info("CURSOR: {}", .{pos});
|
||||||
|
@ -17,3 +17,4 @@ pub const Program = @import("opengl/Program.zig");
|
|||||||
pub const Shader = @import("opengl/Shader.zig");
|
pub const Shader = @import("opengl/Shader.zig");
|
||||||
pub const Texture = @import("opengl/Texture.zig");
|
pub const Texture = @import("opengl/Texture.zig");
|
||||||
pub const VertexArray = @import("opengl/VertexArray.zig");
|
pub const VertexArray = @import("opengl/VertexArray.zig");
|
||||||
|
pub usingnamespace @import("opengl/draw.zig");
|
||||||
|
15
src/opengl/draw.zig
Normal file
15
src/opengl/draw.zig
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
const c = @import("c.zig");
|
||||||
|
const errors = @import("errors.zig");
|
||||||
|
|
||||||
|
pub fn clearColor(r: f32, g: f32, b: f32, a: f32) void {
|
||||||
|
c.glClearColor(r, g, b, a);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn clear(mask: c.GLbitfield) void {
|
||||||
|
c.glClear(mask);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn drawArrays(mode: c.GLenum, first: c.GLint, count: c.GLsizei) !void {
|
||||||
|
c.glDrawArrays(mode, first, count);
|
||||||
|
try errors.getError();
|
||||||
|
}
|
Reference in New Issue
Block a user