polyadvent

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

commit e5e6566c9fd688d5b051186c0cc5c68038812f1b
parent 52d077def7ed21ef79da3d32976ea8d90011068a
Author: William Casarin <jb55@jb55.com>
Date:   Thu,  8 Nov 2018 14:13:50 -0800

initial skybox stuff

Diffstat:
MMakefile | 7++++---
Adata/textures/cubemaps/ame_shadow/ame_shadow.shader | 9+++++++++
Adata/textures/cubemaps/ame_shadow/readme | 5+++++
Adata/textures/cubemaps/ame_shadow/shadowpeak_bk.tga | 0
Adata/textures/cubemaps/ame_shadow/shadowpeak_dn.tga | 0
Adata/textures/cubemaps/ame_shadow/shadowpeak_ft.tga | 0
Adata/textures/cubemaps/ame_shadow/shadowpeak_lf.tga | 0
Adata/textures/cubemaps/ame_shadow/shadowpeak_rt.tga | 0
Adata/textures/cubemaps/ame_shadow/shadowpeak_up.tga | 0
Adata/textures/cubemaps/ame_siege/ame_siege.shader | 9+++++++++
Adata/textures/cubemaps/ame_siege/readme | 5+++++
Adata/textures/cubemaps/ame_siege/siege_bk.tga | 0
Adata/textures/cubemaps/ame_siege/siege_dn.tga | 0
Adata/textures/cubemaps/ame_siege/siege_ft.tga | 0
Adata/textures/cubemaps/ame_siege/siege_lf.tga | 0
Adata/textures/cubemaps/ame_siege/siege_rt.tga | 0
Adata/textures/cubemaps/ame_siege/siege_up.tga | 0
Adata/textures/cubemaps/mp_sorbin/license.txt | 7+++++++
Adata/textures/cubemaps/mp_sorbin/mp_sorbin.shader | 14++++++++++++++
Adata/textures/cubemaps/mp_sorbin/readme.txt | 94+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Adata/textures/cubemaps/mp_sorbin/sorbin_bk.tga | 0
Adata/textures/cubemaps/mp_sorbin/sorbin_dn.tga | 0
Adata/textures/cubemaps/mp_sorbin/sorbin_ft.tga | 0
Adata/textures/cubemaps/mp_sorbin/sorbin_lf.tga | 0
Adata/textures/cubemaps/mp_sorbin/sorbin_rt.tga | 0
Adata/textures/cubemaps/mp_sorbin/sorbin_up.tga | 0
Aetc/shaders/skybox.f.glsl | 12++++++++++++
Aetc/shaders/skybox.v.glsl | 11+++++++++++
Msrc/game.c | 11++---------
Msrc/game.h | 10++++++----
Msrc/geometry.c | 55+++++++++++++++++++++++++++++++++++--------------------
Msrc/gl.h | 2++
Msrc/model.c | 1+
Msrc/model.h | 1+
Msrc/render.c | 4+++-
Msrc/shader.c | 1+
Msrc/shader.h | 2+-
Asrc/skybox.c | 104+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/skybox.h | 21+++++++++++++++++++++
39 files changed, 347 insertions(+), 38 deletions(-)

