Dawn/src/game/game.c

62 lines
1.2 KiB
C

/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "game.h"
game_t GAME_STATE;
bool gameInit() {
// Init the game
GAME_STATE.name = GAME_NAME;
// Init the renderer.
gameTimeInit();
renderInit();
inputInit();
worldInit();
// Load the world shader.
GAME_STATE.shaderWorld = assetShaderLoad(
"shaders/test.vert", "shaders/test.frag"
);
entityInit(0x00, 0x01);
// Init the input manger.
return true;
}
bool gameUpdate() {
gameTimeUpdate();
renderFrameStart();
inputUpdate();
// Attach the world shader
shaderUse(GAME_STATE.shaderWorld);
// Set up the camera.
int32_t d = 10;
cameraLookAt(&GAME_STATE.cameraWorld, d, d, d, 0, 0, 0);
cameraPerspective(&GAME_STATE.cameraWorld, 45.0f,
((float)RENDER_STATE.width) / ((float)RENDER_STATE.height),
0.5f, 500.0f
);
shaderUseCamera(GAME_STATE.shaderWorld, &GAME_STATE.cameraWorld);
// Render the game scene.
worldRender();
if(inputIsPressed(INPUT_NULL)) return false;
return true;
}
void gameDispose() {
shaderDispose(GAME_STATE.shaderWorld);
worldDispose();
inputDispose();
renderDispose();
}