mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
opengl: more funcs
This commit is contained in:
15
src/main.zig
15
src/main.zig
@ -22,7 +22,7 @@ pub fn main() !void {
|
|||||||
window.setSizeCallback((struct {
|
window.setSizeCallback((struct {
|
||||||
fn callback(_: glfw.Window, width: i32, height: i32) void {
|
fn callback(_: glfw.Window, width: i32, height: i32) void {
|
||||||
std.log.info("set viewport {} {}", .{ width, height });
|
std.log.info("set viewport {} {}", .{ width, height });
|
||||||
gl.c.glViewport(0, 0, width, height);
|
try gl.viewport(0, 0, width, height);
|
||||||
}
|
}
|
||||||
}).callback);
|
}).callback);
|
||||||
|
|
||||||
@ -46,12 +46,11 @@ pub fn main() !void {
|
|||||||
defer tex.destroy();
|
defer tex.destroy();
|
||||||
var texbind = try tex.bind(gl.c.GL_TEXTURE_2D);
|
var texbind = try tex.bind(gl.c.GL_TEXTURE_2D);
|
||||||
defer texbind.unbind();
|
defer texbind.unbind();
|
||||||
gl.c.glTexParameteri(gl.c.GL_TEXTURE_2D, gl.c.GL_TEXTURE_WRAP_S, gl.c.GL_REPEAT);
|
try texbind.parameter(gl.c.GL_TEXTURE_WRAP_S, gl.c.GL_REPEAT);
|
||||||
gl.c.glTexParameteri(gl.c.GL_TEXTURE_2D, gl.c.GL_TEXTURE_WRAP_T, gl.c.GL_REPEAT);
|
try texbind.parameter(gl.c.GL_TEXTURE_WRAP_T, gl.c.GL_REPEAT);
|
||||||
gl.c.glTexParameteri(gl.c.GL_TEXTURE_2D, gl.c.GL_TEXTURE_MIN_FILTER, gl.c.GL_LINEAR);
|
try texbind.parameter(gl.c.GL_TEXTURE_MIN_FILTER, gl.c.GL_LINEAR);
|
||||||
gl.c.glTexParameteri(gl.c.GL_TEXTURE_2D, gl.c.GL_TEXTURE_MAG_FILTER, gl.c.GL_LINEAR);
|
try texbind.parameter(gl.c.GL_TEXTURE_MAG_FILTER, gl.c.GL_LINEAR);
|
||||||
gl.c.glTexImage2D(
|
try texbind.image2D(
|
||||||
gl.c.GL_TEXTURE_2D,
|
|
||||||
0,
|
0,
|
||||||
gl.c.GL_RGB,
|
gl.c.GL_RGB,
|
||||||
imgwidth,
|
imgwidth,
|
||||||
@ -61,7 +60,7 @@ pub fn main() !void {
|
|||||||
gl.c.GL_UNSIGNED_BYTE,
|
gl.c.GL_UNSIGNED_BYTE,
|
||||||
data,
|
data,
|
||||||
);
|
);
|
||||||
gl.c.glGenerateMipmap(gl.c.GL_TEXTURE_2D);
|
texbind.generateMipmap();
|
||||||
|
|
||||||
// Create our vertex shader
|
// Create our vertex shader
|
||||||
const vs = try gl.Shader.create(gl.c.GL_VERTEX_SHADER);
|
const vs = try gl.Shader.create(gl.c.GL_VERTEX_SHADER);
|
||||||
|
@ -13,6 +13,41 @@ pub const Binding = struct {
|
|||||||
c.glBindTexture(b.target, 0);
|
c.glBindTexture(b.target, 0);
|
||||||
b.* = undefined;
|
b.* = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn generateMipmap(b: Binding) void {
|
||||||
|
c.glGenerateMipmap(b.target);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn parameter(b: Binding, name: c.GLenum, value: anytype) !void {
|
||||||
|
switch (@TypeOf(value)) {
|
||||||
|
c.GLint => c.glTexParameteri(b.target, name, value),
|
||||||
|
else => unreachable,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn image2D(
|
||||||
|
b: Binding,
|
||||||
|
level: c.GLint,
|
||||||
|
internal_format: c.GLint,
|
||||||
|
width: c.GLsizei,
|
||||||
|
height: c.GLsizei,
|
||||||
|
border: c.GLint,
|
||||||
|
format: c.GLenum,
|
||||||
|
typ: c.GLenum,
|
||||||
|
data: *const anyopaque,
|
||||||
|
) !void {
|
||||||
|
c.glTexImage2D(
|
||||||
|
b.target,
|
||||||
|
level,
|
||||||
|
internal_format,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
border,
|
||||||
|
format,
|
||||||
|
typ,
|
||||||
|
data,
|
||||||
|
);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Create a single texture.
|
/// Create a single texture.
|
||||||
|
@ -13,3 +13,7 @@ pub fn drawArrays(mode: c.GLenum, first: c.GLint, count: c.GLsizei) !void {
|
|||||||
c.glDrawArrays(mode, first, count);
|
c.glDrawArrays(mode, first, count);
|
||||||
try errors.getError();
|
try errors.getError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn viewport(x: c.GLint, y: c.GLint, width: c.GLsizei, height: c.GLsizei) !void {
|
||||||
|
c.glViewport(x, y, width, height);
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user