Dawn/src/engine/engine.c
2021-04-03 22:44:11 +11:00

67 lines
1.4 KiB
C

/**
* Copyright (c) 2021 Dominic Msters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "engine.h"
camera_t *camera;
shader_t *shader;
primitive_t *cube;
engine_t * engineInit(platform_t *platform, char *name, uint32_t inputCount) {
// Create the engine instance.
engine_t *engine = malloc(sizeof(engine_t));
if(engine == NULL) return NULL;
engine->name = name;
engine->platform = platform;
// Setup the renderer.
engine->render = renderInit(name);
if(engine->render == NULL) {
free(engine);
return NULL;
}
// Setup the input manager.
engine->input = inputInit(inputCount, platform->inputSourceCount);
if(engine->input == NULL) {
free(engine->render);
free(engine);
return NULL;
}
shader = assetShaderLoad("shaders/test.vert", "shaders/test.frag");
camera = cameraCreate();
cameraLookAt(camera,
3, 3, 3,
0, 0, 0
);
cameraPerspective(camera, 45.0f, 1920.0f/1080.0f, 0.5f, 100.0f);
shaderUseCamera(shader, camera);
// cube = quadCreate(0, 0, 0, 0, 1, 1, 1, 1);
cube = cubeCreate(1, 1, 1);
return engine;
}
uint32_t engineUpdate(engine_t *engine) {
shaderUse(shader);
renderFrame(engine->render);
primitiveDraw(cube, 0, cube->indiceCount);
inputUpdate(engine->input);
return 0;
}
bool engineDispose(engine_t *engine) {
if(!renderDispose(engine->render)) return false;
free(engine);
return true;
}