Skip to content

Instantly share code, notes, and snippets.

@schroffl
Last active November 28, 2018 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schroffl/ff86ed745533b7eb6df13f2832c4bea2 to your computer and use it in GitHub Desktop.
Save schroffl/ff86ed745533b7eb6df13f2832c4bea2 to your computer and use it in GitHub Desktop.
var direct_allocator = std.heap.DirectAllocator.init();
var allocator = &direct_allocator.allocator;
fn initShaders() void {
const program = c.glCreateProgram();
const vsrc =
c\\#version 300
c\\in vec3 position;
c\\out vec3 vecPosition;
c\\
c\\void main() {
c\\ vecPosition = position;
c\\ gl_Position = vec3(poostion, 1.0);
c\\}
;
const vshader = createShader(c.GL_VERTEX_SHADER, vsrc);
}
fn createShader(shader_type: c.GLenum, source: [*]const u8) c.GLuint {
const shader = c.glCreateShader(shader_type);
const srcArr = [][*]const u8 { source };
c.glShaderSource(shader, 1, &srcArr, null);
c.glCompileShader(shader);
const log = getShaderInfoLog(shader);
warn("Log {}\n", log);
return shader;
}
fn getShaderiv(shader: c.GLuint, param: c.GLenum) i32 {
var temp: [1]i32 = []i32 { 0 };
c.glGetShaderiv(shader, param, &temp);
return temp[0];
}
fn getShaderInfoLog(shader: c.GLuint) ![]const u8 {
const log_length = getShaderiv(shader, c.GL_INFO_LOG_LENGTH);
var buffer = try allocator.alloc(u8, @intCast(usize, log_length));
var temp: [1]i32 = []i32 { 0 };
c.glGetShaderInfoLog(shader, log_length, &temp, @ptrCast([*]u8, &buffer));
return buffer;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment