WARNING: **NEW** raylib code CONVENTION: Comments do not end with '.'

This commit is contained in:
Ray 2025-08-07 18:23:20 +02:00
commit 570082deba
55 changed files with 210 additions and 208 deletions

View file

@ -28,6 +28,10 @@ Some other conventions to follow:
- **ALWAYS** initialize all defined variables. - **ALWAYS** initialize all defined variables.
- **Do not use TABS**, use 4 spaces instead. - **Do not use TABS**, use 4 spaces instead.
- Avoid trailing spaces, please, avoid them - Avoid trailing spaces, please, avoid them
- Comments always start with space + capital letter and never end with a '.', place them **before** the line(s) they refer to
```c
// This is a comment in raylib or raylib examples
```
- Control flow statements always are followed **by a space**: - Control flow statements always are followed **by a space**:
```c ```c
if (condition) value = 0; if (condition) value = 0;

View file

@ -108,8 +108,6 @@ int main(void)
{ {
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Sample mouse input.
mousePosition = GetMousePosition(); mousePosition = GetMousePosition();
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) if (IsMouseButtonDown(MOUSE_BUTTON_LEFT))
@ -125,7 +123,7 @@ int main(void)
// Compute two cycles to allow the buffer padding, simplifying any modulation, resampling, etc. // Compute two cycles to allow the buffer padding, simplifying any modulation, resampling, etc.
if (frequency != oldFrequency) if (frequency != oldFrequency)
{ {
// Compute wavelength. Limit size in both directions. // Compute wavelength. Limit size in both directions
//int oldWavelength = waveLength; //int oldWavelength = waveLength;
waveLength = (int)(22050/frequency); waveLength = (int)(22050/frequency);
if (waveLength > MAX_SAMPLES/2) waveLength = MAX_SAMPLES/2; if (waveLength > MAX_SAMPLES/2) waveLength = MAX_SAMPLES/2;

View file

@ -12,7 +12,7 @@
* 4. PollInputEvents() * 4. PollInputEvents()
* *
* To avoid steps 2, 3 and 4, flag SUPPORT_CUSTOM_FRAME_CONTROL can be enabled in * To avoid steps 2, 3 and 4, flag SUPPORT_CUSTOM_FRAME_CONTROL can be enabled in
* config.h (it requires recompiling raylib). This way those steps are up to the user. * config.h (it requires recompiling raylib). This way those steps are up to the user
* *
* Note that enabling this flag invalidates some functions: * Note that enabling this flag invalidates some functions:
* - GetFrameTime() * - GetFrameTime()

View file

@ -43,7 +43,8 @@ int main(void)
Camera2D screenSpaceCamera = { 0 }; // Smoothing camera Camera2D screenSpaceCamera = { 0 }; // Smoothing camera
screenSpaceCamera.zoom = 1.0f; screenSpaceCamera.zoom = 1.0f;
RenderTexture2D target = LoadRenderTexture(virtualScreenWidth, virtualScreenHeight); // This is where we'll draw all our objects. // Load render texture to draw all our objects
RenderTexture2D target = LoadRenderTexture(virtualScreenWidth, virtualScreenHeight);
Rectangle rec01 = { 70.0f, 35.0f, 20.0f, 20.0f }; Rectangle rec01 = { 70.0f, 35.0f, 20.0f, 20.0f };
Rectangle rec02 = { 90.0f, 55.0f, 30.0f, 10.0f }; Rectangle rec02 = { 90.0f, 55.0f, 30.0f, 10.0f };

View file

@ -6,30 +6,30 @@
1. File naming: <module>_<description> - Lower case filename, words separated by underscore, 1. File naming: <module>_<description> - Lower case filename, words separated by underscore,
no more than 3-4 words in total to describe the example. <module> referes to the primary no more than 3-4 words in total to describe the example. <module> referes to the primary
raylib module the example is more related with (code, shapes, textures, models, shaders, raudio). raylib module the example is more related with (code, shapes, textures, models, shaders, raudio)
i.e: core_input_multitouch, shapes_lines_bezier, shaders_palette_switch i.e: core_input_multitouch, shapes_lines_bezier, shaders_palette_switch
2. Follow below template structure, example info should list the module, the short description 2. Follow below template structure, example info should list the module, the short description
and the author of the example, twitter or github info could be also provided for the author. and the author of the example, twitter or github info could be also provided for the author
Short description should also be used on the title of the window. Short description should also be used on the title of the window
3. Code should be organized by sections:[Initialization]- [Update] - [Draw] - [De-Initialization] 3. Code should be organized by sections:[Initialization]- [Update] - [Draw] - [De-Initialization]
Place your code between the dotted lines for every section, please don't mix update logic with drawing Place your code between the dotted lines for every section, please don't mix update logic with drawing
and remember to unload all loaded resources. and remember to unload all loaded resources
4. Code should follow raylib conventions: https://github.com/raysan5/raylib/wiki/raylib-coding-conventions 4. Code should follow raylib conventions: https://github.com/raysan5/raylib/wiki/raylib-coding-conventions
Try to be very organized, using line-breaks appropiately. Try to be very organized, using line-breaks appropiately
5. Add comments to the specific parts of code the example is focus on. 5. Add comments to the specific parts of code the example is focus on
Don't abuse with comments, try to be clear and impersonal on the comments. Don't abuse with comments, try to be clear and impersonal on the comments
6. Try to keep the example simple, under 300 code lines if possible. Try to avoid external dependencies. 6. Try to keep the example simple, under 300 code lines if possible. Try to avoid external dependencies
Try to avoid defining functions outside the main(). Example should be as self-contained as possible. Try to avoid defining functions outside the main(). Example should be as self-contained as possible
7. About external resources, they should be placed in a [resources] folder and those resources 7. About external resources, they should be placed in a [resources] folder and those resources
should be open and free for use and distribution. Avoid propietary content. should be open and free for use and distribution. Avoid propietary content
8. Try to keep the example simple but with a creative touch. 8. Try to keep the example simple but with a creative touch
Simple but beautiful examples are more appealing to users! Simple but beautiful examples are more appealing to users!
9. In case of additional information is required, just come to raylib Discord channel: example-contributions 9. In case of additional information is required, just come to raylib Discord channel: example-contributions
@ -37,7 +37,7 @@
10. Have fun! 10. Have fun!
The following files should be updated when adding a new example, it's planned to create some The following files should be updated when adding a new example, it's planned to create some
script to automatize this process but not available yet. script to automatize this process but not available yet
- raylib/examples/<category>/<category>_example_name.c - raylib/examples/<category>/<category>_example_name.c
- raylib/examples/<category>/<category>_example_name.png - raylib/examples/<category>/<category>_example_name.png

View file

@ -17,7 +17,7 @@
* *
* NOTE: To export a model from blender, make sure it is not posed, the vertices need to be * NOTE: To export a model from blender, make sure it is not posed, the vertices need to be
* in the same position as they would be in edit mode and the scale of your models is * in the same position as they would be in edit mode and the scale of your models is
* set to 0. Scaling can be done from the export menu. * set to 0. Scaling can be done from the export menu
* *
********************************************************************************************/ ********************************************************************************************/

View file

@ -40,7 +40,7 @@ int main(void)
Vector3 billPositionStatic = { 0.0f, 2.0f, 0.0f }; // Position of static billboard Vector3 billPositionStatic = { 0.0f, 2.0f, 0.0f }; // Position of static billboard
Vector3 billPositionRotating = { 1.0f, 2.0f, 1.0f }; // Position of rotating billboard Vector3 billPositionRotating = { 1.0f, 2.0f, 1.0f }; // Position of rotating billboard
// Entire billboard texture, source is used to take a segment from a larger texture. // Entire billboard texture, source is used to take a segment from a larger texture
Rectangle source = { 0.0f, 0.0f, (float)bill.width, (float)bill.height }; Rectangle source = { 0.0f, 0.0f, (float)bill.width, (float)bill.height };
// NOTE: Billboard locked on axis-Y // NOTE: Billboard locked on axis-Y
@ -54,7 +54,7 @@ int main(void)
Vector2 origin = Vector2Scale(size, 0.5f); Vector2 origin = Vector2Scale(size, 0.5f);
// Distance is needed for the correct billboard draw order // Distance is needed for the correct billboard draw order
// Larger distance (further away from the camera) should be drawn prior to smaller distance. // Larger distance (further away from the camera) should be drawn prior to smaller distance
float distanceStatic; float distanceStatic;
float distanceRotating; float distanceRotating;
float rotation = 0.0f; float rotation = 0.0f;

View file

@ -7,11 +7,11 @@
* NOTE: raylib supports multiple models file formats: * NOTE: raylib supports multiple models file formats:
* *
* - OBJ > Text file format. Must include vertex position-texcoords-normals information, * - OBJ > Text file format. Must include vertex position-texcoords-normals information,
* if files references some .mtl materials file, it will be loaded (or try to). * if files references some .mtl materials file, it will be loaded (or try to)
* - GLTF > Text/binary file format. Includes lot of information and it could * - GLTF > Text/binary file format. Includes lot of information and it could
* also reference external files, raylib will try loading mesh and materials data. * also reference external files, raylib will try loading mesh and materials data
* - IQM > Binary file format. Includes mesh vertex data but also animation data, * - IQM > Binary file format. Includes mesh vertex data but also animation data,
* raylib can load .iqm animations. * raylib can load .iqm animations
* - VOX > Binary file format. MagikaVoxel mesh format: * - VOX > Binary file format. MagikaVoxel mesh format:
* https://github.com/ephtracy/voxel-model/blob/master/MagicaVoxel-file-format-vox.txt * https://github.com/ephtracy/voxel-model/blob/master/MagicaVoxel-file-format-vox.txt
* - M3D > Binary file format. Model 3D format: * - M3D > Binary file format. Model 3D format:

View file

@ -119,7 +119,7 @@ int main(void)
// without a -1, we would always draw a cube at the origin // without a -1, we would always draw a cube at the origin
for (int i = 0; i < model.boneCount - 1; i++) for (int i = 0; i < model.boneCount - 1; i++)
{ {
// By default the model is loaded in bind-pose by LoadModel(). // By default the model is loaded in bind-pose by LoadModel()
// But if UpdateModelAnimation() has been called at least once // But if UpdateModelAnimation() has been called at least once
// then the model is already in animation pose, so we need the animated skeleton // then the model is already in animation pose, so we need the animated skeleton
if (!animPlaying || !animsCount) if (!animPlaying || !animsCount)

View file

@ -221,10 +221,12 @@ int main(void)
} }
// NoEase function, used when "no easing" is selected for any axis. It just ignores all parameters besides b. // NoEase function, used when "no easing" is selected for any axis
// It just ignores all parameters besides b
static float NoEase(float t, float b, float c, float d) static float NoEase(float t, float b, float c, float d)
{ {
float burn = t + b + c + d; // Hack to avoid compiler warning (about unused variables) // Hack to avoid compiler warning (about unused variables)
float burn = t + b + c + d;
d += burn; d += burn;
return b; return b;

View file

@ -16,13 +16,13 @@
******************************************************************************************** ********************************************************************************************
* *
* Mixes raylib and plain OpenGL code to draw a GL_POINTS based particle system. The * Mixes raylib and plain OpenGL code to draw a GL_POINTS based particle system. The
* primary point is to demonstrate raylib and OpenGL interop. * primary point is to demonstrate raylib and OpenGL interop
* *
* rlgl batched draw operations internally so we have to flush the current batch before * rlgl batched draw operations internally so we have to flush the current batch before
* doing our own OpenGL work (rlDrawRenderBatchActive()). * doing our own OpenGL work (rlDrawRenderBatchActive())
* *
* The example also demonstrates how to get the current model view projection matrix of * The example also demonstrates how to get the current model view projection matrix of
* raylib. That way raylib cameras and so on work as expected. * raylib. That way raylib cameras and so on work as expected
* *
********************************************************************************************/ ********************************************************************************************/
@ -87,13 +87,13 @@ int main(void)
particles[i].x = (float)GetRandomValue(20, screenWidth - 20); particles[i].x = (float)GetRandomValue(20, screenWidth - 20);
particles[i].y = (float)GetRandomValue(50, screenHeight - 20); particles[i].y = (float)GetRandomValue(50, screenHeight - 20);
// Give each particle a slightly different period. But don't spread it to much. // Give each particle a slightly different period. But don't spread it to much
// This way the particles line up every so often and you get a glimps of what is going on. // This way the particles line up every so often and you get a glimps of what is going on
particles[i].period = (float)GetRandomValue(10, 30)/10.0f; particles[i].period = (float)GetRandomValue(10, 30)/10.0f;
} }
// Create a plain OpenGL vertex buffer with the data and an vertex array object // Create a plain OpenGL vertex buffer with the data and an vertex array object
// that feeds the data from the buffer into the vertexPosition shader attribute. // that feeds the data from the buffer into the vertexPosition shader attribute
GLuint vao = 0; GLuint vao = 0;
GLuint vbo = 0; GLuint vbo = 0;
glGenVertexArrays(1, &vao); glGenVertexArrays(1, &vao);

View file

@ -23,11 +23,11 @@
#include <stdlib.h> #include <stdlib.h>
// IMPORTANT: This must match gol*.glsl GOL_WIDTH constant. // IMPORTANT: This must match gol*.glsl GOL_WIDTH constant
// This must be a multiple of 16 (check golLogic compute dispatch). // This must be a multiple of 16 (check golLogic compute dispatch)
#define GOL_WIDTH 768 #define GOL_WIDTH 768
// Maximum amount of queued draw commands (squares draw from mouse down events). // Maximum amount of queued draw commands (squares draw from mouse down events)
#define MAX_BUFFERED_TRANSFERTS 48 #define MAX_BUFFERED_TRANSFERTS 48
// Game Of Life Update Command // Game Of Life Update Command
@ -160,7 +160,7 @@ int main(void)
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Unload shader buffers objects. // Unload shader buffers objects
rlUnloadShaderBuffer(ssboA); rlUnloadShaderBuffer(ssboA);
rlUnloadShaderBuffer(ssboB); rlUnloadShaderBuffer(ssboB);
rlUnloadShaderBuffer(ssboTransfert); rlUnloadShaderBuffer(ssboTransfert);

View file

@ -9,7 +9,7 @@
* *
* Example originally created with raylib 1.6, last time updated with raylib 4.0 * Example originally created with raylib 1.6, last time updated with raylib 4.0
* *
* WARNING: This example is intended only for PLATFORM_DESKTOP and OpenGL 3.3 Core profile. * WARNING: This example is intended only for PLATFORM_DESKTOP and OpenGL 3.3 Core profile
* It could work on other platforms if redesigned for those platforms (out-of-scope) * It could work on other platforms if redesigned for those platforms (out-of-scope)
* *
* DEPENDENCIES: * DEPENDENCIES:
@ -48,7 +48,7 @@
* 2. Altered source versions must be plainly marked as such, and must not be misrepresented * 2. Altered source versions must be plainly marked as such, and must not be misrepresented
* as being the original software. * as being the original software.
* *
* 3. This notice may not be removed or altered from any source distribution. * 3. This notice may not be removed or altered from any source distribution
* *
********************************************************************************************/ ********************************************************************************************/

View file

@ -5,9 +5,9 @@
* Example complexity rating: [★★★★] 4/4 * Example complexity rating: [★★★★] 4/4
* *
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support, * NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version. * OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version
* *
* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3). * NOTE: Shaders used in this example are #version 330 (OpenGL 3.3)
* *
* Example originally created with raylib 3.0, last time updated with raylib 4.2 * Example originally created with raylib 3.0, last time updated with raylib 4.2
* *

View file

@ -5,7 +5,7 @@
* Example complexity rating: [★★☆☆] 2/4 * Example complexity rating: [★★☆☆] 2/4
* *
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support, * NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version. * OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version
* *
* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3), to test this example * NOTE: Shaders used in this example are #version 330 (OpenGL 3.3), to test this example
* on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders * on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders

View file

@ -99,44 +99,44 @@ int main(void)
// NOTE: Vertex positions are stored in a texture for simplicity. A better approach would use a depth texture // NOTE: Vertex positions are stored in a texture for simplicity. A better approach would use a depth texture
// (instead of a detph renderbuffer) to reconstruct world positions in the final render shader via clip-space position, // (instead of a detph renderbuffer) to reconstruct world positions in the final render shader via clip-space position,
// depth, and the inverse view/projection matrices. // depth, and the inverse view/projection matrices
// 16-bit precision ensures OpenGL ES 3 compatibility, though it may lack precision for real scenarios. // 16-bit precision ensures OpenGL ES 3 compatibility, though it may lack precision for real scenarios
// But as mentioned above, the positions could be reconstructed instead of stored. If not targeting OpenGL ES // But as mentioned above, the positions could be reconstructed instead of stored. If not targeting OpenGL ES
// and you wish to maintain this approach, consider using `RL_PIXELFORMAT_UNCOMPRESSED_R32G32B32`. // and you wish to maintain this approach, consider using `RL_PIXELFORMAT_UNCOMPRESSED_R32G32B32`
gBuffer.positionTexture = rlLoadTexture(NULL, screenWidth, screenHeight, RL_PIXELFORMAT_UNCOMPRESSED_R16G16B16, 1); gBuffer.positionTexture = rlLoadTexture(NULL, screenWidth, screenHeight, RL_PIXELFORMAT_UNCOMPRESSED_R16G16B16, 1);
// Similarly, 16-bit precision is used for normals ensures OpenGL ES 3 compatibility. // Similarly, 16-bit precision is used for normals ensures OpenGL ES 3 compatibility
// This is generally sufficient, but a 16-bit fixed-point format offer a better uniform precision in all orientations. // This is generally sufficient, but a 16-bit fixed-point format offer a better uniform precision in all orientations
gBuffer.normalTexture = rlLoadTexture(NULL, screenWidth, screenHeight, RL_PIXELFORMAT_UNCOMPRESSED_R16G16B16, 1); gBuffer.normalTexture = rlLoadTexture(NULL, screenWidth, screenHeight, RL_PIXELFORMAT_UNCOMPRESSED_R16G16B16, 1);
// Albedo (diffuse color) and specular strength can be combined into one texture. // Albedo (diffuse color) and specular strength can be combined into one texture
// The color in RGB, and the specular strength in the alpha channel. // The color in RGB, and the specular strength in the alpha channel
gBuffer.albedoSpecTexture = rlLoadTexture(NULL, screenWidth, screenHeight, RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, 1); gBuffer.albedoSpecTexture = rlLoadTexture(NULL, screenWidth, screenHeight, RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, 1);
// Activate the draw buffers for our framebuffer // Activate the draw buffers for our framebuffer
rlActiveDrawBuffers(3); rlActiveDrawBuffers(3);
// Now we attach our textures to the framebuffer. // Now we attach our textures to the framebuffer
rlFramebufferAttach(gBuffer.framebuffer, gBuffer.positionTexture, RL_ATTACHMENT_COLOR_CHANNEL0, RL_ATTACHMENT_TEXTURE2D, 0); rlFramebufferAttach(gBuffer.framebuffer, gBuffer.positionTexture, RL_ATTACHMENT_COLOR_CHANNEL0, RL_ATTACHMENT_TEXTURE2D, 0);
rlFramebufferAttach(gBuffer.framebuffer, gBuffer.normalTexture, RL_ATTACHMENT_COLOR_CHANNEL1, RL_ATTACHMENT_TEXTURE2D, 0); rlFramebufferAttach(gBuffer.framebuffer, gBuffer.normalTexture, RL_ATTACHMENT_COLOR_CHANNEL1, RL_ATTACHMENT_TEXTURE2D, 0);
rlFramebufferAttach(gBuffer.framebuffer, gBuffer.albedoSpecTexture, RL_ATTACHMENT_COLOR_CHANNEL2, RL_ATTACHMENT_TEXTURE2D, 0); rlFramebufferAttach(gBuffer.framebuffer, gBuffer.albedoSpecTexture, RL_ATTACHMENT_COLOR_CHANNEL2, RL_ATTACHMENT_TEXTURE2D, 0);
// Finally we attach the depth buffer. // Finally we attach the depth buffer
gBuffer.depthRenderbuffer = rlLoadTextureDepth(screenWidth, screenHeight, true); gBuffer.depthRenderbuffer = rlLoadTextureDepth(screenWidth, screenHeight, true);
rlFramebufferAttach(gBuffer.framebuffer, gBuffer.depthRenderbuffer, RL_ATTACHMENT_DEPTH, RL_ATTACHMENT_RENDERBUFFER, 0); rlFramebufferAttach(gBuffer.framebuffer, gBuffer.depthRenderbuffer, RL_ATTACHMENT_DEPTH, RL_ATTACHMENT_RENDERBUFFER, 0);
// Make sure our framebuffer is complete. // Make sure our framebuffer is complete
// NOTE: rlFramebufferComplete() automatically unbinds the framebuffer, so we don't have // NOTE: rlFramebufferComplete() automatically unbinds the framebuffer, so we don't have
// to rlDisableFramebuffer() here. // to rlDisableFramebuffer() here
if (!rlFramebufferComplete(gBuffer.framebuffer)) if (!rlFramebufferComplete(gBuffer.framebuffer))
{ {
TraceLog(LOG_WARNING, "Framebuffer is not complete"); TraceLog(LOG_WARNING, "Framebuffer is not complete");
} }
// Now we initialize the sampler2D uniform's in the deferred shader. // Now we initialize the sampler2D uniform's in the deferred shader
// We do this by setting the uniform's values to the texture units that // We do this by setting the uniform's values to the texture units that
// we later bind our g-buffer textures to. // we later bind our g-buffer textures to
rlEnableShader(deferredShader.id); rlEnableShader(deferredShader.id);
int texUnitPosition = 0; int texUnitPosition = 0;
int texUnitNormal = 1; int texUnitNormal = 1;
@ -219,7 +219,7 @@ int main(void)
rlDisableColorBlend(); rlDisableColorBlend();
BeginMode3D(camera); BeginMode3D(camera);
// NOTE: We have to use rlEnableShader here. `BeginShaderMode` or thus `rlSetShader` // NOTE: We have to use rlEnableShader here. `BeginShaderMode` or thus `rlSetShader`
// will not work, as they won't immediately load the shader program. // will not work, as they won't immediately load the shader program
rlEnableShader(gbufferShader.id); rlEnableShader(gbufferShader.id);
// When drawing a model here, make sure that the material's shaders // When drawing a model here, make sure that the material's shaders
// are set to the gbuffer shader! // are set to the gbuffer shader!
@ -236,7 +236,7 @@ int main(void)
EndMode3D(); EndMode3D();
rlEnableColorBlend(); rlEnableColorBlend();
// Go back to the default framebuffer (0) and draw our deferred shading. // Go back to the default framebuffer (0) and draw our deferred shading
rlDisableFramebuffer(); rlDisableFramebuffer();
rlClearScreenBuffers(); // Clear color & depth buffer rlClearScreenBuffers(); // Clear color & depth buffer
@ -264,7 +264,7 @@ int main(void)
rlEnableColorBlend(); rlEnableColorBlend();
EndMode3D(); EndMode3D();
// As a last step, we now copy over the depth buffer from our g-buffer to the default framebuffer. // As a last step, we now copy over the depth buffer from our g-buffer to the default framebuffer
rlBindFramebuffer(RL_READ_FRAMEBUFFER, gBuffer.framebuffer); rlBindFramebuffer(RL_READ_FRAMEBUFFER, gBuffer.framebuffer);
rlBindFramebuffer(RL_DRAW_FRAMEBUFFER, 0); rlBindFramebuffer(RL_DRAW_FRAMEBUFFER, 0);
rlBlitFramebuffer(0, 0, screenWidth, screenHeight, 0, 0, screenWidth, screenHeight, 0x00000100); // GL_DEPTH_BUFFER_BIT rlBlitFramebuffer(0, 0, screenWidth, screenHeight, 0, 0, screenWidth, screenHeight, 0x00000100); // GL_DEPTH_BUFFER_BIT

View file

@ -4,7 +4,7 @@
* *
* Example complexity rating: [★★★☆] 3/4 * Example complexity rating: [★★★☆] 3/4
* *
* NOTE: Sieve of Eratosthenes, the earliest known (ancient Greek) prime number sieve. * NOTE: Sieve of Eratosthenes, the earliest known (ancient Greek) prime number sieve
* *
* "Sift the twos and sift the threes, * "Sift the twos and sift the threes,
* The Sieve of Eratosthenes. * The Sieve of Eratosthenes.
@ -12,9 +12,9 @@
* the numbers that are left are prime." * the numbers that are left are prime."
* *
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support, * NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version. * OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version
* *
* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3). * NOTE: Shaders used in this example are #version 330 (OpenGL 3.3)
* *
* Example originally created with raylib 2.5, last time updated with raylib 4.0 * Example originally created with raylib 2.5, last time updated with raylib 4.0
* *

