Added frame buffer support.

This commit is contained in:
2021-05-05 07:37:25 -07:00
parent 469750b0a0
commit c3244274ce
10 changed files with 168 additions and 44 deletions

View File

@ -9,11 +9,9 @@
game_t GAME_STATE;
holdemgame_t holdem;
holdemrender_t render;
texture_t *fontTexture;
spritebatch_t *fontBatch;
primitive_t *prim;
framebuffer_t *fbo;
texture_t *text;
bool gameInit() {
// Init the game
@ -25,29 +23,14 @@ bool gameInit() {
inputInit();
worldInit();
holdemGameInit(&holdem);
holdemRenderInit(&render);
prim = cubeCreate(1, 1, 1);
text = assetTextureLoad("bruh.png");
holdemRoundInit(&holdem);
cardShuffle(holdem.deck, holdem.deckSize);
// Deal Card
holdemDealAll(&holdem, 2);
holdemFlop(&holdem);
fontTexture = assetTextureLoad("font.png");
fontBatch = spriteBatchCreate(100);
tileset_t *tileset = tilesetCreate(20, 20,
fontTexture->width, fontTexture->height,
1, 1, 1, 1
);
char *buffer = "!\"#$%";
fontSpriteBatchBuffer(fontBatch, tileset, buffer, 0, 0, 0, 1.1, 1.5);
fbo = frameBufferCreate(128, 128);
// Load the world shader.
GAME_STATE.shaderWorld = assetShaderLoad(
"shaders/test.vert", "shaders/test.frag"
"shaders/textured.vert", "shaders/textured.frag"
);
// Init the input manger.
@ -59,25 +42,27 @@ bool gameUpdate(float platformDelta) {
renderFrameStart();
inputUpdate();
// Attach the world shader
// Set up the camera and shader.
shaderUse(GAME_STATE.shaderWorld);
frameBufferUse(fbo, true);
cameraLookAt(&GAME_STATE.cameraWorld, 2, 2, 2, 0, 0, 0);
cameraPerspective(&GAME_STATE.cameraWorld, 45.0f,
((float)fbo->texture->width) / ((float)fbo->texture->height),
0.5f, 500.0f
);
shaderUseCamera(GAME_STATE.shaderWorld, &GAME_STATE.cameraWorld);
shaderUsePosition(GAME_STATE.shaderWorld, 0, 0, 0, TIME_STATE.current, TIME_STATE.current, 0);
shaderUseTexture(GAME_STATE.shaderWorld, text);
primitiveDraw(prim, 0, prim->indiceCount);
// Set up the camera.
int x = 10;
cameraLookAt(&GAME_STATE.cameraWorld, x, 2.5f, 50, x, 2, 0);
frameBufferUse(NULL, true);
shaderUseTexture(GAME_STATE.shaderWorld, fbo->texture);
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);
shaderUseTexture(GAME_STATE.shaderWorld, fontTexture);
spriteBatchDraw(fontBatch, 0, -1);
// holdemRender(&render, &holdem);
// Render the game scene.
// worldRender();
primitiveDraw(prim, 0, prim->indiceCount);
if(inputIsPressed(INPUT_NULL)) return false;
return true;

View File

@ -11,13 +11,11 @@
#include "../display/shader.h"
#include "../file/asset.h"
#include "../input/input.h"
#include "../world/world.h"
#include "../world/entity/entity.h"
#include "../card/poker/holdem.h"
#include "../display/gui/font.h"
#include "../display/spritebatch.h"
#include "../display/tileset.h"
#include "../display/primitive.h"
#include "../display/framebuffer.h"
#include "../display/primitives/cube.h"
#include "../display/primitives/quad.h"
/**
* Initialize the game context.