sr.h (1194B)
1 #pragma once 2 3 #include <SDL2/SDL.h> 4 #include "types.h" 5 6 #define W 640 7 #define H 480 8 9 #define WIN_W 640 10 #define WIN_H 480 11 #define VERTEX_BUFFER_LEN 64*1024 12 13 #define VEC2I_SWAP(x, y) { ivec2 temp = x; x = y; y = temp; } 14 #define C_SWAP(x, y) { C temp = x; x = y; y = temp; } 15 #define I_SWAP(x, y) { int temp = x; x = y; y = temp; } 16 17 typedef struct {u8 b;u8 g;u8 r;} C; 18 typedef struct { double x, y, z; } point; 19 typedef struct { int x, y; } ivec2; 20 typedef struct { double x, y, z; } vec3f; 21 enum mop {ADD, SUB, MUL, DIV}; 22 23 typedef struct _RENDERER { 24 SDL_Window* window; 25 SDL_Texture* tex; 26 SDL_Renderer* renderer; 27 ivec2* verts; 28 C* colors; 29 u32* fb; 30 u32 nvertices; /* Current number or vertices in the buffers */ 31 } REN; 32 33 void FB_flip_vert(u32*); 34 ivec2 IVEC2_op(ivec2, ivec2, enum mop); 35 ivec2 IVEC2_ops(ivec2, i32, enum mop); 36 C C_new(u32); 37 38 void REN_triangle(REN*, ivec2[3], C[3]); 39 REN* REN_new(void); 40 ivec2 POSITION_from_gp0(u32 val); 41 C COLOR_from_gp0(u32 val); 42 void REN_push_triangle(REN*, ivec2[3], C[3]); 43 void REN_push_quad(REN*, ivec2[4], C[4]); 44 void REN_draw(REN* ren); 45 void REN_display(REN* ren); 46 void REN_flush(REN* ren); 47 void draw_scanline(REN*, int, int, C, int, C);