Court is now in session
This commit is contained in:
@ -30,6 +30,9 @@
|
||||
#define HOLDEM_GAME_FRAME_RIGHT_WIDTH (\
|
||||
RENDER_STATE.width - HOLDEM_GAME_FRAME_LEFT_WIDTH - 1\
|
||||
)
|
||||
#define HOLDEM_GAME_CARD_WIDTH 0.05
|
||||
#define HOLDEM_GAME_CARD_HEIGHT 0.07
|
||||
#define HOLDEM_GAME_CARD_DEPTH 0.001
|
||||
|
||||
|
||||
/** Texas Hold'em Player State */
|
||||
@ -71,13 +74,16 @@ typedef struct {
|
||||
holdemplayer_t players[HOLDEM_PLAYER_COUNT];
|
||||
} holdemmatch_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
holdemmatch_t match;
|
||||
|
||||
texture_t *kagamiTexture;
|
||||
tileset_t *kagamiTileset;
|
||||
primitive_t *kagamiQuad;
|
||||
|
||||
primitive_t *cube;
|
||||
texture_t *texture;
|
||||
texture_t *cardTexture;
|
||||
tileset_t *cardTileset;
|
||||
primitive_t *cardPrimitive;
|
||||
|
||||
/** Game Render Frames */
|
||||
framebuffer_t *frameLeft;
|
||||
|
@ -10,6 +10,8 @@ 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;
|
||||
@ -19,9 +21,36 @@ void holdemGameInit() {
|
||||
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);
|
||||
|
||||
//TESTING
|
||||
HOLDEM_GAME_STATE.cube = cubeCreate(1, 1, 1);
|
||||
HOLDEM_GAME_STATE.texture = assetTextureLoad("bruh.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);
|
||||
@ -38,37 +67,49 @@ void holdemGameUpdate() {
|
||||
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, 0, lWidth, height, 1, 1, 0, 0);
|
||||
quadBuffer(HOLDEM_GAME_STATE.quadRight, 0, 0, 0, 0, 0, rWidth, height, 1, 1, 0, 0);
|
||||
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, 75,
|
||||
((float)lWidth/height), 0.25f, 100.0f
|
||||
cameraPerspective(&HOLDEM_GAME_STATE.cameraLeft, 45,
|
||||
((float)lWidth/height), 1.0f, 1000.0f
|
||||
);
|
||||
cameraLookAt(&HOLDEM_GAME_STATE.cameraLeft, 5, 5, 5, 0, 0, 0);
|
||||
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, 5, 5, 0, 0, 0);
|
||||
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);
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "../../display/shader.h"
|
||||
#include "../../display/camera.h"
|
||||
#include "../../display/primitives/cube.h"
|
||||
#include "../../display/tileset.h"
|
||||
#include "../../display/primitives/quad.h"
|
||||
#include "../../file/asset.h"
|
||||
|
||||
|
@ -7,9 +7,53 @@
|
||||
|
||||
#include "holdemrender.h"
|
||||
|
||||
void holdemRenderWorld() {
|
||||
shaderUseTexture(GAME_STATE.shaderWorld, HOLDEM_GAME_STATE.texture);
|
||||
shaderUsePosition(GAME_STATE.shaderWorld, 0, 0, 0, 0, 0, 0);
|
||||
shaderUsePosition(GAME_STATE.shaderWorld, 0, 0, 0, TIME_STATE.current, TIME_STATE.current, 0);
|
||||
primitiveDraw(HOLDEM_GAME_STATE.cube, 0, -1);
|
||||
void holdemRenderPlayer(float x, float y, float z, float yaw) {
|
||||
float w, h;
|
||||
w = 1, h = (
|
||||
(float)HOLDEM_GAME_STATE.kagamiTileset->divY /
|
||||
(float)HOLDEM_GAME_STATE.kagamiTileset->divX
|
||||
);
|
||||
|
||||
int i = (int32_t)(TIME_STATE.current*10)%HOLDEM_GAME_STATE.kagamiTileset->count;
|
||||
quadBuffer(HOLDEM_GAME_STATE.kagamiQuad, 0,
|
||||
-w/2, -h/2,
|
||||
HOLDEM_GAME_STATE.kagamiTileset->divisions[i].x0,
|
||||
HOLDEM_GAME_STATE.kagamiTileset->divisions[i].y1,
|
||||
w/2, h/2,
|
||||
HOLDEM_GAME_STATE.kagamiTileset->divisions[i].x1,
|
||||
HOLDEM_GAME_STATE.kagamiTileset->divisions[i].y0,
|
||||
0, 0
|
||||
);
|
||||
|
||||
shaderUseTexture(GAME_STATE.shaderWorld, HOLDEM_GAME_STATE.kagamiTexture);
|
||||
shaderUsePosition(GAME_STATE.shaderWorld, x, y, z, 0, mathDeg2Rad(yaw), 0);
|
||||
primitiveDraw(HOLDEM_GAME_STATE.kagamiQuad, 0, -1);
|
||||
}
|
||||
|
||||
void holdemRenderCard(card_t card,
|
||||
float x, float y, float z, float pitch, float yaw, float roll
|
||||
) {
|
||||
tilesetdiv_t *cardFront = HOLDEM_GAME_STATE.cardTileset->divisions + card;
|
||||
quadBuffer(HOLDEM_GAME_STATE.cardPrimitive, HOLDEM_GAME_CARD_DEPTH,
|
||||
-HOLDEM_GAME_CARD_WIDTH, -HOLDEM_GAME_CARD_HEIGHT,
|
||||
cardFront->x0, cardFront->y1,
|
||||
HOLDEM_GAME_CARD_WIDTH, HOLDEM_GAME_CARD_HEIGHT,
|
||||
cardFront->x1, cardFront->y0,
|
||||
0, 0
|
||||
);
|
||||
|
||||
shaderUseTexture(GAME_STATE.shaderWorld, HOLDEM_GAME_STATE.cardTexture);
|
||||
shaderUsePosition(GAME_STATE.shaderWorld, x, y, z, pitch, yaw, roll);
|
||||
primitiveDraw(HOLDEM_GAME_STATE.cardPrimitive, 0, -1);
|
||||
}
|
||||
|
||||
void holdemRenderWorld() {
|
||||
holdemRenderCard(CARD_HEARTS_QUEEN, 0, 0, 0, mathDeg2Rad(-90), 0, 0);
|
||||
|
||||
// Draw the players
|
||||
holdemRenderPlayer(0, 0, -1, 0);
|
||||
holdemRenderPlayer(-1, 0, -0, 90);
|
||||
holdemRenderPlayer(-0.75, 0, 0.75, -45);
|
||||
holdemRenderPlayer(0.75, 0, 0.75, 45);
|
||||
holdemRenderPlayer(1, 0, 0, -90);
|
||||
}
|
@ -9,5 +9,11 @@
|
||||
#include <dawn/dawn.h>
|
||||
#include "../../../display/shader.h"
|
||||
#include "../../../display/primitive.h"
|
||||
#include "../../../display/primitives/quad.h"
|
||||
#include "../../../util/math.h"
|
||||
|
||||
void holdemRenderPlayer(float x, float y, float z, float yaw);
|
||||
void holdemRenderCard(card_t card,
|
||||
float x, float y, float z, float pitch, float yaw, float roll
|
||||
);
|
||||
void holdemRenderWorld();
|
@ -10,6 +10,7 @@
|
||||
void cameraLookAt(camera_t *camera,
|
||||
float x, float y, float z, float targetX, float targetY, float targetZ
|
||||
) {
|
||||
glm_mat4_identity(camera->view);
|
||||
glm_lookat(
|
||||
(vec3){ x, y, z },
|
||||
(vec3){ targetX, targetY, targetZ },
|
||||
@ -22,6 +23,7 @@ void cameraLook(camera_t *camera,
|
||||
float x, float y, float z,
|
||||
float pitch, float yaw, float roll
|
||||
) {
|
||||
glm_mat4_identity(camera->view);
|
||||
glm_look(
|
||||
(vec3){ x, y, z },
|
||||
(vec3){ pitch, yaw, roll },
|
||||
@ -33,11 +35,13 @@ void cameraLook(camera_t *camera,
|
||||
void cameraPerspective(camera_t *camera,
|
||||
float fov, float aspect, float near, float far
|
||||
) {
|
||||
glm_perspective(fov, aspect, near, far, camera->projection);
|
||||
glm_mat4_identity(camera->projection);
|
||||
glm_perspective(mathDeg2Rad(fov), aspect, near, far, camera->projection);
|
||||
}
|
||||
|
||||
void cameraOrtho(camera_t *camera,
|
||||
float left, float right, float bottom, float top, float near, float far
|
||||
) {
|
||||
glm_mat4_identity(camera->projection);
|
||||
glm_ortho(left, right, bottom, top, near, far, camera->projection);
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
|
||||
#pragma once
|
||||
#include <dawn/dawn.h>
|
||||
#include "../util/math.h"
|
||||
|
||||
/**
|
||||
* Make a camera look at a position in world space while itself being positioned
|
||||
@ -42,7 +43,7 @@ void cameraLook(camera_t *camera,
|
||||
* Make a camera's projection be a 3D Perspective view.
|
||||
*
|
||||
* @param camera The camera to project.
|
||||
* @param fov The field of view of the camera.
|
||||
* @param fov The field of view of the camera (in degrees).
|
||||
* @param aspect The aspect ratio of the camera (w / h)
|
||||
* @param near The near plane clip.
|
||||
* @param far the far plane clip.
|
||||
|
@ -11,6 +11,10 @@ framebuffer_t * frameBufferCreate(int32_t w, int32_t h) {
|
||||
framebuffer_t *fb = malloc(sizeof(framebuffer_t));
|
||||
if(fb == NULL) return NULL;
|
||||
|
||||
// At least one pixel
|
||||
if(w <= 0) w = 1;
|
||||
if(h <= 0) h = 1;
|
||||
|
||||
// Create Color Attachment texture.
|
||||
fb->texture = textureCreate(w, h, NULL);
|
||||
if(fb->texture == NULL) {
|
||||
|
@ -103,8 +103,8 @@ void shaderUse(shader_t *shader) {
|
||||
}
|
||||
|
||||
void shaderUseCamera(shader_t *shader, camera_t *camera) {
|
||||
glUniformMatrix4fv(shader->uniView, 1, GL_FALSE, (float*)camera->view);
|
||||
glUniformMatrix4fv(shader->uniProj, 1, GL_FALSE, (float*)camera->projection);
|
||||
glUniformMatrix4fv(shader->uniView, 1, GL_FALSE, camera->view[0]);
|
||||
glUniformMatrix4fv(shader->uniProj, 1, GL_FALSE, camera->projection[0]);
|
||||
}
|
||||
|
||||
void shaderUseTexture(shader_t *shader, texture_t *texture) {
|
||||
@ -131,11 +131,13 @@ void shaderUsePosition(shader_t *shader,
|
||||
//Rotation, we do each axis individually
|
||||
axis[0] = 1, axis[1] = 0, axis[2] = 0;
|
||||
glm_rotate(MATRIX_POSITION, pitch, axis);
|
||||
|
||||
axis[0] = 0, axis[1] = 1;
|
||||
glm_rotate(MATRIX_POSITION, yaw, axis);
|
||||
|
||||
axis[1] = 0, axis[2] = 1;
|
||||
glm_rotate(MATRIX_POSITION, roll, axis);
|
||||
|
||||
//Send to the shader.
|
||||
glUniformMatrix4fv(shader->uniModl, 1, GL_FALSE, (float*)MATRIX_POSITION);
|
||||
glUniformMatrix4fv(shader->uniModl, 1, GL_FALSE, MATRIX_POSITION[0]);
|
||||
}
|
@ -11,6 +11,11 @@ game_t *runningGame = NULL;
|
||||
int32_t main() {
|
||||
// Attempt to init GLFW
|
||||
if(!glfwInit()) return NULL;
|
||||
|
||||
// Setup window hints
|
||||
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, false);
|
||||
|
||||
// Create Window
|
||||
window = glfwCreateWindow(WINDOW_WIDTH_DEFAULT, WINDOW_HEIGHT_DEFAULT,
|
||||
"", NULL, NULL
|
||||
);
|
||||
@ -28,6 +33,8 @@ int32_t main() {
|
||||
glfwSetWindowSizeCallback(window, &glfwOnResize);
|
||||
glfwSetKeyCallback(window, &glfwOnKey);
|
||||
|
||||
glfwSetErrorCallback (&glfwOnError);
|
||||
|
||||
// Init the game
|
||||
if(gameInit()) {
|
||||
// Bind initial keys
|
||||
@ -88,3 +95,7 @@ void glfwOnKey(GLFWwindow *window,
|
||||
INPUT_STATE.buffer[key] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void glfwOnError(int error, const char* description) {
|
||||
fputs(description, stderr);
|
||||
}
|
@ -43,3 +43,6 @@ void glfwOnResize(GLFWwindow *window, int32_t width, int32_t height);
|
||||
void glfwOnKey(GLFWwindow *window,
|
||||
int32_t key, int32_t scancode, int32_t action, int32_t mods
|
||||
);
|
||||
|
||||
|
||||
void glfwOnError(int error, const char* description);
|
@ -9,3 +9,5 @@
|
||||
#define mathMax(a,b) (a<b?b:a)
|
||||
#define mathMin(a,b) (a>b?b:a)
|
||||
#define mathAbs(n) (n<0?-n:n)
|
||||
#define mathDeg2Rad(n) (n * M_PI / 180.0)
|
||||
#define mathRad2Deg(n) (n * 180 / M_PI)
|
Reference in New Issue
Block a user