Compare commits

..

No commits in common. "9f4137dac9e33e9d8522e71412c5c5e7c08372e3" and "3c21e2c471e4f389552e8d1d909f99c495906f35" have entirely different histories.

4 changed files with 2 additions and 79 deletions

View File

@ -1,9 +0,0 @@
#ifndef RASTERISER_H
#define RASTERISER_H
#include "vector/vec.h"
#include "window/window.h"
void draw_line(window_t *wnd, vec2i_t p0, vec2i_t p1, colour_t colour);
#endif // !RASTERISER_H

View File

@ -33,12 +33,6 @@ typedef struct {
#define vec_dot(T, v1, v2) vec_dot_##T(v1, v2)
#define vec_magnitude(T, v) vec_magnitude_##T(v)
#define vec_unit(T, v) vec_unit_##T(v)
#define vec_swap(T, v1, v2) \
{ \
T tmp = v1; \
v1 = v2; \
v2 = tmp; \
}
vec2i_t vec_add_vec2i_t(vec2i_t v1, vec2i_t v2);
vec2i_t vec_sub_vec2i_t(vec2i_t v1, vec2i_t v2);

View File

@ -1,47 +1,7 @@
#include "rasteriser/rasteriser.h"
#include "vector/vec.h"
#include "window/window.h"
#include <SDL2/SDL_events.h>
#include <SDL2/SDL_keycode.h>
#include <stdio.h>
#include <stdlib.h>
int main(void) {
colour_t bg =
(colour_t){.rgba.r = 27, .rgba.g = 38, .rgba.b = 79, .rgba.a = 255};
window_t window = {0};
if (!init_window(&window, 800, 800, "CG From Scratch Rasteriser")) {
return EXIT_FAILURE;
}
bool running = true;
SDL_Event event = {0};
// i32 w_min = ((i32)window.half_width) * -1;
// i32 w_max = (i32)window.half_width;
// i32 h_min = ((i32)window.half_height) * -1;
// i32 h_max = (i32)window.half_height;
vec2i_t a = {.x = -300, .y = 0};
vec2i_t b = {.x = 300, .y = 250};
while (running) {
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
running = false;
break;
}
}
clear_window(&window, bg);
draw_line(&window, a, b, (colour_t){.colour = 0xffffffff});
swap_buffers(&window);
}
close_window(&window);
printf("RASTERISER\n");
return EXIT_SUCCESS;
}

View File

@ -1,22 +0,0 @@
#include "c_cpp_aliases/aliases.h"
#include "vector/vec.h"
#include "window/window.h"
void draw_line(window_t *wnd, vec2i_t p0, vec2i_t p1, colour_t colour) {
if (p1.x < p0.x) {
vec_swap(vec2i_t, p0, p1);
}
i32 x0 = p0.x;
i32 y0 = p0.y;
i32 x1 = p1.x;
i32 y1 = p1.y;
f32 a = ((f32)y1 - y0) / ((f32)x1 - x0);
f32 y = y0;
for (i32 x = x0; x <= x1; ++x) {
set_pixel(wnd, x, (i32)y, colour);
y += a;
}
}