split parts, vector, tc

This commit is contained in:
Tyrel Souza 2024-04-12 23:41:06 -04:00
parent edfc64d225
commit f783db8a45
3 changed files with 77 additions and 46 deletions

View File

@ -63,6 +63,7 @@ void render_color_buffer(void) {
);
SDL_RenderCopy(renderer, color_buffer_texture, NULL, NULL);
}
void draw_grid(int size) {
if (color_buffer == NULL) {
return;
@ -70,7 +71,7 @@ void draw_grid(int size) {
for (int y = 0; y < window_height; y++) {
for (int x = 0; x < window_width; x++) {
if (y % size == 0 || x % size == 0) {
color_buffer[(window_width * y) + x] = 0xFF333333;
draw_pixel(x, y, 0xFF333333);
}
}
}
@ -82,9 +83,7 @@ void draw_rect(int x, int y, int width, int height, uint32_t color){
}
for (int i = y; i < height + y; i++) {
for (int j = x; j < width; j++) {
int cur_x = x+j;
int cur_y = y+i;
color_buffer[(window_width * cur_y) + cur_x] = color;
draw_pixel(x + j, y + i, color);
}
}
}
@ -96,3 +95,9 @@ void destroy_window(void) {
SDL_DestroyTexture(color_buffer_texture);
SDL_Quit();
}
void draw_pixel(int x, int y, uint32_t color) {
if (x < window_width && y < window_height) {
color_buffer[(window_width * y) + x] = color;
}
}

View File

@ -1,5 +1,6 @@
#ifndef DISPLAY_H
#define DISPLAY_H
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
@ -13,10 +14,17 @@ extern int window_width;
extern int window_height;
bool initialize_window(void);
void draw_grid(int size);
void draw_pixel(int x, int y, uint32_t color);
void draw_rect(int x, int y, int width, int height, uint32_t color);
void clear_color_buffer(uint32_t color);
void render_color_buffer(void);
void destroy_window(void);

View File

@ -2,6 +2,14 @@
#include <stdbool.h>
#include <SDL2/SDL.h>
#include "display.h"
#include "vector.h"
////////////////////////////////////////////////////////////
// Declare an array of points
////////////////////////////////////////////////////////////
#define N_POINTS (9 * 9 * 9)
vec3_t cube_points[N_POINTS];
bool is_running = false;
@ -17,6 +25,15 @@ void setup(void) {
window_width,
window_height
);
int point_count = 0;
for (float x = -1; x <= 1; x += 0.25) {
for (float y = -1; y <= 1; y += 0.25) {
for (float z = -1; z <= 1; z += 0.25) {
vec3_t new_point = { .x = x, .y = y, .z = z };
cube_points[point_count++] = new_point;
}
}
}
}
void process_input(void) {
@ -56,6 +73,7 @@ void render(void) {
int main(void) {
is_running = initialize_window();
setup();
while (is_running) {
process_input();
update();