Dawn/src/game/sandbox/game.c

78 lines
2.3 KiB
C

/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "game.h"
bool sandboxGameInit(sandboxgame_t *game) {
uint8_t i;
// Initialize the scene.
sceneInit(&game->scene, &game->engine);
// Load Shader
assetManagerLoadShader(&game->engine.assetManager, game->scene.assetOwner,
&game->shader, "shaders/textured.vert", "shaders/textured.frag"
);
// Load the texture
assetManagerLoadScaledTexture(
&game->engine.assetManager, game->scene.assetOwner,
&game->st, "poker/characters/sammy", "sprite"
);
assetManagerLoadTextureScale(
&game->engine.assetManager, game->scene.assetOwner,
&game->st, &game->texture, 0
);
quadInit(&game->quad, 0, 0,0,0,0, 500,500,1,1);
i = renderPassAdd(&game->scene.renderList, &game->shader);
return true;
}
void sandboxGameUpdate(sandboxgame_t *game) {
camera_t camera;
float n;
n = assetManagerProgressGet(&game->engine.assetManager);
if(n < 1.0f) return;
// First pass
sceneRenderStart(&game->scene);
renderListRenderPass(&game->scene.renderList, &game->engine, 0);
cameraOrtho(&camera,
0, game->engine.render.width,
game->engine.render.height, 0,
0.01f, 1000.0f
);
cameraLookAt(&camera, 0,0,10, 0,0,0);
shaderuniform_t uniView = shaderGetUniform(&game->shader, "u_View");
shaderuniform_t uniProj = shaderGetUniform(&game->shader, "u_Proj");
shaderuniform_t uniModel = shaderGetUniform(&game->shader, "u_Modl");
shaderuniform_t uniColor = shaderGetUniform(&game->shader, "u_Colr");
shaderuniform_t uniTexture = shaderGetUniform(&game->shader, "u_Text");
shaderUse(&game->shader);
shaderUseCamera(&game->shader, uniView, uniProj, &camera);
shaderUseColor(&game->shader, uniColor, PIXEL_COLOR_WHITE);
shaderUseTexture(&game->shader, uniTexture, &game->texture);
shaderUsePosition(&game->shader, uniModel, 0,0,0, 0,0,0);
primitiveDraw(&game->quad, 0, -1);
sceneRenderEnd(&game->scene, &game->shader,
uniView, uniProj, uniModel, &uniTexture,
&game->shader,
uniView, uniProj, uniModel, uniTexture
);
}
void sandboxGameDispose(sandboxgame_t *game) {
sceneDispose(&game->scene);
// assetManagerHolderRelease(&game->engine.assetManager, game->assetOwner);
// primitiveDispose(&game->quad);
}