diff --git a/Makefile b/Makefile @@ -22,6 +22,7 @@ OBJS += $(SRC)/fbo.o OBJS += $(SRC)/file.o OBJS += $(SRC)/game.o OBJS += $(SRC)/geometry.o +OBJS += $(SRC)/hires.o OBJS += $(SRC)/input.o OBJS += $(SRC)/main.o OBJS += $(SRC)/mat4.o @@ -35,15 +36,15 @@ OBJS += $(SRC)/poisson.o OBJS += $(SRC)/quat.o OBJS += $(SRC)/render.o OBJS += $(SRC)/shader.o +OBJS += $(SRC)/skybox.o +OBJS += $(SRC)/stb_image.o OBJS += $(SRC)/terrain.o +OBJS += $(SRC)/texture.o OBJS += $(SRC)/ui.o OBJS += $(SRC)/uniform.o OBJS += $(SRC)/update.o OBJS += $(SRC)/util.o OBJS += $(SRC)/vec3.o -OBJS += $(SRC)/hires.o -OBJS += $(SRC)/stb_image.o -OBJS += $(SRC)/texture.o SRCS=$(OBJS:.o=.c) diff --git a/data/textures/cubemaps/ame_shadow/ame_shadow.shader b/data/textures/cubemaps/ame_shadow/ame_shadow.shader @@ -0,0 +1,9 @@ +textures/skies/ame_shadow +{ + qer_editorimage env/ame_shadow/shadowpeak_ft.tga + surfaceparm noimpact + surfaceparm nolightmap + q3map_sun 1.00 1.00 1.00 100 270 35 + q3map_surfacelight 80 + skyparms env/ame_shadow/shadowpeak - - +} diff --git a/data/textures/cubemaps/ame_shadow/readme b/data/textures/cubemaps/ame_shadow/readme @@ -0,0 +1,5 @@ +Created by 'amethyst7' aka Chris Matz. +WEB site: http://amethyst7.gotdoofed.com + +You may use and distribute this sky box under the terms of the +GNU General Public License version 2. diff --git a/data/textures/cubemaps/ame_shadow/shadowpeak_bk.tga b/data/textures/cubemaps/ame_shadow/shadowpeak_bk.tga Binary files differ. diff --git a/data/textures/cubemaps/ame_shadow/shadowpeak_dn.tga b/data/textures/cubemaps/ame_shadow/shadowpeak_dn.tga Binary files differ. diff --git a/data/textures/cubemaps/ame_shadow/shadowpeak_ft.tga b/data/textures/cubemaps/ame_shadow/shadowpeak_ft.tga Binary files differ. diff --git a/data/textures/cubemaps/ame_shadow/shadowpeak_lf.tga b/data/textures/cubemaps/ame_shadow/shadowpeak_lf.tga Binary files differ. diff --git a/data/textures/cubemaps/ame_shadow/shadowpeak_rt.tga b/data/textures/cubemaps/ame_shadow/shadowpeak_rt.tga Binary files differ. diff --git a/data/textures/cubemaps/ame_shadow/shadowpeak_up.tga b/data/textures/cubemaps/ame_shadow/shadowpeak_up.tga Binary files differ. diff --git a/data/textures/cubemaps/ame_siege/ame_siege.shader b/data/textures/cubemaps/ame_siege/ame_siege.shader @@ -0,0 +1,9 @@ +textures/skies/ame_siege +{ + qer_editorimage env/ame_siege/siege_ft.tga + surfaceparm noimpact + surfaceparm nolightmap + q3map_sun 1.00 1.00 0.965 75 320 30 + q3map_surfacelight 50 + skyparms env/ame_siege/siege - - +} diff --git a/data/textures/cubemaps/ame_siege/readme b/data/textures/cubemaps/ame_siege/readme @@ -0,0 +1,5 @@ +Created by 'amethyst7' aka Chris Matz. +WEB site: http://amethyst7.gotdoofed.com + +You may use and distribute this sky box under the terms of the +GNU General Public License version 2. diff --git a/data/textures/cubemaps/ame_siege/siege_bk.tga b/data/textures/cubemaps/ame_siege/siege_bk.tga Binary files differ. diff --git a/data/textures/cubemaps/ame_siege/siege_dn.tga b/data/textures/cubemaps/ame_siege/siege_dn.tga Binary files differ. diff --git a/data/textures/cubemaps/ame_siege/siege_ft.tga b/data/textures/cubemaps/ame_siege/siege_ft.tga Binary files differ. diff --git a/data/textures/cubemaps/ame_siege/siege_lf.tga b/data/textures/cubemaps/ame_siege/siege_lf.tga Binary files differ. diff --git a/data/textures/cubemaps/ame_siege/siege_rt.tga b/data/textures/cubemaps/ame_siege/siege_rt.tga Binary files differ. diff --git a/data/textures/cubemaps/ame_siege/siege_up.tga b/data/textures/cubemaps/ame_siege/siege_up.tga Binary files differ. diff --git a/data/textures/cubemaps/mp_sorbin/license.txt b/data/textures/cubemaps/mp_sorbin/license.txt @@ -0,0 +1,7 @@ +This skybox has been created by 'The Mighty Pete'. He can be reached +at the following WEB site: + +http://www.petesoasis.com + +The author grants you the right to freely use this sky box in your projects +and distribute it under the GNU General Public License version 2. diff --git a/data/textures/cubemaps/mp_sorbin/mp_sorbin.shader b/data/textures/cubemaps/mp_sorbin/mp_sorbin.shader @@ -0,0 +1,14 @@ +// Direction & elevation checked and adjusted - Speaker + +textures/skies/mp_sorbin +{ + qer_editorimage env/mp_sorbin/sorbin_ft.tga + surfaceparm noimpact + surfaceparm nolightmap + q3map_globaltexture + q3map_lightsubdivide 256 + surfaceparm sky + q3map_surfacelight 200 + q3map_sun 1 0.9 0.8 200 40 75 + skyparms env/mp_sorbin/sorbin - - +} diff --git a/data/textures/cubemaps/mp_sorbin/readme.txt b/data/textures/cubemaps/mp_sorbin/readme.txt @@ -0,0 +1,94 @@ + + _______ _______ _______ ______ _________ _ + ( ____ \( ___ )( ____ )( ___ \ \__ __/( ( /| + | ( \/| ( ) || ( )|| ( ) ) ) ( | \ ( | + | (_____ | | | || (____)|| (__/ / | | | \ | | + (_____ )| | | || __)| __ ( | | | (\ \) | + ) || | | || (\ ( | ( \ \ | | | | \ | + /\____) || (___) || ) \ \__| )___) )___) (___| ) \ | + \_______)(_______)|/ \__/|/ \___/ \_______/|/ )_) + + + + + + + + From the Mind of the Mighty Pete ! + + + Enjoy ! + + + http://www.geocities.com/petes-oasis/ + + + http://www.planethalflife.com/wadfather/ + + + + + + $, $, , + "ss.$ss. .s' + , .ss$$$$$$$$$$s, + $. s$$$$$$$$$$$$$$`$$Ss + "$$$$$$$$$$$$$$$$$$o$$$ , + s$$$$$$$$$$$$$$$$$$$$$$$$s, ,s + s$$$$$$$$$"$$$$$$""""$$$$$$"$$$$$, + s$$$$$$$$$$s""$$$$ssssss"$$$$$$$$" + s$$$$$$$$$$' `"""ss"$"$s"" + s$$$$$$$$$$, `"""""$ .s$$s + s$$$$$$$$$$$$s,... `s$$' ` + `ssss$$$$$$$$$$$$$$$$$$$$####s. .$$"$. , s- + `""""$$$$$$$$$$$$$$$$$$$$#####$$$$$$" $.$' + "$$$$$$$$$$$$$$$$$$$$$####s"" .$$$| + "$$$$$$$$$$$$$$$$$$$$$$$$##s .$$" $ + $$""$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" ` + $$" "$"$$$$$$$$$$$$$$$$$$$$S""""' + , ," ' $$$$$$$$$$$$$$$$####s + $. .s$$$$$$$$$$$$$$$$$####" + , "$s. ..ssS$$$$$$$$$$$$$$$$$$$####" + $ .$$$S$$$$$$$$$$$$$$$$$$$$$$$$#####" + Ss ..sS$$$$$$$$$$$$$$$$$$$$$$$$$$$######"" + "$$sS$$$$$$$$$$$$$$$$$$$$$$$$$$$########" + , s$$$$$$$$$$$$$$$$$$$$$$$$#########""' + $ s$$$$$$$$$$$$$$$$$$$$$#######""' s' , + $$..$$$$$$$$$$$$$$$$$$######"' ....,$$.... ,$ + "$$$$$$$$$$$$$$$######"' , .sS$$$$$$$$$$$$$$$$s$$ + $$$$$$$$$$$$#####" $, .s$$$$$$$$$$$$$$$$$$$$$$$$s. + ) $$$$$$$$$$$#####' `$$$$$$$$$###########$$$$$$$$$$$. + (( $$$$$$$$$$$##### $$$$$$$$###" "####$$$$$$$$$$ + ) \ $$$$$$$$$$$$####. $$$$$$###" "###$$$$$$$$$ s' + ( ) $$$$$$$$$$$$$####. $$$$$###" The Mighty ####$$$$$$$$s$$' + ) ( ( $$"$$$$$$$$$$$#####.$$$$$###' Pete .###$$$$$$$$$$" + ( ) ) _,$" $$$$$$$$$$$$######.$$##' .###$$$$$$$$$$ + ) ( ( \. "$$$$$$$$$$$$$#######,,,. ..####$$$$$$$$$$$" + ( )$ ) ) ,$$$$$$$$$$$$$$$$$$####################$$$$$$$$$$$" + ( ($$ ( \ _sS" `"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$S$$, + ) )$$$s ) ) . . `$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"' `$$ + ( $$$Ss/ .$, .$,,s$$$$$$##S$$$$$$$$$$$$$$$$$$$$$$$$S"" ' + \)_$$$$$$$$$$$$$$$$$$$$$$$##" $$ `$$. `$$. + `"S$$$$$$$$$$$$$$$$$#" $ `$ `$ + `"""""""""""""' ' ' ' + + + + + + +No bones about it, based on a parameter file by who knows? +Thanks, Too bad cause it's nice stuff. + +Name length warning: + +It's possible that the file names are too long for some older games. +If that's the case just shorten them leaving everything after the _ and they should work just fine. +Remember you only need the *.tga and *.bmp for some games and the *.tga and *.pcx for other games. +If you don't need them you don't have to include them with your map. +Don't distribute my zips, If you want the originals go back to the Wadfather and download a fresh set. + + + + + diff --git a/data/textures/cubemaps/mp_sorbin/sorbin_bk.tga b/data/textures/cubemaps/mp_sorbin/sorbin_bk.tga Binary files differ. diff --git a/data/textures/cubemaps/mp_sorbin/sorbin_dn.tga b/data/textures/cubemaps/mp_sorbin/sorbin_dn.tga Binary files differ. diff --git a/data/textures/cubemaps/mp_sorbin/sorbin_ft.tga b/data/textures/cubemaps/mp_sorbin/sorbin_ft.tga Binary files differ. diff --git a/data/textures/cubemaps/mp_sorbin/sorbin_lf.tga b/data/textures/cubemaps/mp_sorbin/sorbin_lf.tga Binary files differ. diff --git a/data/textures/cubemaps/mp_sorbin/sorbin_rt.tga b/data/textures/cubemaps/mp_sorbin/sorbin_rt.tga Binary files differ. diff --git a/data/textures/cubemaps/mp_sorbin/sorbin_up.tga b/data/textures/cubemaps/mp_sorbin/sorbin_up.tga Binary files differ. diff --git a/etc/shaders/skybox.f.glsl b/etc/shaders/skybox.f.glsl @@ -0,0 +1,12 @@ +#include profile + +out vec4 frag_color; + +in vec3 tex_coords; + +uniform samplerCube skybox; + +void main() +{ + frag_color = texture(skybox, tex_coords); +} diff --git a/etc/shaders/skybox.v.glsl b/etc/shaders/skybox.v.glsl @@ -0,0 +1,11 @@ +#include profile + +in vec3 position; +out vec3 tex_coords; + +uniform mat4 mvp; + +void main() { + tex_coords = position; + gl_Position = mvp * vec4(position, 1.0); +} diff --git a/src/game.c b/src/game.c @@ -10,6 +10,7 @@ #include "entity.h" #include "texture.h" #include "stb_image.h" +#include "skybox.h" #include <assert.h> mat4 *cam_init = (float[16]){ @@ -74,6 +75,7 @@ void game_init(struct game *game, int width, int height) { check_gl(); init_terrain(terrain, size); + create_skybox(&res->skybox); mat4_id(mvp); @@ -135,14 +137,5 @@ void game_init(struct game *game, int width, int height) { // FBO STUFF END // TEXTURES - const char *faces[6] = { - CUBEMAP("test/right.jpg"), - CUBEMAP("test/left.jpg"), - CUBEMAP("test/top.jpg"), - CUBEMAP("test/bottom.jpg"), - CUBEMAP("test/front.jpg"), - CUBEMAP("test/back.jpg"), - }; - res->test_cubemap = create_cubemap(faces); // END TEXTURES } diff --git a/src/game.h b/src/game.h @@ -3,16 +3,17 @@ #define PA_GAME_H #include "buffer.h" +#include "entity.h" +#include "fbo.h" #include "input.h" #include "model.h" #include "node.h" +#include "orbit.h" #include "shader.h" -#include "entity.h" +#include "skybox.h" #include "terrain.h" -#include "ui.h" -#include "fbo.h" -#include "orbit.h" #include "texture.h" +#include "ui.h" #define PLAYER_HEIGHT 1.73 @@ -65,6 +66,7 @@ struct resources { float time; bool fog_on, diffuse_on; + struct skybox skybox; float sun_color[3]; float test_mvp[MAT4_ELEMS]; float light_dir[3]; diff --git a/src/geometry.c b/src/geometry.c @@ -43,32 +43,46 @@ void bind_geometry(struct geometry *geom, struct attributes *attrs) { check_gl(); } -void render_geometry(struct geometry *geom, struct attributes *attrs, - struct gpu_program *program) -{ +static void check_for_patches(struct gpu_program *program, int *type) { int has_tess_shader = get_program_shader(program, GL_TESS_EVALUATION_SHADER) != NULL; - int type = GL_TRIANGLES; if (has_tess_shader) { glPatchParameteri(GL_PATCH_VERTICES, 3); - type = GL_PATCHES; + *type = GL_PATCHES; } +} + + +void render_geometry(struct geometry *geom, struct attributes *attrs, + struct gpu_program *program) +{ + int type = GL_TRIANGLES; + //check_for_patches(program, &type); bind_geometry(geom, attrs); - glDrawElements(type, - geom->num_indices, /* count */ - GL_UNSIGNED_INT, /* type */ - (void*)0 /* element array buffer offset */ - ); - check_gl(); + if (geom->indices) { + glDrawElements(type, + geom->num_indices, /* count */ + GL_UNSIGNED_INT, /* type */ + (void*)0 /* element array buffer offset */ + ); + check_gl(); + } + else { + glDrawArrays(type, 0, geom->num_verts); + check_gl(); + } } void init_geometry(struct geometry *geom) { geom->colors = NULL; - geom->vbos.color.handle = 0; geom->normals = NULL; + geom->indices = NULL; + geom->vertices = NULL; geom->tex_coords = NULL; + + geom->vbos.color.handle = 0; geom->vbos.normal.handle = 0; geom->vbos.tex_coord.handle = 0; } @@ -79,8 +93,8 @@ make_buffer_geometry(struct geometry *geom) { assert(geom->vertices); /* assert(geom->normals); */ - assert(geom->indices); - assert(geom->num_indices >= 1); + /* assert(geom->indices); */ + /* assert(geom->num_indices >= 1); */ /* printf("making vertex buffer\n"); */ make_vertex_buffer( @@ -125,12 +139,13 @@ make_buffer_geometry(struct geometry *geom) { /* printf("making index buffer\n"); */ // cube indices - make_index_buffer( - GL_ELEMENT_ARRAY_BUFFER, - geom->indices, - geom->num_indices * (int)sizeof(*geom->indices), - &geom->vbos.index - ); + if (geom->indices) + make_index_buffer( + GL_ELEMENT_ARRAY_BUFFER, + geom->indices, + geom->num_indices * (int)sizeof(*geom->indices), + &geom->vbos.index + ); } diff --git a/src/gl.h b/src/gl.h @@ -100,4 +100,6 @@ void glFramebufferTexture( GLenum target, void glPatchParameteri( GLenum pname, GLint value); +void glBindVertexArray( GLuint array); + #endif /* POLYADVENT_GL_H */ diff --git a/src/model.c b/src/model.c @@ -4,6 +4,7 @@ void init_model(struct model *model) { model->shading = SHADING_VERT_COLOR; + model->texture = 0; init_geometry(&model->geom); } diff --git a/src/model.h b/src/model.h @@ -17,6 +17,7 @@ enum shading { struct model { struct geometry geom; enum shading shading; + u32 texture; }; diff --git a/src/render.c b/src/render.c @@ -12,6 +12,7 @@ #include "geometry.h" #include "debug.h" #include "render.h" +#include "skybox.h" #include "util.h" @@ -231,7 +232,6 @@ static void gamma_correct(float *c, float *d) { } void render (struct game *game, struct render_config *config) { - float adjust = game->test_resources.light_intensity; float gtmp[3]; struct resources *res = &game->test_resources; @@ -284,6 +284,8 @@ void render (struct game *game, struct render_config *config) { glCullFace(GL_BACK); } + render_skybox(&res->skybox, view_proj); + for (u32 i = 0; i < num_entities; ++i) { struct entity *entity = &entities[i]; if (config->is_depth_pass && !entity->casts_shadows) diff --git a/src/shader.c b/src/shader.c @@ -253,3 +253,4 @@ make_program_from_shaders(struct shader **shaders, int n_shaders, struct gpu_pro return 1; } + diff --git a/src/shader.h b/src/shader.h @@ -9,6 +9,7 @@ #define MAX_SHADER_INCLUDES 16 #define MAX_INCLUDE_FNAME_LEN 64 #define MAX_SHADERS 5 +#define MAX_UNIFORMS 16 struct shader { GLenum type; @@ -29,7 +30,6 @@ struct gpu_program { #define NO_GEOM_SHADER NULL int reload_program(struct gpu_program *program); - int make_shader(GLenum type, const char *filename, struct shader *shader); int make_program_from_shaders(struct shader **shaders, diff --git a/src/skybox.c b/src/skybox.c @@ -0,0 +1,104 @@ + +#include "skybox.h" +#include "util.h" +#include "texture.h" + +static float skybox_vertices[] = { + // positions + -1.0f, 1.0f, -1.0f, + -1.0f, -1.0f, -1.0f, + 0.0f, -1.0f, -1.0f, + 0.0f, -1.0f, -1.0f, + 0.0f, 1.0f, -1.0f, + 1.0f, 1.0f, -1.0f, + + 1.0f, -1.0f, 1.0f, + 1.0f, -1.0f, -1.0f, + 1.0f, 1.0f, -1.0f, + 1.0f, 1.0f, -1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, -1.0f, 1.0f, + + 0.0f, -1.0f, -1.0f, + 0.0f, -1.0f, 1.0f, + 0.0f, 1.0f, 1.0f, + 0.0f, 1.0f, 1.0f, + 0.0f, 1.0f, -1.0f, + 0.0f, -1.0f, -1.0f, + + 1.0f, -1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 0.0f, 1.0f, 1.0f, + 0.0f, 1.0f, 1.0f, + 0.0f, -1.0f, 1.0f, + 1.0f, -1.0f, 1.0f, + + 1.0f, 1.0f, -1.0f, + 0.0f, 1.0f, -1.0f, + 0.0f, 1.0f, 1.0f, + 0.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, -1.0f, + + 1.0f, -1.0f, -1.0f, + 1.0f, -1.0f, 1.0f, + 0.0f, -1.0f, -1.0f, + 0.0f, -1.0f, -1.0f, + 1.0f, -1.0f, 1.0f, + 0.0f, -1.0f, 1.0f +}; + +void create_skybox(struct skybox *skybox) { + struct shader vertex, frag; + struct shader *shaders[] = {&vertex, &frag}; + + init_model(&skybox->model); + skybox->model.geom.vertices = skybox_vertices; + skybox->model.geom.num_verts = ARRAY_SIZE(skybox_vertices); + make_buffer_geometry(&skybox->model.geom); + + static const char *faces[6] = { + CUBEMAP("ame_siege/siege_rt.tga"), + CUBEMAP("ame_siege/siege_lf.tga"), + CUBEMAP("ame_siege/siege_up.tga"), + CUBEMAP("ame_siege/siege_dn.tga"), + CUBEMAP("ame_siege/siege_ft.tga"), + CUBEMAP("ame_siege/siege_bk.tga"), + }; + skybox->model.texture = create_cubemap(faces); + + make_shader(GL_VERTEX_SHADER, SHADER("skybox.v.glsl"), &vertex); + check_gl(); + make_shader(GL_FRAGMENT_SHADER, SHADER("skybox.f.glsl"), &frag); + check_gl(); + + make_program_from_shaders(shaders, 2, &skybox->program); + check_gl(); + + skybox->uniforms.mvp = + glGetUniformLocation(skybox->program.handle, "mvp"); + + skybox->attrs.position = (gpu_addr) + glGetAttribLocation(skybox->program.handle, "position"); +} + + +void render_skybox(struct skybox *skybox, mat4 *camera) { + glDepthMask(GL_FALSE); + check_gl(); + + glUseProgram(skybox->program.handle); + check_gl(); + + glUniformMatrix4fv(skybox->uniforms.mvp, 1, 0, camera); + check_gl(); + + glBindTexture(GL_TEXTURE_CUBE_MAP, skybox->model.texture); + check_gl(); + + render_geometry(&skybox->model.geom, &skybox->attrs, &skybox->program); + check_gl(); + + glDepthMask(GL_TRUE); + check_gl(); +} diff --git a/src/skybox.h b/src/skybox.h @@ -0,0 +1,21 @@ + +#ifndef SKYBOX_H +#define SKYBOX_H + +#include "model.h" +#include "shader.h" +#include "mat4.h" + +struct skybox { + struct gpu_program program; + struct model model; + struct attributes attrs; + struct { + int mvp; + } uniforms; +}; + +void create_skybox(struct skybox *skybox); +void render_skybox(struct skybox *skybox, mat4 *camera); + +#endif /* SKYBOX_H */