From 7e68e733f525ced1a0565c3fb1245c706409fa82 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 3 Jun 2021 21:04:23 +0200 Subject: [PATCH] Update models_material_pbr.c --- examples/models/models_material_pbr.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/examples/models/models_material_pbr.c b/examples/models/models_material_pbr.c index f89a2758..dfef69da 100644 --- a/examples/models/models_material_pbr.c +++ b/examples/models/models_material_pbr.c @@ -279,17 +279,31 @@ static TextureCubemap GenTextureCubemap(Shader shader, Texture2D panorama, int s rlViewport(0, 0, size, size); // Set viewport to current fbo dimensions + // Activate and enable texture for drawing to cubemap faces + rlActiveTextureSlot(0); + rlEnableTexture(panorama.id); + for (int i = 0; i < 6; i++) { + // Set the view matrix for the current cube face rlSetUniformMatrix(shader.locs[SHADER_LOC_MATRIX_VIEW], fboViews[i]); + + // Select the current cubemap face attachment for the fbo + // WARNING: This function by default enables->attach->disables fbo!!! rlFramebufferAttach(fbo, cubemap.id, RL_ATTACHMENT_COLOR_CHANNEL0, RL_ATTACHMENT_CUBEMAP_POSITIVE_X + i, 0); - rlEnableFramebuffer(fbo); - rlSetTexture(panorama.id); // WARNING: It must be called after enabling current framebuffer if using internal batch system! + // Load and draw a cube, it uses the current enabled texture rlClearScreenBuffers(); - DrawCubeV(Vector3Zero(), Vector3One(), WHITE); - rlDrawRenderBatchActive(); + rlLoadDrawCube(); + + // ALTERNATIVE: Try to use internal batch system to draw the cube instead of rlLoadDrawCube + // for some reason this method does not work, maybe due to cube triangles definition? normals pointing out? + // TODO: Investigate this issue... + //rlSetTexture(panorama.id); // WARNING: It must be called after enabling current framebuffer if using internal batch system! + //rlClearScreenBuffers(); + //DrawCubeV(Vector3Zero(), Vector3One(), WHITE); + //rlDrawRenderBatchActive(); } //------------------------------------------------------------------------------------------