added shader to renderer2d

This commit is contained in:
DaniTheSkunk 2023-03-22 23:08:34 +00:00
parent 2606a344b8
commit fc8f2b387c
9 changed files with 73 additions and 5 deletions

View File

@ -1,5 +1,5 @@
@ECHO OFF
cl build.c src/str.c src/types.c /Iinclude /nologo && del *.obj && build.exe && del build.exe && build\gsa_simple.exe
cl build.c src/str.c src/types.c /Iinclude /nologo && del *.obj && build.exe && del build.exe && build\simple.exe
EXIT /B %ERRORLEVEL%

View File

@ -84,6 +84,7 @@ int main(int argc, char *argv[]) {
"/I. ");
sys("copy gsa_simple.exe test.exe");
sys("skip ca1 ../example_data gsa_simple.exe");
sys("skip ca1 ../example_data simple.exe");
sys("del *.obj");

View File

@ -1,13 +1,18 @@
#include <skunkworks.h>
void tick() {
void render() {
}
int main(int argc, char *argv[]) {
struct sw_window *win;
struct sw_renderer2d *ren;
sw_init(argc, argv);
win = sw_window_create(sw_vec2i(1280, 720), "example", 0);
sw_window_run(win, tick);
ren = sw_renderer2d_create();
sw_window_add_renderer(win, ren->renderer, render);
sw_window_run(win);
return 0;
}

View File

@ -3,8 +3,11 @@
#include "shader.h"
struct sw_renderer;
struct sw_renderer2d {
struct sw_shaderprogram shader;
struct sw_renderer *renderer;
};
struct sw_renderer2d *sw_renderer2d_create();

View File

@ -7,6 +7,7 @@
#include "gamepad.h"
#include "image32.h"
#include "image8.h"
#include "renderer2d.h"
#include "skip.h"
#include "str.h"
#include "types.h"

View File

@ -1,3 +1,48 @@
#include "renderer2d.h"
#include "renderer.h"
#include "shader.h"
#include "skip.h"
struct sw_renderer2d *sw_renderer2d_create(){};
#include <stdlib.h>
#include "gl.h"
struct vert {
f32 x, y, z;
};
static void r_enter(struct sw_window *win, void *data);
static void r_exit(struct sw_window *win, void *data);
struct sw_renderer2d *sw_renderer2d_create() {
struct sw_renderer2d *ren;
u8 *frag, *vert;
ren = malloc(sizeof(struct sw_renderer2d));
ren->renderer = sw_renderer_create(ren, r_enter, r_exit);
frag = sw_skip_get_string(sw_skip_self, "renderer2d_frag.glsl");
vert = sw_skip_get_string(sw_skip_self, "renderer2d_vert.glsl");
ren->shader = sw_shaderprogram_create(vert, 0, frag, 0, 0);
return ren;
};
static void r_enter(struct sw_window *win, void *data) {
struct sw_renderer2d *ren;
ren = data;
sw_shaderprogram_use(ren->shader);
glBegin(GL_TRIANGLES);
glVertex2i(0, 0);
glVertex2i(1, 0);
glVertex2i(0, 1);
glEnd();
}
static void r_exit(struct sw_window *win, void *data) {
}

7
src/renderer2d_frag.glsl Normal file
View File

@ -0,0 +1,7 @@
#version 460
layout(location = 0) out vec4 color;
void main() {
color = vec4(0.1, 0.2, 0.3, 1.0);
}

7
src/renderer2d_vert.glsl Normal file
View File

@ -0,0 +1,7 @@
#version 460
layout(location = 0) in vec3 pos;
void main() {
gl_Position = vec4(pos, 1.0);
}

View File

@ -7,7 +7,6 @@ struct sw_shaderprogram sw_shaders_scale;
void sw_shaders_static_init() {
u8 *vert_copy, *frag_copy, *frag_scale;
u32 size;
sw_log("initialising shaders");
vert_copy = sw_skip_get_string(sw_skip_self, "shader_copy_vert.glsl");