Compare commits
3 Commits
dc5d252c90
...
148dec2d3d
Author | SHA1 | Date | |
---|---|---|---|
148dec2d3d | |||
0f87945e89 | |||
02e4326f4c |
@ -1,3 +1,3 @@
|
||||
# SDL Boilerplate
|
||||
# Compositor test
|
||||
|
||||
Boilerplate for setting up a simple SDL program that creates a window and a renderer and handles the quit event.
|
||||
Test for building a basic node-based compositing application
|
||||
|
@ -10,6 +10,7 @@
|
||||
typedef struct point point_t;
|
||||
typedef struct line line_t;
|
||||
typedef struct triangle triangle_t;
|
||||
typedef struct rect rect_t;
|
||||
typedef struct window window_t;
|
||||
|
||||
struct point {
|
||||
@ -28,6 +29,12 @@ struct triangle {
|
||||
point_t p2;
|
||||
};
|
||||
|
||||
struct rect {
|
||||
point_t topleft;
|
||||
i32 w;
|
||||
i32 h;
|
||||
};
|
||||
|
||||
struct window {
|
||||
u64 width;
|
||||
u64 height;
|
||||
@ -52,5 +59,6 @@ void draw_point(const window_t *wnd, point_t p, colour_t colour);
|
||||
void draw_line(const window_t *wnd, const line_t *ln, colour_t colour);
|
||||
void draw_triangle(const window_t *wnd, const triangle_t *triangle,
|
||||
colour_t colour);
|
||||
void draw_rect(const window_t *wnd, const rect_t *rect, colour_t colour);
|
||||
|
||||
#endif // !WINDOW_H
|
||||
|
@ -36,6 +36,8 @@ i32 run_main_loop(void) {
|
||||
|
||||
comp.running = true;
|
||||
|
||||
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
|
||||
|
||||
colour_t bg_colour = {.abgr = 0xffffffff};
|
||||
colour_t fg_colour = {.abgr = 0xff000000};
|
||||
|
||||
|
13
src/window.c
13
src/window.c
@ -1,7 +1,8 @@
|
||||
#include "window.h"
|
||||
#include "SDL_render.h"
|
||||
#include "SDL_video.h"
|
||||
#include "aliases/aliases.h"
|
||||
#include <SDL2/SDL_rect.h>
|
||||
#include <SDL2/SDL_render.h>
|
||||
#include <SDL2/SDL_video.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
bool init_window(window_t *wnd, const char *title, u64 width, u64 height) {
|
||||
@ -72,3 +73,11 @@ void draw_triangle(const window_t *wnd, const triangle_t *triangle,
|
||||
draw_line(wnd, &ln1, colour);
|
||||
draw_line(wnd, &ln2, colour);
|
||||
}
|
||||
|
||||
void draw_rect(const window_t *wnd, const rect_t *rect, colour_t colour) {
|
||||
set_colour(wnd, colour);
|
||||
|
||||
SDL_Rect dst = {rect->topleft.x, rect->topleft.y, rect->w, rect->h};
|
||||
|
||||
SDL_RenderDrawRect(wnd->renderer, &dst);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user