diff --git a/src/platform.zig b/src/platform.zig index 4c4ecf0..223c923 100644 --- a/src/platform.zig +++ b/src/platform.zig @@ -25,10 +25,10 @@ pub const Gui = struct { // zig fmt: off const vertices: [32]f32 = [_]f32{ // Positions // Colours // Texture Coords - 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, // Top Right - 1.0, -1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, // Bottom Right - -1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, // Bottom Left - -1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, // Top Left + 1.0, -1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, // Top Right + 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, // Bottom Right + -1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, // Bottom Left + -1.0, -1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, // Top Left }; const indices: [6]u32 = [_]u32{ @@ -47,8 +47,8 @@ pub const Gui = struct { pub fn init(title: *const [12]u8, apu: *Apu, width: i32, height: i32) Self { if (SDL.SDL_Init(SDL.SDL_INIT_VIDEO | SDL.SDL_INIT_EVENTS | SDL.SDL_INIT_AUDIO) < 0) panic(); if (SDL.SDL_GL_SetAttribute(SDL.SDL_GL_CONTEXT_PROFILE_MASK, SDL.SDL_GL_CONTEXT_PROFILE_CORE) < 0) panic(); - if (SDL.SDL_GL_SetAttribute(SDL.SDL_GL_CONTEXT_MAJOR_VERSION, 4) < 0) panic(); - if (SDL.SDL_GL_SetAttribute(SDL.SDL_GL_CONTEXT_MAJOR_VERSION, 4) < 0) panic(); + if (SDL.SDL_GL_SetAttribute(SDL.SDL_GL_CONTEXT_MAJOR_VERSION, 3) < 0) panic(); + if (SDL.SDL_GL_SetAttribute(SDL.SDL_GL_CONTEXT_MAJOR_VERSION, 3) < 0) panic(); const window = SDL.SDL_CreateWindow( default_title.ptr, @@ -119,13 +119,13 @@ pub const Gui = struct { gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, @sizeOf(@TypeOf(indices)), &indices, gl.STATIC_DRAW); // Position - gl.vertexAttribPointer(0, 3, gl.FLOAT, gl.FALSE, 8 * @sizeOf(f32), &0); + gl.vertexAttribPointer(0, 3, gl.FLOAT, gl.FALSE, 8 * @sizeOf(f32), @intToPtr(?*anyopaque, 0)); // lmao gl.enableVertexAttribArray(0); // Colour - gl.vertexAttribPointer(1, 3, gl.FLOAT, gl.FALSE, 8 * @sizeOf(f32), &(3 * @sizeOf(f32))); + gl.vertexAttribPointer(1, 3, gl.FLOAT, gl.FALSE, 8 * @sizeOf(f32), @intToPtr(?*anyopaque, (3 * @sizeOf(f32)))); gl.enableVertexAttribArray(1); // Texture Coord - gl.vertexAttribPointer(2, 3, gl.FLOAT, gl.FALSE, 8 * @sizeOf(f32), &(6 * @sizeOf(f32))); + gl.vertexAttribPointer(2, 2, gl.FLOAT, gl.FALSE, 8 * @sizeOf(f32), @intToPtr(?*anyopaque, (6 * @sizeOf(f32)))); gl.enableVertexAttribArray(2); return .{ vao_id, vbo_id, ebo_id }; @@ -136,13 +136,13 @@ pub const Gui = struct { gl.genTextures(1, &tex_id); gl.bindTexture(gl.TEXTURE_2D, tex_id); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); + // gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); + // gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gba_width, gba_height, 0, gl.RGBA, gl.UNSIGNED_BYTE, buf.ptr); + gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gba_width, gba_height, 0, gl.RGBA, gl.UNSIGNED_INT_8_8_8_8, buf.ptr); // gl.generateMipmap(gl.TEXTURE_2D); // TODO: Remove? return tex_id; @@ -218,7 +218,7 @@ pub const Gui = struct { // Emulator has an internal Double Buffer const framebuf = cpu.bus.ppu.framebuf.get(.Renderer); - gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gba_width, gba_height, gl.RGBA, gl.UNSIGNED_BYTE, framebuf.ptr); + gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gba_width, gba_height, gl.RGBA, gl.UNSIGNED_INT_8_8_8_8, framebuf.ptr); gl.useProgram(self.program_id); gl.bindVertexArray(vao_id); diff --git a/src/shader/pixelbuf.frag b/src/shader/pixelbuf.frag index b4abca1..f867bde 100644 --- a/src/shader/pixelbuf.frag +++ b/src/shader/pixelbuf.frag @@ -1,4 +1,4 @@ -#version 450 core +#version 330 core out vec4 FragColor; in vec3 ourColor; @@ -7,8 +7,7 @@ in vec2 TexCoord; // texture sampler uniform sampler2D texture1; -void main() -{ - FragColor = texture(texture1, TexCoord).wzyx; +void main() { + FragColor = texture(texture1, TexCoord); } diff --git a/src/shader/pixelbuf.vert b/src/shader/pixelbuf.vert index c0ce337..0738b36 100644 --- a/src/shader/pixelbuf.vert +++ b/src/shader/pixelbuf.vert @@ -1,4 +1,4 @@ -#version 450 core +#version 330 core layout (location = 0) in vec3 aPos; layout (location = 1) in vec3 aColor; layout (location = 2) in vec2 aTexCoord; @@ -6,9 +6,8 @@ layout (location = 2) in vec2 aTexCoord; out vec3 ourColor; out vec2 TexCoord; -void main() -{ +void main() { gl_Position = vec4(aPos, 1.0); ourColor = aColor; - TexCoord = vec2(aTexCoord.x, aTexCoord.y); + TexCoord = aTexCoord; } \ No newline at end of file