2024-04-12 04:27:14 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <SDL2/SDL.h>
|
|
|
|
#include "display.h"
|
2024-04-13 03:41:06 +00:00
|
|
|
#include "vector.h"
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// Declare an array of points
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
#define N_POINTS (9 * 9 * 9)
|
|
|
|
vec3_t cube_points[N_POINTS];
|
|
|
|
|
2024-04-12 04:27:14 +00:00
|
|
|
|
|
|
|
bool is_running = false;
|
|
|
|
|
|
|
|
void setup(void) {
|
2024-04-13 03:41:06 +00:00
|
|
|
// Allocate the required memory in bytes to hold color buffer
|
|
|
|
color_buffer = (uint32_t *) malloc(sizeof(uint32_t) * window_width * window_height);
|
|
|
|
|
|
|
|
// Creating the SDL Texture that is uses to display the color buffer
|
|
|
|
color_buffer_texture = SDL_CreateTexture(
|
|
|
|
renderer,
|
|
|
|
SDL_PIXELFORMAT_ARGB8888,
|
|
|
|
SDL_TEXTUREACCESS_STREAMING,
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-04-12 04:27:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void process_input(void) {
|
2024-04-13 03:41:06 +00:00
|
|
|
SDL_Event event;
|
|
|
|
SDL_PollEvent(&event);
|
|
|
|
|
|
|
|
switch (event.type) {
|
|
|
|
case SDL_QUIT:
|
|
|
|
is_running = false;
|
|
|
|
break;
|
|
|
|
case SDL_KEYDOWN:
|
|
|
|
if (event.key.keysym.sym == SDLK_ESCAPE) {
|
|
|
|
is_running = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2024-04-12 04:27:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void update(void) {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void render(void) {
|
2024-04-13 03:41:06 +00:00
|
|
|
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
|
|
|
|
SDL_RenderClear(renderer);
|
2024-04-12 04:27:14 +00:00
|
|
|
|
2024-04-13 03:41:06 +00:00
|
|
|
clear_color_buffer(0xFF000000);
|
|
|
|
draw_grid(10);
|
|
|
|
draw_rect(50, 50, 640, 480, 0xFFDD00DD);
|
|
|
|
render_color_buffer();
|
2024-04-12 04:27:14 +00:00
|
|
|
|
2024-04-13 03:41:06 +00:00
|
|
|
SDL_RenderPresent(renderer);
|
2024-04-12 04:27:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main(void) {
|
2024-04-13 03:41:06 +00:00
|
|
|
is_running = initialize_window();
|
|
|
|
setup();
|
|
|
|
|
|
|
|
while (is_running) {
|
|
|
|
process_input();
|
|
|
|
update();
|
|
|
|
render();
|
|
|
|
}
|
|
|
|
destroy_window();
|
|
|
|
return 0;
|
2024-04-12 04:27:14 +00:00
|
|
|
}
|