/** * Copyright (c) 2021 Dominic Masters * * This software is released under the MIT License. * https://opensource.org/licenses/MIT */ #include "holdemgame.h" holdemgame_t HOLDEM_GAME_STATE; void holdemGameInit() { int32_t lWidth, rWidth, height; card_t card; tilesetdiv_t *cardBack; // Create the initial frame buffers lWidth = HOLDEM_GAME_FRAME_LEFT_WIDTH, rWidth = HOLDEM_GAME_FRAME_RIGHT_WIDTH; height = HOLDEM_GAME_FRAME_HEIGHT; HOLDEM_GAME_STATE.frameLeft = frameBufferCreate(lWidth, height); HOLDEM_GAME_STATE.frameRight = frameBufferCreate(rWidth, height); HOLDEM_GAME_STATE.quadLeft = quadCreate(0, 0, 0, 0, 0, lWidth, height, 1, 1); HOLDEM_GAME_STATE.quadRight = quadCreate(0, 0, 0, 0, 0, rWidth, height, 1, 1); // Font HOLDEM_GAME_STATE.fontTexture = assetTextureLoad("font.png"); HOLDEM_GAME_STATE.fontTileset = tilesetCreate(20, 20, HOLDEM_GAME_STATE.fontTexture->width, HOLDEM_GAME_STATE.fontTexture->height, 1, 1, 1, 1 ); HOLDEM_GAME_STATE.fontBatch = spriteBatchCreate(1024); // Poker Table HOLDEM_GAME_STATE.tablePrimitive = pokerTableCreate(); HOLDEM_GAME_STATE.tableTexture = assetTextureLoad("pokertable.png"); // Kagami HOLDEM_GAME_STATE.kagamiTexture = assetTextureLoad("kagami.png"); HOLDEM_GAME_STATE.kagamiTileset = tilesetCreate(3, 2, HOLDEM_GAME_STATE.kagamiTexture->width, HOLDEM_GAME_STATE.kagamiTexture->height, 0, 0, 0, 0 ); HOLDEM_GAME_STATE.kagamiQuad = quadCreate(0, 0, 0, 0, 0, 1, 1, 1, 1); // Load Cards Texture HOLDEM_GAME_STATE.cardTexture = assetTextureLoad("cards_normal.png"); HOLDEM_GAME_STATE.cardTileset = tilesetCreate(CARD_COUNT_PER_SUIT, 6, HOLDEM_GAME_STATE.cardTexture->width, HOLDEM_GAME_STATE.cardTexture->height, 0, 0, 0, 0 ); // Cards Primitive cardBack = HOLDEM_GAME_STATE.cardTileset->divisions+( HOLDEM_GAME_STATE.cardTileset->columns * 4 ); HOLDEM_GAME_STATE.cardPrimitive = primitiveCreate( QUAD_VERTICE_COUNT * 2, QUAD_INDICE_COUNT * 2 ); quadBuffer(HOLDEM_GAME_STATE.cardPrimitive, -HOLDEM_GAME_CARD_DEPTH, -HOLDEM_GAME_CARD_WIDTH, -HOLDEM_GAME_CARD_HEIGHT, cardBack->x0, cardBack->y1, HOLDEM_GAME_CARD_WIDTH, HOLDEM_GAME_CARD_HEIGHT, cardBack->x1, cardBack->y0, QUAD_VERTICE_COUNT, QUAD_INDICE_COUNT ); // Prepare match holdemMatchInit(&HOLDEM_GAME_STATE.match); holdemRoundInit(&HOLDEM_GAME_STATE.match); cardShuffle(HOLDEM_GAME_STATE.match.deck, HOLDEM_GAME_STATE.match.deckSize); holdemFlop(&HOLDEM_GAME_STATE.match); } void holdemGameUpdate() { int32_t lWidth, rWidth, height; if(true) { cameraPerspective(&HOLDEM_GAME_STATE.cameraLeft, 45, ((float)RENDER_STATE.width/(float)RENDER_STATE.height), 1.0f, 1000.0f ); cameraLookAt(&HOLDEM_GAME_STATE.cameraLeft, 2, 2, 2, 0, 0, 0); shaderUseCamera(GAME_STATE.shaderWorld, &HOLDEM_GAME_STATE.cameraLeft); holdemRenderWorld(); return; } // Resize Frame buffers. lWidth = HOLDEM_GAME_FRAME_LEFT_WIDTH, rWidth = HOLDEM_GAME_FRAME_RIGHT_WIDTH; height = HOLDEM_GAME_FRAME_HEIGHT; if( HOLDEM_GAME_STATE.frameLeft->texture->width != lWidth || HOLDEM_GAME_STATE.frameLeft->texture->height != height ) { frameBufferDispose(HOLDEM_GAME_STATE.frameLeft); frameBufferDispose(HOLDEM_GAME_STATE.frameRight); HOLDEM_GAME_STATE.frameLeft = frameBufferCreate(lWidth, height); HOLDEM_GAME_STATE.frameRight = frameBufferCreate(rWidth, height); quadBuffer(HOLDEM_GAME_STATE.quadLeft, 0, 0, 0, 0, 1, lWidth, height, 1, 0, 0, 0 ); quadBuffer(HOLDEM_GAME_STATE.quadRight, 0, 0, 0, 0, 1, rWidth, height, 1, 0, 0, 0 ); } // Render things on the left frame buffer glClearColor(0.3, 0, 0, 1); frameBufferUse(HOLDEM_GAME_STATE.frameLeft, true); cameraPerspective(&HOLDEM_GAME_STATE.cameraLeft, 45, ((float)lWidth/height), 1.0f, 1000.0f ); cameraLookAt(&HOLDEM_GAME_STATE.cameraLeft, 2, 2, 2, 0, 0, 0); shaderUseCamera(GAME_STATE.shaderWorld, &HOLDEM_GAME_STATE.cameraLeft); holdemRenderWorld(); // Render things on the right frame buffer glClearColor(0.3, 0.3, 0, 1); frameBufferUse(HOLDEM_GAME_STATE.frameRight, true); cameraPerspective(&HOLDEM_GAME_STATE.cameraRight, 45, ((float)rWidth/height), 0.25f, 100.0f ); cameraLookAt(&HOLDEM_GAME_STATE.cameraRight, 0, 3, 3, 0, 0, 0); shaderUseCamera(GAME_STATE.shaderWorld, &HOLDEM_GAME_STATE.cameraRight); holdemRenderWorld(); // Finally, render the frame buffers to the back buffer. glClearColor(0, 0, 0, 1); frameBufferUse(NULL, true); cameraOrtho(&GAME_STATE.cameraWorld, 0, RENDER_STATE.width, RENDER_STATE.height, 1, 0, 1 ); cameraLookAt(&GAME_STATE.cameraWorld, 0, 0, 0.5f, 0, 0, 0); shaderUseCamera(GAME_STATE.shaderWorld, &GAME_STATE.cameraWorld); // L shaderUsePosition(GAME_STATE.shaderWorld, 0, 0, 0, 0, 0, 0); shaderUseTexture(GAME_STATE.shaderWorld, HOLDEM_GAME_STATE.frameLeft->texture); primitiveDraw(HOLDEM_GAME_STATE.quadLeft, 0, -1); // R shaderUsePosition(GAME_STATE.shaderWorld, RENDER_STATE.width-rWidth, 0, 0, 0, 0, 0 ); shaderUseTexture(GAME_STATE.shaderWorld, HOLDEM_GAME_STATE.frameRight->texture); primitiveDraw(HOLDEM_GAME_STATE.quadRight, 0, -1); }