split parts, vector, tc
This commit is contained in:
parent
edfc64d225
commit
f783db8a45
@ -63,28 +63,27 @@ void render_color_buffer(void) {
|
|||||||
);
|
);
|
||||||
SDL_RenderCopy(renderer, color_buffer_texture, NULL, NULL);
|
SDL_RenderCopy(renderer, color_buffer_texture, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_grid(int size) {
|
void draw_grid(int size) {
|
||||||
if (color_buffer == NULL) {
|
if (color_buffer == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (int y = 0; y < window_height; y++) {
|
for (int y = 0; y < window_height; y++) {
|
||||||
for (int x = 0; x < window_width; x++) {
|
for (int x = 0; x < window_width; x++) {
|
||||||
if (y % size == 0 || x % size == 0 ) {
|
if (y % size == 0 || x % size == 0) {
|
||||||
color_buffer[(window_width * y) + x] = 0xFF333333;
|
draw_pixel(x, y, 0xFF333333);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_rect(int x, int y, int width, int height, uint32_t color){
|
void draw_rect(int x, int y, int width, int height, uint32_t color) {
|
||||||
if (color_buffer == NULL) {
|
if (color_buffer == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (int i = y; i < height+y; i++) {
|
for (int i = y; i < height + y; i++) {
|
||||||
for (int j = x; j < width; j++) {
|
for (int j = x; j < width; j++) {
|
||||||
int cur_x = x+j;
|
draw_pixel(x + j, y + i, color);
|
||||||
int cur_y = y+i;
|
|
||||||
color_buffer[(window_width * cur_y) + cur_x] = color;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -96,3 +95,9 @@ void destroy_window(void) {
|
|||||||
SDL_DestroyTexture(color_buffer_texture);
|
SDL_DestroyTexture(color_buffer_texture);
|
||||||
SDL_Quit();
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#ifndef DISPLAY_H
|
#ifndef DISPLAY_H
|
||||||
#define DISPLAY_H
|
#define DISPLAY_H
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
@ -13,10 +14,17 @@ extern int window_width;
|
|||||||
extern int window_height;
|
extern int window_height;
|
||||||
|
|
||||||
bool initialize_window(void);
|
bool initialize_window(void);
|
||||||
|
|
||||||
void draw_grid(int size);
|
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 draw_rect(int x, int y, int width, int height, uint32_t color);
|
||||||
|
|
||||||
void clear_color_buffer(uint32_t color);
|
void clear_color_buffer(uint32_t color);
|
||||||
|
|
||||||
void render_color_buffer(void);
|
void render_color_buffer(void);
|
||||||
|
|
||||||
void destroy_window(void);
|
void destroy_window(void);
|
||||||
|
|
||||||
|
|
||||||
|
18
src/main.c
18
src/main.c
@ -2,6 +2,14 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include "display.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;
|
bool is_running = false;
|
||||||
|
|
||||||
@ -17,6 +25,15 @@ void setup(void) {
|
|||||||
window_width,
|
window_width,
|
||||||
window_height
|
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) {
|
void process_input(void) {
|
||||||
@ -56,6 +73,7 @@ void render(void) {
|
|||||||
int main(void) {
|
int main(void) {
|
||||||
is_running = initialize_window();
|
is_running = initialize_window();
|
||||||
setup();
|
setup();
|
||||||
|
|
||||||
while (is_running) {
|
while (is_running) {
|
||||||
process_input();
|
process_input();
|
||||||
update();
|
update();
|
||||||
|
Loading…
Reference in New Issue
Block a user