Added functionality to print grid to screen
This commit is contained in:
29
src/main.c
29
src/main.c
@@ -22,6 +22,13 @@ bool initialize_window(void) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Use SDL to query what is the fullscreen max. width and height
|
||||||
|
SDL_DisplayMode display_mode;
|
||||||
|
SDL_GetCurrentDisplayMode(0, &display_mode);
|
||||||
|
|
||||||
|
window_width = display_mode.w;
|
||||||
|
window_height = display_mode.h;
|
||||||
|
|
||||||
// Create a SDL window
|
// Create a SDL window
|
||||||
window = SDL_CreateWindow(
|
window = SDL_CreateWindow(
|
||||||
NULL,
|
NULL,
|
||||||
@@ -42,10 +49,18 @@ bool initialize_window(void) {
|
|||||||
fprintf(stderr, "Error creating SDL error.\n");
|
fprintf(stderr, "Error creating SDL error.\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// SDL_RenderDrawLine(&render_grid, 100, 100, 300, 300);
|
||||||
|
|
||||||
|
|
||||||
void setup(void){
|
void setup(void){
|
||||||
// Allocates the memory in bytes required to hold for color_buffer, using sizeof to allocate the # of bytes required
|
// Allocates the memory in bytes required to hold for color_buffer, using sizeof to allocate the # of bytes required
|
||||||
color_buffer = (uint32_t*) malloc(sizeof(uint32_t) * window_width * window_height);
|
color_buffer = (uint32_t*) malloc(sizeof(uint32_t) * window_width * window_height);
|
||||||
@@ -96,13 +111,23 @@ void clear_color_buffer(uint32_t color){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void draw_grid(void){
|
||||||
|
for (int y = 0; y < window_height; y += 10){
|
||||||
|
for (int x = 0; x < window_width; x += 10){
|
||||||
|
// if (x % 10 == 0 || y % 10 == 0){
|
||||||
|
color_buffer[(window_width * y) + x] = 0xFF333333;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// }
|
||||||
|
|
||||||
void render(void){
|
void render(void){
|
||||||
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
|
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer);
|
||||||
|
|
||||||
|
draw_grid();
|
||||||
render_color_buffer();
|
render_color_buffer();
|
||||||
|
clear_color_buffer(0xFF000000);
|
||||||
clear_color_buffer(0xFFFFFF00);
|
|
||||||
|
|
||||||
SDL_RenderPresent(renderer);
|
SDL_RenderPresent(renderer);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user