polyadvent

A game engine from scratch in C
git clone git://jb55.com/polyadvent
Log | Files | Refs | README

commit fcb7afe358b12a506655246e9f244eb98bde088e
parent d6f32a8e53ed205fe23042b22d523d12abad4bda
Author: William Casarin <jb55@jb55.com>
Date:   Sat, 21 Apr 2018 15:21:13 -0700

initial terrain stuff

Diffstat:
MMakefile | 10+++-------
Msrc/main.c | 33+++++++++++++++++++--------------
Asrc/terrain.c | 40++++++++++++++++++++++++++++++++++++++++
Asrc/terrain.h | 18++++++++++++++++++
Msrc/update.c | 8+++++---
5 files changed, 85 insertions(+), 24 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,7 +1,7 @@ NAME ?= polyadvent BIN ?= $(NAME) PREFIX ?= /usr/local -CFLAGS = -ggdb -I src -Wall -Wextra -Werror -std=c99 \ +CFLAGS = -ggdb -I src -Wall -Wextra -std=c99 \ -Wno-unused-function \ -Wno-unused-parameter \ -Wno-unused-variable \ @@ -11,8 +11,6 @@ LDFLAGS = -lSDL2 -lGL DEFS= -DGLFW_INCLUDE_NONE SRC=src -SHLIB=$(SRC)/lib$(NAME).so - OBJS = $(SRC)/window.o OBJS += $(SRC)/buffer.o #OBJS += $(SRC)/camera.o @@ -24,6 +22,7 @@ OBJS += $(SRC)/mat4/mat4.o OBJS += $(SRC)/render.o OBJS += $(SRC)/shader.o OBJS += $(SRC)/update.o +OBJS += $(SRC)/terrain.o OBJS += $(SRC)/slab.o OBJS += $(SRC)/slab_geom.o OBJS += $(SRC)/geometry.o @@ -34,10 +33,7 @@ all: $(BIN) %.o: %.c %.h $(CC) $(CFLAGS) -fPIC $(DEFS) -c $< -o $@ -$(SHLIB): $(OBJS) - $(CC) $(CFLAGS) -shared $^ -o $@ - -$(BIN): $(SRC)/main.o $(SHLIB) +$(BIN): $(SRC)/main.o $(OBJS) $(CC) $(CFLAGS) $(DEFS) $^ $(LDFLAGS) -o $@ install: $(BIN) diff --git a/src/main.c b/src/main.c @@ -10,6 +10,7 @@ #include "geometry.h" #include "event.h" #include "render.h" +#include "terrain.h" #include <assert.h> @@ -18,6 +19,8 @@ int main(void) struct game_state game; struct slab slab; struct geometry slab_geom; + struct terrain terrain; + size_t length; void *slab_buffer; @@ -30,18 +33,20 @@ int main(void) init_gl(&game.test_resources); init_game(&game); - // load slab file - slab_buffer = file_contents(SLAB("test.slab"), &length); - // parse to a slab_t - slab_parse(&slab, slab_buffer); - slab_show(&slab); - slab_alloc_arrays(&slab, &slab_geom, NULL); - slab_arrays(&slab, - slab_geom.vertices, - slab_geom.normals, - slab_geom.indices, - &slab_geom.num_elements); - make_buffer_geometry(&slab_geom); + terrain_init(&terrain); + terrain_create(&terrain); + + /* slab_buffer = file_contents(SLAB("test.slab"), &length); */ + /* slab_parse(&slab, slab_buffer); */ + /* slab_show(&slab); */ + /* slab_alloc_arrays(&slab, &slab_geom, NULL); */ + /* slab_arrays(&slab, */ + /* slab_geom.vertices, */ + /* slab_geom.normals, */ + /* slab_geom.indices, */ + /* &slab_geom.num_elements); */ + + /* make_buffer_geometry(&slab_geom); */ // mesh it -> load into vbo /* Loop until the user closes the window */ @@ -54,8 +59,8 @@ int main(void) SDL_GL_SwapWindow(window); } - //free(slab_buffer); - //free_slab_geom(&geom, NULL) + /* free(slab_buffer); */ + /* free_slab_geom(&geom, NULL) */ //SDL_GL_DeleteContext(gl); //return 0; diff --git a/src/terrain.c b/src/terrain.c @@ -0,0 +1,40 @@ + +#include "terrain.h" + + +#include "util.h" + +// v6----- v5 +// /| /| +// v1------v0| +// | | | | +// | |v7---|-|v4 +// |/ |/ +// v2------v3 + +void +terrain_init(struct terrain *terrain) { + terrain->width = 1; + terrain->height = 1; +} + +void +terrain_create(struct terrain *terrain) { + const int num_verts = 4; + float *vs; + float *ns; + + terrain->geom.num_verts = num_verts; + vs = terrain->geom.vertices = calloc(num_verts * 3, sizeof(*terrain->geom.vertices)); + ns = terrain->geom.normals = calloc(num_verts * 3, sizeof(*terrain->geom.normals)); + + for (int i = 0; i < num_verts; ++i) { + } +} + +void +terrain_detroy(struct terrain *terrain) { + free(terrain->geom.vertices); + free(terrain->geom.normals); +} + diff --git a/src/terrain.h b/src/terrain.h @@ -0,0 +1,18 @@ + + +#ifndef POLYADVENT_TERRAIN_H +#define POLYADVENT_TERRAIN_H + +#include "geometry.h" + +struct terrain { + struct geometry geom; + float width, height; +}; + +void terrain_init(struct terrain *terrain); +void terrain_create(struct terrain *terrain); +void terrain_destroy(struct terrain *terrain); + + +#endif /* POLYADVENT_TERRAIN_H */ diff --git a/src/update.c b/src/update.c @@ -4,11 +4,13 @@ void update (struct game_state * game) { unsigned int ms = SDL_GetTicks(); - struct resources *res; + /* struct resources *res; */ - res = &game->test_resources; + /* res = &game->test_resources; */ // Update fade effect in shader - res->fade_factor = sinf((float)ms * 0.001f) * 0.5f + 0.5f; + //res->fade_factor = sinf((float)ms * 0.001f) * 0.5f + 0.5f; + + /* game->test_resources */ }