fixed crash.

This commit is contained in:
Tijani Lawal 2024-08-31 13:53:51 -05:00
parent 8b7af0c1ec
commit af0033cace
3 changed files with 9 additions and 54 deletions

3
.gitignore vendored
View File

@ -2,4 +2,5 @@
*.pdf
*.obj
*.pdb
*.res
*.res
*.rdi

View File

@ -1,19 +1,11 @@
#define WIN32_LEAN_AND_MEAN
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "base/base_inc.h"
#include "renderer/display.h"
#include "renderer/vector.h"
#include "renderer/display.c"
#include "renderer/vector.c"
#define POINTS (9 * 9 * 9)
Vec3F32 cube_points[POINTS];
Vec2F32 projected_points[POINTS];
int is_running;
@ -21,26 +13,8 @@ void setup(void) {
colour_buffer = (u32 *)malloc(sizeof(u32) * window_width * window_height);
colour_buffer_texture =
SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, window_width, window_height);
int point_count = 0;
// Start loading an array of vectors
// from -1 to 1 (in the 9*9*9 cube)
for (f32 x = -1; x < 1; x += 0.25) {
for (f32 y = -1; y < 1; y += 0.25) {
for (f32 z = -1; z < 1; z += 0.25) {
Vec3F32 new_point = {.x = x, .y = y, .z = z};
cube_points[point_count++] = new_point;
}
}
}
}
// Orthographic projection
// Vec2F32 project(Vec3F32 point) {
// Vec2F32 projected_point = {.x = point.x, .y = point.y};
// return projected_point;
// }
void process_input(void) {
SDL_Event event;
@ -60,39 +34,17 @@ void process_input(void) {
}
}
// Convert 3D projection -> 2D
Vec2F32 project(Vec3F32 point) {
Vec2F32 projected_point = {.x = point.x, .y = point.y};
return projected_point;
}
void update(void) {
for (int i = 0; i < POINTS; ++i) {
Vec3F32 point = cube_points[i];
// Project the current point
Vec2F32 projected_point = project(point);
// save the projected 2D vector in the array of projected_points
projected_points[i] = projected_point;
}
}
void render(void) {
// FrameMarkStart("render");
draw_grid(0xFFFFFFFF);
draw_dots(0xFFFFFFFF);
// Loop all projected points and render them
for (int i = 0; i < POINTS; i++) {
Vec2F32 projected_point = projected_points[i];
draw_rect(projected_point.x, projected_point.y, 4, 4, 0xFFFFFF00);
}
// SDL_SetRenderDrawColor(renderer, 28, 450, 560, 255);
// SDL_RenderClear(renderer);
SDL_SetRenderDrawColor(renderer, 28, 450, 560, 255);
SDL_RenderClear(renderer);
render_colour_buffer();
// clear_colour_buffer(0xFF384893);
clear_colour_buffer(0xFF384893);
clear_colour_buffer(0xFF000000);
SDL_RenderPresent(renderer);

View File

@ -79,4 +79,6 @@ void draw_rect(s32 x, s32 y, s32 width, s32 height, s32 colour) {
}
}
void draw_pixel(u32 x, u32 y, u32 colour) { colour_buffer[(window_width * y) + x] = colour; }
void draw_pixel(u32 x, u32 y, u32 colour) {
colour_buffer[(window_width * y) + x] = colour;
}