View file

@ -5,9 +5,9 @@
* Example complexity rating: [★★★☆] 3/4 * Example complexity rating: [★★★☆] 3/4
* *
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support, * NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version. * OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version
* *
* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3). * NOTE: Shaders used in this example are #version 330 (OpenGL 3.3)
* *
* Example originally created with raylib 2.5, last time updated with raylib 3.7 * Example originally created with raylib 2.5, last time updated with raylib 3.7
* *

View file

@ -5,7 +5,7 @@
* Example complexity rating: [★★★☆] 3/4 * Example complexity rating: [★★★☆] 3/4
* *
* NOTE: This example requires raylib OpenGL 3.3 for shaders support and only #version 330 * NOTE: This example requires raylib OpenGL 3.3 for shaders support and only #version 330
* is currently supported. OpenGL ES 2.0 platforms are not supported at the moment. * is currently supported. OpenGL ES 2.0 platforms are not supported at the moment
* *
* Example originally created with raylib 3.0, last time updated with raylib 3.5 * Example originally created with raylib 3.0, last time updated with raylib 3.5
* *

View file

@ -61,15 +61,15 @@ int main(void)
// You are required to write depth for all shaders if one shader does it // You are required to write depth for all shaders if one shader does it
Shader shdrRaster = LoadShader(0, TextFormat("resources/shaders/glsl%i/hybrid_raster.fs", GLSL_VERSION)); Shader shdrRaster = LoadShader(0, TextFormat("resources/shaders/glsl%i/hybrid_raster.fs", GLSL_VERSION));
// Declare Struct used to store camera locs. // Declare Struct used to store camera locs
RayLocs marchLocs = {0}; RayLocs marchLocs = {0};
// Fill the struct with shader locs. // Fill the struct with shader locs
marchLocs.camPos = GetShaderLocation(shdrRaymarch, "camPos"); marchLocs.camPos = GetShaderLocation(shdrRaymarch, "camPos");
marchLocs.camDir = GetShaderLocation(shdrRaymarch, "camDir"); marchLocs.camDir = GetShaderLocation(shdrRaymarch, "camDir");
marchLocs.screenCenter = GetShaderLocation(shdrRaymarch, "screenCenter"); marchLocs.screenCenter = GetShaderLocation(shdrRaymarch, "screenCenter");
// Transfer screenCenter position to shader. Which is used to calculate ray direction. // Transfer screenCenter position to shader. Which is used to calculate ray direction
Vector2 screenCenter = {.x = screenWidth/2.0f, .y = screenHeight/2.0f}; Vector2 screenCenter = {.x = screenWidth/2.0f, .y = screenHeight/2.0f};
SetShaderValue(shdrRaymarch, marchLocs.screenCenter , &screenCenter , SHADER_UNIFORM_VEC2); SetShaderValue(shdrRaymarch, marchLocs.screenCenter , &screenCenter , SHADER_UNIFORM_VEC2);
@ -85,7 +85,7 @@ int main(void)
.projection = CAMERA_PERSPECTIVE // Camera projection type .projection = CAMERA_PERSPECTIVE // Camera projection type
}; };
// Camera FOV is pre-calculated in the camera Distance. // Camera FOV is pre-calculated in the camera distance
float camDist = 1.0f/(tanf(camera.fovy*0.5f*DEG2RAD)); float camDist = 1.0f/(tanf(camera.fovy*0.5f*DEG2RAD));
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60); // Set our game to run at 60 frames-per-second
@ -98,10 +98,10 @@ int main(void)
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
UpdateCamera(&camera, CAMERA_ORBITAL); UpdateCamera(&camera, CAMERA_ORBITAL);
// Update Camera Postion in the ray march shader. // Update Camera Postion in the ray march shader
SetShaderValue(shdrRaymarch, marchLocs.camPos, &(camera.position), RL_SHADER_UNIFORM_VEC3); SetShaderValue(shdrRaymarch, marchLocs.camPos, &(camera.position), RL_SHADER_UNIFORM_VEC3);
// Update Camera Looking Vector. Vector length determines FOV. // Update Camera Looking Vector. Vector length determines FOV
Vector3 camDir = Vector3Scale( Vector3Normalize( Vector3Subtract(camera.target, camera.position)) , camDist); Vector3 camDir = Vector3Scale( Vector3Normalize( Vector3Subtract(camera.target, camera.position)) , camDist);
SetShaderValue(shdrRaymarch, marchLocs.camDir, &(camDir), RL_SHADER_UNIFORM_VEC3); SetShaderValue(shdrRaymarch, marchLocs.camDir, &(camDir), RL_SHADER_UNIFORM_VEC3);
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -113,7 +113,7 @@ int main(void)
ClearBackground(WHITE); ClearBackground(WHITE);
// Raymarch Scene // Raymarch Scene
rlEnableDepthTest(); //Manually enable Depth Test to handle multiple rendering methods. rlEnableDepthTest(); // Manually enable Depth Test to handle multiple rendering methods
BeginShaderMode(shdrRaymarch); BeginShaderMode(shdrRaymarch);
DrawRectangleRec((Rectangle){0,0, (float)screenWidth, (float)screenHeight},WHITE); DrawRectangleRec((Rectangle){0,0, (float)screenWidth, (float)screenHeight},WHITE);
EndShaderMode(); EndShaderMode();

Some files were not shown because too many files have changed in this diff Show more