Skybox Implementation

This commit is contained in:
2025-08-31 16:36:01 -05:00
parent ed403627ea
commit c04809ff6b
10 changed files with 114 additions and 0 deletions

60
main.c
View File

@@ -6,6 +6,7 @@
#include "stdlib.h"
#include "stdint.h"
#include "time.h"
#include "rlgl.h"
//----------------------------------------------------------------------------------
// Defines and Macros
@@ -214,6 +215,49 @@ int main(void)
int locCutoff = GetShaderLocation(shAlphaClip, "u_alphaCutoff");
float cutoff = 0.3f; // tweak to taste; 0.3 - 0.5 works well for tree PNGs
SetShaderValue(shAlphaClip, locCutoff, &cutoff, SHADER_UNIFORM_FLOAT);
// --- Skybox setup ---
// Generate cube mesh
Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f);
Model skybox = LoadModelFromMesh(cube);
// Load skybox shader
// Make sure the .vs/.fs are in your resources/shaders/glsl330/ folder
Shader skyboxShader = LoadShader(
"resources/shaders/skybox.vs",
"resources/shaders/skybox.fs"
);
// Attach shader to skybox
skybox.materials[0].shader = skyboxShader;
// Load your cubemap (cross layout image)
Image img = LoadImage("resources/cubemap/cubemap.png");
// AUTO_DETECT will figure out layout (works for cross 4x3, panorama, etc.)
skybox.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture =
LoadTextureCubemap(img, CUBEMAP_LAYOUT_AUTO_DETECT);
UnloadImage(img);
// Tell the shader which material map is the environmentMap
int mapType = MATERIAL_MAP_CUBEMAP;
SetShaderValue(skyboxShader,
GetShaderLocation(skyboxShader, "environmentMap"),
&mapType, SHADER_UNIFORM_INT);
// Flip/gamma options (set to 0 for PNG cross)
int vflipped = 0;
int doGamma = 0;
SetShaderValue(skyboxShader, GetShaderLocation(skyboxShader, "vflipped"), &vflipped, SHADER_UNIFORM_INT);
SetShaderValue(skyboxShader, GetShaderLocation(skyboxShader, "doGamma"), &doGamma, SHADER_UNIFORM_INT);
// Done now you can draw it
//--------------------------------------------------------------------------------------
// Main game loop
@@ -333,6 +377,22 @@ int main(void)
ClearBackground(BLACK);
BeginMode3D(g.player.camera);
rlDisableBackfaceCulling();
rlDisableDepthMask();
// keep it centered on the camera
skybox.transform = MatrixTranslate(
g.player.camera.position.x,
g.player.camera.position.y,
g.player.camera.position.z
);
DrawModel(skybox, (Vector3){0}, 1.0f, WHITE);
rlEnableDepthMask();
rlEnableBackfaceCulling();
DrawLevel(mdlTile);
BeginShaderMode(shAlphaClip);