When I run this program (C) :
#include <stdio.h>
#include <stdlib.h>
#include <SDL2/SDL.h>
#include "./constants.h"
int game_is_running = FALSE;
SDL_Window *window = NULL;
SDL_Renderer * renderer = NULL;
int initialize_window(void){
if(SDL_Init(SDL_INIT_EVERYTHING) != 0){
fprintf(stderr, "Error initializing SDLn");
return FALSE;
}
window = SDL_CreateWindow("SDL WINDOW", SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED, WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_BORDERLESS);
if (!window){
fprintf(stderr,"Error creating SDL Windown");
return FALSE;
}
SDL_Renderer * renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
if(!renderer){
fprintf(stderr,"Error creating renderern");
return FALSE;
}
return TRUE;
}
void setup(){
}
void update(){
}
void render(){
SDL_SetRenderDrawColor(renderer, 0,0,0,255);
SDL_RenderClear(renderer);
//Start drawing game objects
SDL_SetRenderDrawColor(renderer, 255,0,0,255);
SDL_RenderDrawLine(renderer,0,0,50,50);
SDL_RenderPresent(renderer);
}
void destroy_window(){
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
//exit(0);
}
int main(int argc, char **argv){
int game_is_running = initialize_window();
setup();
SDL_Event e;
while(game_is_running){
SDL_PollEvent(&e);
if(e.type ==SDL_KEYDOWN)
{
if(e.key.keysym.sym == SDLK_ESCAPE){
game_is_running = FALSE;
destroy_window();
}
}
update();
render();
}
destroy_window();
return 0;
}
I get an empty window that is transparent and has no color
This is a C program and I’m using gcc main.c -o game -lSDL2 -lSDL2main
to compile the program running on kali 2024.2
I tried taking the render() function and putting it in the while(game_is_running)
loop.
Also tried setting the SDL_Create_Renderer()
flag to 0.
I haven’t seen an answer to this online and this solution is not what I am looking for
Any help is greatly appreciated :))
(Also StackOverflow is detecting this as a cpp program but it’s in C)