Being able to set the color
This commit is contained in:
parent
07b47f3e82
commit
4883fc68e2
14
src/main.zig
14
src/main.zig
|
@ -28,6 +28,7 @@ pub fn main() !void {
|
||||||
const ctx = try sdl.gl.createContext(window);
|
const ctx = try sdl.gl.createContext(window);
|
||||||
defer sdl.gl.deleteContext(ctx);
|
defer sdl.gl.deleteContext(ctx);
|
||||||
|
|
||||||
|
var color_loc: u32 = undefined;
|
||||||
const program = gl.Program.create();
|
const program = gl.Program.create();
|
||||||
{
|
{
|
||||||
const vs = gl.Shader.create(.vertex);
|
const vs = gl.Shader.create(.vertex);
|
||||||
|
@ -43,6 +44,7 @@ pub fn main() !void {
|
||||||
program.attach(fs);
|
program.attach(fs);
|
||||||
defer program.detach(fs);
|
defer program.detach(fs);
|
||||||
program.link();
|
program.link();
|
||||||
|
color_loc = program.uniformLocation("color").?;
|
||||||
}
|
}
|
||||||
program.use();
|
program.use();
|
||||||
|
|
||||||
|
@ -51,8 +53,11 @@ pub fn main() !void {
|
||||||
|
|
||||||
const vertex_buffer = [_]f32{
|
const vertex_buffer = [_]f32{
|
||||||
-1.0, -1.0, 0.0,
|
-1.0, -1.0, 0.0,
|
||||||
1.0, -1.0, 0.0,
|
-1.0, 1.0, 0.0,
|
||||||
0.0, 1.0, 0.0,
|
0.0, 1.0, 0.0,
|
||||||
|
1.0, 1.0, 0.0,
|
||||||
|
0.0, -1.0, 0.0,
|
||||||
|
1.0, -1.0, 0.0,
|
||||||
};
|
};
|
||||||
|
|
||||||
const buf = gl.Buffer.gen();
|
const buf = gl.Buffer.gen();
|
||||||
|
@ -83,9 +88,14 @@ pub fn main() !void {
|
||||||
|
|
||||||
gl.enableVertexAttribArray(0);
|
gl.enableVertexAttribArray(0);
|
||||||
buf.bind(.array_buffer);
|
buf.bind(.array_buffer);
|
||||||
|
|
||||||
gl.vertexAttribPointer(0, 3, .float, false, 0, 0);
|
gl.vertexAttribPointer(0, 3, .float, false, 0, 0);
|
||||||
|
|
||||||
|
gl.uniform4f(color_loc, 0.45, 0.21, 0.70, 1);
|
||||||
gl.drawArrays(.triangles, 0, 3);
|
gl.drawArrays(.triangles, 0, 3);
|
||||||
|
|
||||||
|
gl.uniform4f(color_loc, 0.2, 0.5, 1.0, 1);
|
||||||
|
gl.drawArrays(.triangles, 3, 3);
|
||||||
|
|
||||||
gl.disableVertexAttribArray(0);
|
gl.disableVertexAttribArray(0);
|
||||||
|
|
||||||
//current_state = switch (current_state) {
|
//current_state = switch (current_state) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#version 330 core
|
#version 330 core
|
||||||
|
|
||||||
out vec3 color;
|
uniform vec4 color;
|
||||||
|
|
||||||
void main(){
|
void main(){
|
||||||
color = vec3(1,0,0);
|
gl_FragColor = color;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue