Refactored.
This commit is contained in:
@ -7,16 +7,6 @@
|
||||
|
||||
#include "camera.h"
|
||||
|
||||
camera_t * cameraCreate() {
|
||||
camera_t *camera = malloc(sizeof(camera_t));
|
||||
if(!camera) return NULL;
|
||||
return camera;
|
||||
}
|
||||
|
||||
void cameraDispose(camera_t *camera) {
|
||||
free(camera);
|
||||
}
|
||||
|
||||
void cameraLookAt(camera_t *camera,
|
||||
float x, float y, float z, float targetX, float targetY, float targetZ
|
||||
) {
|
||||
|
@ -4,31 +4,7 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include <cglm/cglm.h>
|
||||
#include <malloc.h>
|
||||
|
||||
/** The math for the camera is stored here. */
|
||||
typedef struct {
|
||||
/** View Matrix (Where the camera looks) */
|
||||
mat4 view;
|
||||
|
||||
/** Projection Matrix (How the camera looks) */
|
||||
mat4 projection;
|
||||
} camera_t;
|
||||
|
||||
/**
|
||||
* Create a new camera instance.
|
||||
*
|
||||
* @return A new camera instance.
|
||||
*/
|
||||
camera_t * cameraCreate();
|
||||
|
||||
/**
|
||||
* Cleanup a previously created camera
|
||||
*
|
||||
* @param camera Camera instance to dispose.
|
||||
*/
|
||||
void cameraDispose(camera_t *camera);
|
||||
#include <dawn/dawn.h>
|
||||
|
||||
/**
|
||||
* Make a camera look at a position in world space while itself being positioned
|
||||
|
@ -6,30 +6,7 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <glad/glad.h>
|
||||
#include <malloc.h>
|
||||
|
||||
#define PRIMITIVE_POSITIONS_PER_VERTICE 3
|
||||
#define PRIMITIVE_COORDINATES_PER_VERTICE 2
|
||||
|
||||
/** Structure containing information about a primitive */
|
||||
typedef struct {
|
||||
int32_t verticeCount;
|
||||
int32_t indiceCount;
|
||||
|
||||
GLuint vertexBuffer;
|
||||
GLuint indexBuffer;
|
||||
} primitive_t;
|
||||
|
||||
/** Structure containing vertice position information */
|
||||
typedef struct {
|
||||
float x, y, z;
|
||||
float u, v;
|
||||
} vertice_t;
|
||||
|
||||
/** Indice that references a specific vertice */
|
||||
typedef unsigned int indice_t;
|
||||
#include <dawn/dawn.h>
|
||||
|
||||
/**
|
||||
* Creates a new primitive.
|
||||
|
@ -4,8 +4,7 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <malloc.h>
|
||||
#include <dawn/dawn.h>
|
||||
#include "../primitive.h"
|
||||
|
||||
#define CUBE_VERTICE_COUNT 8
|
||||
|
@ -46,7 +46,9 @@ primitive_t * quadCreate(float z,
|
||||
float x0, float y0, float u0, float v0,
|
||||
float x1, float y1, float u1, float v1
|
||||
) {
|
||||
primitive_t *primitive = primitiveCreate(4, 6);
|
||||
primitive_t *primitive = primitiveCreate(
|
||||
QUAD_VERTICE_COUNT, QUAD_INDICE_COUNT
|
||||
);
|
||||
|
||||
quadBuffer(primitive, z,
|
||||
x0, y0, u0, v0,
|
||||
|
@ -4,7 +4,7 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <dawn/dawn.h>
|
||||
#include "../primitive.h"
|
||||
|
||||
#define QUAD_VERTICE_COUNT 4
|
||||
|
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Msters
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
@ -7,13 +7,9 @@
|
||||
|
||||
#include "render.h"
|
||||
|
||||
render_t * renderInit(char *name) {
|
||||
// Initialize the renderer
|
||||
render_t *render = malloc(sizeof(render_t));
|
||||
if(!render) return NULL;
|
||||
// render->width = WINDOW_WIDTH_DEFAULT;
|
||||
// render->height = WINDOW_HEIGHT_DEFAULT;
|
||||
render_t RENDER_STATE;
|
||||
|
||||
void renderInit() {
|
||||
// Enable GL things.
|
||||
glEnable(GL_BLEND);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
@ -23,22 +19,18 @@ render_t * renderInit(char *name) {
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glDepthMask(GL_TRUE);
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
|
||||
return render;
|
||||
}
|
||||
|
||||
void renderFrame(render_t *render) {
|
||||
void renderFrameStart() {
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
bool renderDispose(render_t *render) {
|
||||
// Free up the renderer
|
||||
free(render);
|
||||
return true;
|
||||
void renderDispose() {
|
||||
|
||||
}
|
||||
|
||||
void renderSetResolution(render_t *render, uint32_t width, uint32_t height) {
|
||||
render->width = width;
|
||||
render->height = height;
|
||||
void renderSetResolution(int32_t width, int32_t height) {
|
||||
RENDER_STATE.width = width;
|
||||
RENDER_STATE.height = height;
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
@ -1,58 +1,31 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Msters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
// Copyright (c) 2021 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <malloc.h>
|
||||
#include <glad/glad.h>
|
||||
#include <cglm/call.h>
|
||||
#include "primitive.h"
|
||||
|
||||
/**
|
||||
* Contains information about the current render state, can be used for querying
|
||||
* how the renderer is currently set up.
|
||||
*/
|
||||
typedef struct {
|
||||
/** Resolution (in pixels) */
|
||||
int32_t width, height;
|
||||
} render_t;
|
||||
#include <dawn/dawn.h>
|
||||
|
||||
/**
|
||||
* Initialize the renderer.
|
||||
*
|
||||
* @param name String of the windows' name.
|
||||
* @return Rendering Context information.
|
||||
*/
|
||||
render_t * renderInit(char *name);
|
||||
void renderInit();
|
||||
|
||||
/**
|
||||
* Render a single frame of the render loop. The renderer is not (currently)
|
||||
* responsible for render looping.
|
||||
*
|
||||
* @param render The renderer to loop for.
|
||||
*/
|
||||
void renderFrame(render_t *render);
|
||||
void renderFrameStart();
|
||||
|
||||
/**
|
||||
* Cleanup a render context.
|
||||
*
|
||||
* @param render Renderer to cleanup.
|
||||
* @return True or False if Successful/Not.
|
||||
*/
|
||||
bool renderDispose(render_t *render);
|
||||
void renderDispose();
|
||||
|
||||
/**
|
||||
* Set the internal display resolution.
|
||||
* Sets the internal display resolution.
|
||||
*
|
||||
* @param render Renderer to set resolution for.
|
||||
* @param width Width (in pixels) of the viewport.
|
||||
* @param height Height (in pixels) of the viewport.
|
||||
* @param width Width of the display (in pixels).
|
||||
* @param height Height of the display (in pixels).
|
||||
*/
|
||||
void renderSetResolution(render_t *render, uint32_t width, uint32_t height);
|
||||
void renderSetResolution(int32_t width, int32_t height);
|
@ -90,7 +90,7 @@ shader_t * shaderCompile(char *vertexShaderSource, char* fragmentShaderSource) {
|
||||
return shader;
|
||||
}
|
||||
|
||||
bool shaderDipose(shader_t *shader) {
|
||||
bool shaderDispose(shader_t *shader) {
|
||||
glDeleteProgram(shader->shaderProgram);
|
||||
glDeleteShader(shader->shaderVertex);
|
||||
glDeleteShader(shader->shaderFrag);
|
||||
|
@ -6,45 +6,7 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <malloc.h>
|
||||
#include "camera.h"
|
||||
#include "texture.h"
|
||||
|
||||
#define SHADER_UNI_VIEW "u_View"
|
||||
#define SHADER_UNI_PROJ "u_Proj"
|
||||
#define SHADER_UNI_TEXT "u_Text"
|
||||
#define SHADER_UNI_MODL "u_Modl"
|
||||
|
||||
/**
|
||||
* Structure containing information about an OpenGL Shader. For simplicity sake
|
||||
* we demand certain uninforms to be present on the shader target.
|
||||
*/
|
||||
typedef struct {
|
||||
/** Pointer to an uploaded vertex shader program */
|
||||
GLuint shaderVertex;
|
||||
|
||||
/** Pointer to an uploaded fragment shader program */
|
||||
GLuint shaderFrag;
|
||||
|
||||
/** Pointer to an uploaded shader program linked */
|
||||
GLuint shaderProgram;
|
||||
|
||||
/** Matrix for the view matrix */
|
||||
GLint uniView;
|
||||
|
||||
/** Matrix for the projection matrix */
|
||||
GLint uniProj;
|
||||
|
||||
/** Uniform for the current texture */
|
||||
GLint uniText;
|
||||
|
||||
/** Uniform for the current model world position */
|
||||
GLint uniModl;
|
||||
} shader_t;
|
||||
#include <dawn/dawn.h>
|
||||
|
||||
/**
|
||||
* Create a shader from vertex and fragment shader code.
|
||||
@ -61,7 +23,7 @@ shader_t * shaderCompile(char *vertexShaderSource, char* fragmentShaderSource);
|
||||
* @param shader The shader to unload
|
||||
* @return True if successfully disposed.
|
||||
*/
|
||||
bool shaderDipose(shader_t *shader);
|
||||
bool shaderDispose(shader_t *shader);
|
||||
|
||||
/**
|
||||
* Attaches the supplied shader as the current shader.
|
||||
|
@ -4,22 +4,11 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <dawn/dawn.h>
|
||||
#include "primitive.h"
|
||||
#include "primitives/quad.h"
|
||||
#include "../util/math.h"
|
||||
|
||||
typedef struct {
|
||||
/** Maximum sprites the batch can hold. */
|
||||
int32_t maxSprites;
|
||||
|
||||
/** The current/next sprite index. */
|
||||
int32_t currentSprite;
|
||||
|
||||
/** Internal primitive */
|
||||
primitive_t *primitive;
|
||||
} spritebatch_t;
|
||||
|
||||
/**
|
||||
* Creates a new Sprite Batch made of standard quads.
|
||||
*
|
||||
|
@ -4,26 +4,7 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <glad/glad.h>
|
||||
#include <malloc.h>
|
||||
#include <memory.h>
|
||||
|
||||
/**
|
||||
* Structure detailing information about a texture.
|
||||
* Because we plan to upload the pixels of a texture into the GPU, we don't
|
||||
* store the pixels in memory because we don't need to!
|
||||
*/
|
||||
typedef struct {
|
||||
int32_t width;
|
||||
int32_t height;
|
||||
GLuint id;
|
||||
} texture_t;
|
||||
|
||||
/** Information about a single pixel. */
|
||||
typedef struct {
|
||||
uint8_t r, g, b, a ;
|
||||
} pixel_t;
|
||||
#include <dawn/dawn.h>
|
||||
|
||||
/**
|
||||
* Creates a new texture that can be written in to.
|
||||
|
@ -4,26 +4,7 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <malloc.h>
|
||||
|
||||
/** Division of a texture */
|
||||
typedef struct {
|
||||
float x0, y0, x1, y1;
|
||||
} tilesetdiv_t;
|
||||
|
||||
/** Definition of a Tileset */
|
||||
typedef struct {
|
||||
/** Count of X/Y divisions */
|
||||
int32_t columns, rows;
|
||||
|
||||
/** Count of divisions (unused) */
|
||||
int32_t count;
|
||||
|
||||
/** Division information */
|
||||
tilesetdiv_t *divisions;
|
||||
} tileset_t;
|
||||
|
||||
#include <dawn/dawn.h>
|
||||
|
||||
/**
|
||||
* Create a tileset. Tilesets will be pre-divided to save performance later.
|
||||
|
Reference in New Issue
Block a user