Tidying some stuff up

This commit is contained in:
2021-04-04 22:33:18 +10:00
parent 9467d04433
commit b8b1f7a870
13 changed files with 82 additions and 36 deletions

View File

@ -8,6 +8,6 @@ out vec4 FragColor;
void main() { void main() {
vec4 color = texture(u_Text, TexCoord); vec4 color = texture(u_Text, TexCoord);
FragColor = color; // FragColor = color;
// FragColor = vec4(1, 1, 1, 1); FragColor = vec4(1, 1, 1, 1);
} }

View File

@ -8,7 +8,7 @@
#include "cube.h" #include "cube.h"
primitive_t * cubeCreate(float w, float h, float d) { primitive_t * cubeCreate(float w, float h, float d) {
primitive_t *cube = primitiveCreate(8, 36); primitive_t *cube = primitiveCreate(CUBE_VERTICE_COUNT, CUBE_INDICE_COUNT);
vertice_t *vertices = malloc(sizeof(vertice_t) * cube->verticeCount); vertice_t *vertices = malloc(sizeof(vertice_t) * cube->verticeCount);
indice_t *indices = malloc(sizeof(indice_t) * cube->indiceCount); indice_t *indices = malloc(sizeof(indice_t) * cube->indiceCount);

View File

@ -8,4 +8,14 @@
#include <malloc.h> #include <malloc.h>
#include "../primitive.h" #include "../primitive.h"
#define CUBE_VERTICE_COUNT 8
#define CUBE_INDICE_COUNT 36
/**
* Creates a cube primitive of given size.
* @param w Width of cube.
* @param h Height of cube.
* @param d Depth of cube.
* @return Primitive of the cube.
*/
primitive_t * cubeCreate(float w, float h, float d); primitive_t * cubeCreate(float w, float h, float d);

View File

@ -12,8 +12,8 @@ void quadBuffer(primitive_t *primitive,
float x1, float y1, float u1, float v1, float x1, float y1, float u1, float v1,
int32_t verticeStart, int32_t indiceStart int32_t verticeStart, int32_t indiceStart
) { ) {
vertice_t *vertices = malloc(sizeof(vertice_t) * 4); vertice_t *vertices = malloc(sizeof(vertice_t) * QUAD_VERTICE_COUNT);
indice_t *indices = malloc(sizeof(indice_t) * 6); indice_t *indices = malloc(sizeof(indice_t) * QUAD_INDICE_COUNT);
vertices[0].x = x0, vertices[0].y = y0, vertices[0].z = 0; vertices[0].x = x0, vertices[0].y = y0, vertices[0].z = 0;
vertices[0].u = u0, vertices[0].v = v0; vertices[0].u = u0, vertices[0].v = v0;
@ -35,8 +35,8 @@ void quadBuffer(primitive_t *primitive,
indices[4] = (indice_t)(verticeStart + 2); indices[4] = (indice_t)(verticeStart + 2);
indices[5] = (indice_t)(verticeStart + 3); indices[5] = (indice_t)(verticeStart + 3);
primitiveBufferVertices(primitive, verticeStart, 4, vertices); primitiveBufferVertices(primitive,verticeStart,QUAD_VERTICE_COUNT,vertices);
primitiveBufferIndices(primitive, indiceStart, 6, indices); primitiveBufferIndices( primitive,indiceStart, QUAD_INDICE_COUNT, indices );
free(vertices); free(vertices);
free(indices); free(indices);

View File

@ -7,6 +7,9 @@
#include <stdint.h> #include <stdint.h>
#include "../primitive.h" #include "../primitive.h"
#define QUAD_VERTICE_COUNT 4
#define QUAD_INDICE_COUNT 6
void quadBuffer(primitive_t *primitive, void quadBuffer(primitive_t *primitive,
float x0, float y0, float u0, float v0, float x0, float y0, float u0, float v0,
float x1, float y1, float u1, float v1, float x1, float y1, float u1, float v1,

View File

@ -9,10 +9,7 @@
camera_t *camera; camera_t *camera;
shader_t *shader; shader_t *shader;
primitive_t *cube; world_t *world;
texture_t *texture;
float bruh;
engine_t * engineInit(platform_t *platform, char *name, uint32_t inputCount) { engine_t * engineInit(platform_t *platform, char *name, uint32_t inputCount) {
// Create the engine instance. // Create the engine instance.
@ -40,18 +37,13 @@ engine_t * engineInit(platform_t *platform, char *name, uint32_t inputCount) {
shader = assetShaderLoad("shaders/test.vert", "shaders/test.frag"); shader = assetShaderLoad("shaders/test.vert", "shaders/test.frag");
camera = cameraCreate(); camera = cameraCreate();
cameraLookAt(camera, cameraLookAt(camera,
3, 3, 3, 30, 30, 30,
0, 0, 0 0, 0, 0
); );
cameraPerspective(camera, 45.0f, 1920.0f/1080.0f, 0.5f, 100.0f); cameraPerspective(camera, 45.0f, 1920.0f/1080.0f, 0.5f, 100.0f);
shaderUseCamera(shader, camera); shaderUseCamera(shader, camera);
texture = assetTextureLoad("bruh.png"); world = worldCreate();
shaderUseTexture(shader, texture);
// cube = quadCreate(0, 0, 0, 0, 1, 1, 1, 1);
cube = cubeCreate(1, 1, 1);
bruh = 0;
return engine; return engine;
} }
@ -60,9 +52,7 @@ uint32_t engineUpdate(engine_t *engine) {
shaderUse(shader); shaderUse(shader);
renderFrame(engine->render); renderFrame(engine->render);
shaderUsePosition(shader, 0, 0, 0, bruh, bruh / 2.0f, bruh / 3.0f); worldRender(world, shader);
bruh += 0.0001f;
primitiveDraw(cube, 0, cube->indiceCount);
inputUpdate(engine->input); inputUpdate(engine->input);
return 0; return 0;

View File

@ -13,9 +13,7 @@
#include "display/shader.h" #include "display/shader.h"
#include "display/camera.h" #include "display/camera.h"
#include "world/world.h" #include "world/world.h"
#include "world/chunklist.h"
#include "display/primitives/cube.h"
#include "display/primitives/quad.h"
/** Information about the current engine context. */ /** Information about the current engine context. */

View File

@ -14,18 +14,30 @@ void chunkCreate(chunk_t *chunk) {
chunk->primitive = primitiveCreate(count * 4, count * 6); chunk->primitive = primitiveCreate(count * 4, count * 6);
i = 0; i = 0;
for(y = 0; y < CHUNK_HEIGHT; y++) { for(z = 0; z < CHUNK_DEPTH; z++) {
for(x = 0; x < CHUNK_WIDTH; x++) { for(y = 0; y < CHUNK_HEIGHT; y++) {
quadBuffer(chunk->primitive, for(x = 0; x < CHUNK_WIDTH; x++) {
x, y, 0, 0, quadBuffer(chunk->primitive,
x+1, y+1, 1, 1, x, y, 0, 0,
i*4, i*6 x+1, y+1, 1, 1,
); i*4, i*6
i++; );
i++;
}
} }
} }
} }
void chunkRender(chunk_t *chunk, shader_t *shader) {
float x, y, z;
x = (chunk->x * CHUNK_WIDTH);
y = (chunk->y * CHUNK_HEIGHT);
z = (chunk->z * CHUNK_DEPTH);
shaderUsePosition(shader, x*2, y*2, z*2, 0, 0, 0);
primitiveDraw(chunk->primitive, 0, chunk->primitive->indiceCount);
}
void chunkLoad(chunk_t *chunk, int32_t x, int32_t y, int32_t z) { void chunkLoad(chunk_t *chunk, int32_t x, int32_t y, int32_t z) {
} }

View File

@ -6,9 +6,10 @@
#pragma once #pragma once
#include <stdint.h> #include <stdint.h>
#include "../display/primitive.h" #include "../display/primitive.h"
#include "../display/shader.h"
#include "../display/primitives/quad.h" #include "../display/primitives/quad.h"
#define CHUNK_WIDTH 32 #define CHUNK_WIDTH 3
#define CHUNK_HEIGHT CHUNK_WIDTH #define CHUNK_HEIGHT CHUNK_WIDTH
#define CHUNK_DEPTH CHUNK_HEIGHT #define CHUNK_DEPTH CHUNK_HEIGHT
@ -28,6 +29,8 @@ typedef struct {
*/ */
void chunkCreate(chunk_t *chunk); void chunkCreate(chunk_t *chunk);
void chunkRender(chunk_t *chunk, shader_t *shader);
/** /**
* Loads a given chunk into the memory specified. * Loads a given chunk into the memory specified.
* *

View File

@ -35,9 +35,9 @@ chunklist_t * chunkListCreate(int32_t width, int32_t height, int32_t depth) {
// Load initial chunks, ZYX order is important. // Load initial chunks, ZYX order is important.
i = 0; i = 0;
for(z = 0; z < width; z++) { for(z = 0; z < depth; z++) {
for(y = 0; y < height; y++) { for(y = 0; y < height; y++) {
for(x = 0; x < depth; x++) { for(x = 0; x < width; x++) {
chunk = list->chunks + i; chunk = list->chunks + i;
list->chunkList[i] = chunk; list->chunkList[i] = chunk;
@ -131,4 +131,14 @@ void chunkListShift(chunklist_t *list, int32_t x, int32_t y, int32_t z) {
// Now copy that array over. // Now copy that array over.
memcpy(list->chunkList, chunkList, sizeof(chunk_t *) * list->count); memcpy(list->chunkList, chunkList, sizeof(chunk_t *) * list->count);
free(chunkList); free(chunkList);
}
void chunkListAlign(chunklist_t *list, int32_t x, int32_t y, int32_t z) {
int32_t lx, ly, lz;
lx = x - list->x;
ly = y - list->y;
lz = z - list->z;
chunkListShift(list, lx, ly, lz);
} }

View File

@ -53,4 +53,14 @@ void chunkListDispose(chunklist_t *list);
* @param y Y movement to shift chunk along. * @param y Y movement to shift chunk along.
* @param z Z movement to shift chunk along. * @param z Z movement to shift chunk along.
*/ */
void chunkListShift(chunklist_t *list, int32_t x, int32_t y, int32_t z); void chunkListShift(chunklist_t *list, int32_t x, int32_t y, int32_t z);
/**
* Align the chunk list (in absolute space).
*
* @param list List to align.
* @param x X movement to shift chunk along.
* @param y Y movement to shift chunk along.
* @param z Z movement to shift chunk along.
*/
void chunkListAlign(chunklist_t *list, int32_t x, int32_t y, int32_t z);

View File

@ -20,6 +20,13 @@ world_t * worldCreate() {
return world; return world;
} }
void worldRender(world_t *world, shader_t *shader) {
int32_t i;
for(i = 0; i < world->chunkList->count; i++) {
chunkRender(world->chunkList->chunks + i, shader);
}
}
void worldDispose(world_t *world) { void worldDispose(world_t *world) {
free(world); free(world);
} }

View File

@ -5,6 +5,7 @@
#pragma once #pragma once
#include "chunklist.h" #include "chunklist.h"
#include "../display/shader.h"
typedef struct { typedef struct {
chunklist_t *chunkList; chunklist_t *chunkList;
@ -12,4 +13,6 @@ typedef struct {
world_t * worldCreate(); world_t * worldCreate();
void worldRender(world_t *world, shader_t *shader);
void worldDispose(world_t *world); void worldDispose(world_t *world);