Fullscreen
This commit is contained in:
@@ -24,6 +24,7 @@ void input_pollKeyDown(SDL_Scancode code) {
|
|||||||
printf("Scancode: %d\n", code);
|
printf("Scancode: %d\n", code);
|
||||||
keyEvent_t * handlers = eventsKeyDown[code];
|
keyEvent_t * handlers = eventsKeyDown[code];
|
||||||
for(int i = 0; i < eventKeyDown_counts[code]; i++) {
|
for(int i = 0; i < eventKeyDown_counts[code]; i++) {
|
||||||
|
printf("Given\n");
|
||||||
handlers[i]();
|
handlers[i]();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -63,7 +63,7 @@ static void game_loop(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(void) {
|
int main(int argc, char ** argv) {
|
||||||
TTF_Init();
|
TTF_Init();
|
||||||
if(Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096) != 0){
|
if(Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096) != 0){
|
||||||
printf("Music sound could not be open!\n"
|
printf("Music sound could not be open!\n"
|
||||||
@@ -75,7 +75,7 @@ int main(void) {
|
|||||||
timecode = clock();
|
timecode = clock();
|
||||||
|
|
||||||
Mix_Init(MIX_INIT_MP3);
|
Mix_Init(MIX_INIT_MP3);
|
||||||
renderer_main(game_setup, game_loop);
|
renderer_main(argc, argv, game_setup, game_loop);
|
||||||
|
|
||||||
Mix_CloseAudio();
|
Mix_CloseAudio();
|
||||||
text_freeFontCache();
|
text_freeFontCache();
|
||||||
|
|||||||
+31
-3
@@ -4,7 +4,9 @@
|
|||||||
#include <SDL2/SDL_error.h>
|
#include <SDL2/SDL_error.h>
|
||||||
#include <SDL2/SDL_rect.h>
|
#include <SDL2/SDL_rect.h>
|
||||||
#include <SDL2/SDL_render.h>
|
#include <SDL2/SDL_render.h>
|
||||||
|
#include <SDL2/SDL_scancode.h>
|
||||||
#include <SDL2/SDL_timer.h>
|
#include <SDL2/SDL_timer.h>
|
||||||
|
#include <SDL2/SDL_video.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -19,20 +21,47 @@ SDL_Window* win;
|
|||||||
SDL_Renderer * renderer;
|
SDL_Renderer * renderer;
|
||||||
const Scene_t * scene;
|
const Scene_t * scene;
|
||||||
int scenesCount = 0;
|
int scenesCount = 0;
|
||||||
|
bool fullscreen = false;
|
||||||
|
|
||||||
|
|
||||||
|
static void toggleFullscreen(void) {
|
||||||
|
printf("Toggling\n");
|
||||||
|
if(!fullscreen) {
|
||||||
|
SDL_SetWindowFullscreen(win, SDL_WINDOW_FULLSCREEN);
|
||||||
|
fullscreen = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
SDL_SetWindowFullscreen(win, 0);
|
||||||
|
fullscreen = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//int (*compar)(const void [.size], const void [.size], void *)
|
//int (*compar)(const void [.size], const void [.size], void *)
|
||||||
void renderer_main(void(*game_setup)(void), void(*game_loop)(void)) {
|
void renderer_main(int argc, char ** argv, void(*game_setup)(void), void(*game_loop)(void)) {
|
||||||
// returns zero on success else non-zero
|
// returns zero on success else non-zero
|
||||||
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
|
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
|
||||||
printf("error initializing SDL: %s\n", SDL_GetError());
|
printf("error initializing SDL: %s\n", SDL_GetError());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int width = 1280;
|
||||||
|
int height = 720;
|
||||||
|
|
||||||
|
if(argc > 2) {
|
||||||
|
width = atoi(argv[1]);
|
||||||
|
height = atoi(argv[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
win = SDL_CreateWindow("The legend of ADAM", // creates a window
|
win = SDL_CreateWindow("The legend of ADAM", // creates a window
|
||||||
SDL_WINDOWPOS_CENTERED,
|
SDL_WINDOWPOS_CENTERED,
|
||||||
SDL_WINDOWPOS_CENTERED,
|
SDL_WINDOWPOS_CENTERED,
|
||||||
1280, 720, 0);
|
width, height, 0);
|
||||||
|
|
||||||
Uint32 render_flags = SDL_RENDERER_ACCELERATED;
|
Uint32 render_flags = SDL_RENDERER_ACCELERATED;
|
||||||
|
|
||||||
|
input_init();
|
||||||
|
input_listenKeyDown(SDL_SCANCODE_F11, toggleFullscreen);
|
||||||
|
|
||||||
// creates a renderer to render our images
|
// creates a renderer to render our images
|
||||||
renderer = SDL_CreateRenderer(win, -1, render_flags);
|
renderer = SDL_CreateRenderer(win, -1, render_flags);
|
||||||
|
|
||||||
@@ -42,7 +71,6 @@ void renderer_main(void(*game_setup)(void), void(*game_loop)(void)) {
|
|||||||
|
|
||||||
SDL_GetRendererOutputSize(renderer, &monitorSize.width, &monitorSize.height);
|
SDL_GetRendererOutputSize(renderer, &monitorSize.width, &monitorSize.height);
|
||||||
|
|
||||||
input_init();
|
|
||||||
|
|
||||||
running = true;
|
running = true;
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -16,7 +16,7 @@ typedef struct MonitorSize {
|
|||||||
int width, height;
|
int width, height;
|
||||||
} MonitorSize_t;
|
} MonitorSize_t;
|
||||||
|
|
||||||
void renderer_main(void(*game_setup)(void), void(*game_loop)(void));
|
void renderer_main(int argc, char ** argv, void(*game_setup)(void), void(*game_loop)(void));
|
||||||
MonitorSize_t renderer_getMonitorSize(void);
|
MonitorSize_t renderer_getMonitorSize(void);
|
||||||
void renderer_setScene(const Scene_t * newScene);
|
void renderer_setScene(const Scene_t * newScene);
|
||||||
const Scene_t * renderer_getScene(void);
|
const Scene_t * renderer_getScene(void);
|
||||||
|
|||||||
@@ -62,8 +62,6 @@ RenderId_t scene_addRenderObject(Scene_t * scene, RenderObject_t object, int x,
|
|||||||
scene->objectCount++;
|
scene->objectCount++;
|
||||||
RenderId_t itemId = scene->lastId++;
|
RenderId_t itemId = scene->lastId++;
|
||||||
|
|
||||||
printf("adding item: %s: %d\n", object.name, itemId);
|
|
||||||
|
|
||||||
if(scene->objectCount * sizeof(SceneObject_t) > scene->objectArraySize) {
|
if(scene->objectCount * sizeof(SceneObject_t) > scene->objectArraySize) {
|
||||||
scene->objectArraySize = scene->objectCount * sizeof(SceneObject_t);
|
scene->objectArraySize = scene->objectCount * sizeof(SceneObject_t);
|
||||||
scene->objects = realloc(scene->objects, scene->objectArraySize);
|
scene->objects = realloc(scene->objects, scene->objectArraySize);
|
||||||
@@ -121,9 +119,6 @@ void scene_removeRenderObject(Scene_t * scene, RenderId_t id) {
|
|||||||
if(index < 0)
|
if(index < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
printf("removing item: %s: %d\n", scene->objects[index].renderObj.name, id);
|
|
||||||
|
|
||||||
|
|
||||||
scene->objectCount--;
|
scene->objectCount--;
|
||||||
|
|
||||||
for(int i = index; i < scene->objectCount; i++) {
|
for(int i = index; i < scene->objectCount; i++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user