Setup the boilerplate for SDL and init commit.
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_events.h>
|
||||
#include <SDL2/SDL_hints.h>
|
||||
#include <SDL2/SDL_keycode.h>
|
||||
#include <SDL2/SDL_mouse.h>
|
||||
#include <SDL2/SDL_pixels.h>
|
||||
#include <SDL2/SDL_rect.h>
|
||||
#include <SDL2/SDL_render.h>
|
||||
#include <SDL2/SDL_stdinc.h>
|
||||
#include <SDL2/SDL_thread.h>
|
||||
#include <SDL2/SDL_timer.h>
|
||||
#include <SDL2/SDL_video.h>
|
||||
#include <SDL2/SDL_image.h>
|
||||
#include <SDL2/SDL_ttf.h>
|
||||
|
||||
const int SCREEN_WIDTH = 1280;
|
||||
const int SCREEN_HEIGHT = 720;
|
||||
|
||||
typedef struct {
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
TTF_Font* font;
|
||||
} App;
|
||||
|
||||
App app;
|
||||
|
||||
void HandleInput(void);
|
||||
int Exit = 0;
|
||||
|
||||
void Cleanup(void) {
|
||||
SDL_DestroyWindow(app.window);
|
||||
SDL_DestroyRenderer(app.renderer);
|
||||
TTF_CloseFont(app.font);
|
||||
TTF_Quit();
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
int main(int argc, char** argv){
|
||||
memset(&app, 0, sizeof(app));
|
||||
|
||||
atexit(Cleanup);
|
||||
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||
printf("SDL failed: %s\n", SDL_GetError());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (TTF_Init() < 0) {
|
||||
printf("Failed to init TTF: %s\n", TTF_GetError());
|
||||
return -1;
|
||||
}
|
||||
|
||||
app.font = TTF_OpenFont("/usr/share/fonts/TTF/Hack-Regular.ttf", 14);
|
||||
|
||||
if (app.font == NULL) {
|
||||
printf("Failed to load font\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
app.window = SDL_CreateWindow("SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
|
||||
|
||||
if (app.window == NULL) {
|
||||
printf("Window creation failed: %s\n", SDL_GetError());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
|
||||
|
||||
app.renderer = SDL_CreateRenderer(app.window, -1, SDL_RENDERER_ACCELERATED);
|
||||
|
||||
if (app.renderer == NULL) {
|
||||
printf("Renderer failed: %s\n", SDL_GetError());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
void HandleInput(void) {
|
||||
SDL_Event event;
|
||||
while(SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_QUIT:
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
Exit = 1;
|
||||
break;
|
||||
case SDL_MOUSEMOTION:
|
||||
//if (MainMenu->HitCheck(event.motion.x, event.motion.y, &MainMenu->Area)) {
|
||||
case SDL_TEXTINPUT:
|
||||
case SDL_KEYDOWN:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user