mirror of
https://github.com/raysan5/raylib.git
synced 2025-11-14 14:28:51 +00:00
EXAMPLES: Format tweaks
This commit is contained in:
@@ -59,10 +59,10 @@ int main(void)
|
||||
TextFormat("resources/shaders/glsl%i/lighting.fs", GLSL_VERSION));
|
||||
// Get some required shader locations
|
||||
shader.locs[SHADER_LOC_VECTOR_VIEW] = GetShaderLocation(shader, "viewPos");
|
||||
// NOTE: "matModel" location name is automatically assigned on shader loading,
|
||||
// NOTE: "matModel" location name is automatically assigned on shader loading,
|
||||
// no need to get the location again if using that uniform name
|
||||
//shader.locs[SHADER_LOC_MATRIX_MODEL] = GetShaderLocation(shader, "matModel");
|
||||
|
||||
|
||||
// Ambient light level (some basic lighting)
|
||||
int ambientLoc = GetShaderLocation(shader, "ambient");
|
||||
SetShaderValue(shader, ambientLoc, (float[4]){ 0.1f, 0.1f, 0.1f, 1.0f }, SHADER_UNIFORM_VEC4);
|
||||
@@ -87,13 +87,13 @@ int main(void)
|
||||
// Update the shader with the camera view vector (points towards { 0.0f, 0.0f, 0.0f })
|
||||
float cameraPos[3] = { camera.position.x, camera.position.y, camera.position.z };
|
||||
SetShaderValue(shader, shader.locs[SHADER_LOC_VECTOR_VIEW], cameraPos, SHADER_UNIFORM_VEC3);
|
||||
|
||||
|
||||
// Check key inputs to enable/disable lights
|
||||
if (IsKeyPressed(KEY_Y)) { lights[0].enabled = !lights[0].enabled; }
|
||||
if (IsKeyPressed(KEY_R)) { lights[1].enabled = !lights[1].enabled; }
|
||||
if (IsKeyPressed(KEY_G)) { lights[2].enabled = !lights[2].enabled; }
|
||||
if (IsKeyPressed(KEY_B)) { lights[3].enabled = !lights[3].enabled; }
|
||||
|
||||
|
||||
// Update light values (actually, only enable/disable them)
|
||||
for (int i = 0; i < MAX_LIGHTS; i++) UpdateLightValues(shader, lights[i]);
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
*
|
||||
* Copyright (c) 2023-2025 Afan OLOVCIC (@_DevDad)
|
||||
*
|
||||
* Model: "Old Rusty Car" (https://skfb.ly/LxRy) by Renafox,
|
||||
* licensed under Creative Commons Attribution-NonCommercial
|
||||
* Model: "Old Rusty Car" (https://skfb.ly/LxRy) by Renafox,
|
||||
* licensed under Creative Commons Attribution-NonCommercial
|
||||
* (http://creativecommons.org/licenses/by-nc/4.0/)
|
||||
*
|
||||
********************************************************************************************/
|
||||
@@ -105,7 +105,7 @@ int main()
|
||||
// shader already takes care of it accordingly
|
||||
shader.locs[SHADER_LOC_MAP_METALNESS] = GetShaderLocation(shader, "mraMap");
|
||||
shader.locs[SHADER_LOC_MAP_NORMAL] = GetShaderLocation(shader, "normalMap");
|
||||
// WARNING: Similar to the MRA map, the emissive map packs different information
|
||||
// WARNING: Similar to the MRA map, the emissive map packs different information
|
||||
// into a single texture: it stores height and emission data
|
||||
// It is binded to SHADER_LOC_MAP_EMISSION location an properly processed on shader
|
||||
shader.locs[SHADER_LOC_MAP_EMISSION] = GetShaderLocation(shader, "emissiveMap");
|
||||
@@ -153,7 +153,7 @@ int main()
|
||||
car.materials[0].maps[MATERIAL_MAP_METALNESS].texture = LoadTexture("resources/old_car_mra.png");
|
||||
car.materials[0].maps[MATERIAL_MAP_NORMAL].texture = LoadTexture("resources/old_car_n.png");
|
||||
car.materials[0].maps[MATERIAL_MAP_EMISSION].texture = LoadTexture("resources/old_car_e.png");
|
||||
|
||||
|
||||
// Load floor model mesh and assign material parameters
|
||||
// NOTE: A basic plane shape can be generated instead of being loaded from a model file
|
||||
Model floor = LoadModel("resources/models/plane.glb");
|
||||
@@ -161,9 +161,9 @@ int main()
|
||||
//GenMeshTangents(&floorMesh); // TODO: Review tangents generation
|
||||
//Model floor = LoadModelFromMesh(floorMesh);
|
||||
|
||||
// Assign material shader for our floor model, same PBR shader
|
||||
// Assign material shader for our floor model, same PBR shader
|
||||
floor.materials[0].shader = shader;
|
||||
|
||||
|
||||
floor.materials[0].maps[MATERIAL_MAP_ALBEDO].color = WHITE;
|
||||
floor.materials[0].maps[MATERIAL_MAP_METALNESS].value = 0.8f;
|
||||
floor.materials[0].maps[MATERIAL_MAP_ROUGHNESS].value = 0.1f;
|
||||
@@ -193,7 +193,7 @@ int main()
|
||||
SetShaderValue(shader, GetShaderLocation(shader, "useTexNormal"), &usage, SHADER_UNIFORM_INT);
|
||||
SetShaderValue(shader, GetShaderLocation(shader, "useTexMRA"), &usage, SHADER_UNIFORM_INT);
|
||||
SetShaderValue(shader, GetShaderLocation(shader, "useTexEmissive"), &usage, SHADER_UNIFORM_INT);
|
||||
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//---------------------------------------------------------------------------------------
|
||||
|
||||
@@ -221,11 +221,11 @@ int main()
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(BLACK);
|
||||
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
|
||||
// Set floor model texture tiling and emissive color parameters on shader
|
||||
SetShaderValue(shader, textureTilingLoc, &floorTextureTiling, SHADER_UNIFORM_VEC2);
|
||||
Vector4 floorEmissiveColor = ColorNormalize(floor.materials[0].maps[MATERIAL_MAP_EMISSION].color);
|
||||
@@ -234,7 +234,7 @@ int main()
|
||||
// Set floor metallic and roughness values
|
||||
SetShaderValue(shader, metallicValueLoc, &floor.materials[0].maps[MATERIAL_MAP_METALNESS].value, SHADER_UNIFORM_FLOAT);
|
||||
SetShaderValue(shader, roughnessValueLoc, &floor.materials[0].maps[MATERIAL_MAP_ROUGHNESS].value, SHADER_UNIFORM_FLOAT);
|
||||
|
||||
|
||||
DrawModel(floor, (Vector3){ 0.0f, 0.0f, 0.0f }, 5.0f, WHITE); // Draw floor model
|
||||
|
||||
// Set old car model texture tiling, emissive color and emissive intensity parameters on shader
|
||||
@@ -247,24 +247,24 @@ int main()
|
||||
// Set old car metallic and roughness values
|
||||
SetShaderValue(shader, metallicValueLoc, &car.materials[0].maps[MATERIAL_MAP_METALNESS].value, SHADER_UNIFORM_FLOAT);
|
||||
SetShaderValue(shader, roughnessValueLoc, &car.materials[0].maps[MATERIAL_MAP_ROUGHNESS].value, SHADER_UNIFORM_FLOAT);
|
||||
|
||||
|
||||
DrawModel(car, (Vector3){ 0.0f, 0.0f, 0.0f }, 0.25f, WHITE); // Draw car model
|
||||
|
||||
// Draw spheres to show the lights positions
|
||||
for (int i = 0; i < MAX_LIGHTS; i++)
|
||||
{
|
||||
Color lightColor = (Color){ lights[i].color[0]*255, lights[i].color[1]*255, lights[i].color[2]*255, lights[i].color[3]*255 };
|
||||
|
||||
|
||||
if (lights[i].enabled) DrawSphereEx(lights[i].position, 0.2f, 8, 8, lightColor);
|
||||
else DrawSphereWires(lights[i].position, 0.2f, 8, 8, ColorAlpha(lightColor, 0.3f));
|
||||
}
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
DrawText("Toggle lights: [1][2][3][4]", 10, 40, 20, LIGHTGRAY);
|
||||
|
||||
DrawText("(c) Old Rusty Car model by Renafox (https://skfb.ly/LxRy)", screenWidth - 320, screenHeight - 20, 10, LIGHTGRAY);
|
||||
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
EndDrawing();
|
||||
@@ -273,20 +273,20 @@ int main()
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Unbind (disconnect) shader from car.material[0]
|
||||
// Unbind (disconnect) shader from car.material[0]
|
||||
// to avoid UnloadMaterial() trying to unload it automatically
|
||||
car.materials[0].shader = (Shader){ 0 };
|
||||
UnloadMaterial(car.materials[0]);
|
||||
car.materials[0].maps = NULL;
|
||||
UnloadModel(car);
|
||||
|
||||
|
||||
floor.materials[0].shader = (Shader){ 0 };
|
||||
UnloadMaterial(floor.materials[0]);
|
||||
floor.materials[0].maps = NULL;
|
||||
UnloadModel(floor);
|
||||
|
||||
|
||||
UnloadShader(shader); // Unload Shader
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
@@ -310,7 +310,7 @@ static Light CreateLight(int type, Vector3 position, Vector3 target, Color color
|
||||
light.color[2] = (float)color.b/255.0f;
|
||||
light.color[3] = (float)color.a/255.0f;
|
||||
light.intensity = intensity;
|
||||
|
||||
|
||||
// NOTE: Shader parameters names for lights must match the requested ones
|
||||
light.enabledLoc = GetShaderLocation(shader, TextFormat("lights[%i].enabled", lightCount));
|
||||
light.typeLoc = GetShaderLocation(shader, TextFormat("lights[%i].type", lightCount));
|
||||
@@ -318,7 +318,7 @@ static Light CreateLight(int type, Vector3 position, Vector3 target, Color color
|
||||
light.targetLoc = GetShaderLocation(shader, TextFormat("lights[%i].target", lightCount));
|
||||
light.colorLoc = GetShaderLocation(shader, TextFormat("lights[%i].color", lightCount));
|
||||
light.intensityLoc = GetShaderLocation(shader, TextFormat("lights[%i].intensity", lightCount));
|
||||
|
||||
|
||||
UpdateLight(shader, light);
|
||||
|
||||
lightCount++;
|
||||
@@ -333,7 +333,7 @@ static void UpdateLight(Shader shader, Light light)
|
||||
{
|
||||
SetShaderValue(shader, light.enabledLoc, &light.enabled, SHADER_UNIFORM_INT);
|
||||
SetShaderValue(shader, light.typeLoc, &light.type, SHADER_UNIFORM_INT);
|
||||
|
||||
|
||||
// Send to shader light position values
|
||||
float position[3] = { light.position.x, light.position.y, light.position.z };
|
||||
SetShaderValue(shader, light.positionLoc, position, SHADER_UNIFORM_VEC3);
|
||||
|
||||
@@ -78,7 +78,7 @@ int main(void)
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateCamera(&camera, CAMERA_ORBITAL);
|
||||
|
||||
|
||||
Vector2 mousePosition = GetMousePosition();
|
||||
|
||||
swirlCenter[0] = mousePosition.x;
|
||||
|
||||
@@ -42,7 +42,7 @@ typedef struct GBuffer {
|
||||
unsigned int positionTexture;
|
||||
unsigned int normalTexture;
|
||||
unsigned int albedoSpecTexture;
|
||||
|
||||
|
||||
unsigned int depthRenderbuffer;
|
||||
} GBuffer;
|
||||
|
||||
@@ -94,14 +94,14 @@ int main(void)
|
||||
TraceLog(LOG_WARNING, "Failed to create framebuffer");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
rlEnableFramebuffer(gBuffer.framebuffer);
|
||||
|
||||
// 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.
|
||||
|
||||
// 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
|
||||
// and you wish to maintain this approach, consider using `RL_PIXELFORMAT_UNCOMPRESSED_R32G32B32`.
|
||||
gBuffer.positionTexture = rlLoadTexture(NULL, screenWidth, screenHeight, RL_PIXELFORMAT_UNCOMPRESSED_R16G16B16, 1);
|
||||
@@ -161,7 +161,7 @@ int main(void)
|
||||
const float CUBE_SCALE = 0.25;
|
||||
Vector3 cubePositions[MAX_CUBES] = { 0 };
|
||||
float cubeRotations[MAX_CUBES] = { 0 };
|
||||
|
||||
|
||||
for (int i = 0; i < MAX_CUBES; i++)
|
||||
{
|
||||
cubePositions[i] = (Vector3){
|
||||
@@ -169,7 +169,7 @@ int main(void)
|
||||
.y = (float)(rand()%5),
|
||||
.z = (float)(rand()%10) - 5,
|
||||
};
|
||||
|
||||
|
||||
cubeRotations[i] = (float)(rand()%360);
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ int main(void)
|
||||
// Update the shader with the camera view vector (points towards { 0.0f, 0.0f, 0.0f })
|
||||
float cameraPos[3] = { camera.position.x, camera.position.y, camera.position.z };
|
||||
SetShaderValue(deferredShader, deferredShader.locs[SHADER_LOC_VECTOR_VIEW], cameraPos, SHADER_UNIFORM_VEC3);
|
||||
|
||||
|
||||
// Check key inputs to enable/disable lights
|
||||
if (IsKeyPressed(KEY_Y)) { lights[0].enabled = !lights[0].enabled; }
|
||||
if (IsKeyPressed(KEY_R)) { lights[1].enabled = !lights[1].enabled; }
|
||||
@@ -215,7 +215,7 @@ int main(void)
|
||||
rlEnableFramebuffer(gBuffer.framebuffer);
|
||||
rlClearColor(0, 0, 0, 0);
|
||||
rlClearScreenBuffers(); // Clear color and depth buffer
|
||||
|
||||
|
||||
rlDisableColorBlend();
|
||||
BeginMode3D(camera);
|
||||
// NOTE: We have to use rlEnableShader here. `BeginShaderMode` or thus `rlSetShader`
|
||||
@@ -281,7 +281,7 @@ int main(void)
|
||||
}
|
||||
rlDisableShader();
|
||||
EndMode3D();
|
||||
|
||||
|
||||
DrawText("FINAL RESULT", 10, screenHeight - 30, 20, DARKGREEN);
|
||||
} break;
|
||||
case DEFERRED_POSITION:
|
||||
@@ -291,7 +291,7 @@ int main(void)
|
||||
.width = screenWidth,
|
||||
.height = screenHeight,
|
||||
}, (Rectangle) { 0, 0, (float)screenWidth, (float)-screenHeight }, Vector2Zero(), RAYWHITE);
|
||||
|
||||
|
||||
DrawText("POSITION TEXTURE", 10, screenHeight - 30, 20, DARKGREEN);
|
||||
} break;
|
||||
case DEFERRED_NORMAL:
|
||||
@@ -301,7 +301,7 @@ int main(void)
|
||||
.width = screenWidth,
|
||||
.height = screenHeight,
|
||||
}, (Rectangle) { 0, 0, (float)screenWidth, (float)-screenHeight }, Vector2Zero(), RAYWHITE);
|
||||
|
||||
|
||||
DrawText("NORMAL TEXTURE", 10, screenHeight - 30, 20, DARKGREEN);
|
||||
} break;
|
||||
case DEFERRED_ALBEDO:
|
||||
@@ -311,7 +311,7 @@ int main(void)
|
||||
.width = screenWidth,
|
||||
.height = screenHeight,
|
||||
}, (Rectangle) { 0, 0, (float)screenWidth, (float)-screenHeight }, Vector2Zero(), RAYWHITE);
|
||||
|
||||
|
||||
DrawText("ALBEDO TEXTURE", 10, screenHeight - 30, 20, DARKGREEN);
|
||||
} break;
|
||||
default: break;
|
||||
@@ -321,7 +321,7 @@ int main(void)
|
||||
DrawText("Switch G-buffer textures: [1][2][3][4]", 10, 70, 20, DARKGRAY);
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
// -----------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [shaders] example - Sieve of Eratosthenes
|
||||
* raylib [shaders] example - sieve of Eratosthenes
|
||||
*
|
||||
* Example complexity rating: [★★★☆] 3/4
|
||||
*
|
||||
@@ -45,7 +45,7 @@ int main(void)
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - Sieve of Eratosthenes");
|
||||
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - sieve of Eratosthenes");
|
||||
|
||||
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [shaders] example - Hot reloading
|
||||
* raylib [shaders] example - hot reloading
|
||||
*
|
||||
* Example complexity rating: [★★★☆] 3/4
|
||||
*
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [shaders] example - Hybrid Rendering
|
||||
* raylib [shaders] example - hybrid rendering
|
||||
*
|
||||
* Example complexity rating: [★★★★] 4/4
|
||||
*
|
||||
@@ -69,7 +69,7 @@ int main(void)
|
||||
marchLocs.camDir = GetShaderLocation(shdrRaymarch, "camDir");
|
||||
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};
|
||||
SetShaderValue(shdrRaymarch, marchLocs.screenCenter , &screenCenter , SHADER_UNIFORM_VEC2);
|
||||
|
||||
@@ -84,10 +84,10 @@ int main(void)
|
||||
.fovy = 45.0f, // Camera field-of-view Y
|
||||
.projection = CAMERA_PERSPECTIVE // Camera projection type
|
||||
};
|
||||
|
||||
|
||||
// Camera FOV is pre-calculated in the camera Distance.
|
||||
float camDist = 1.0f/(tanf(camera.fovy*0.5f*DEG2RAD));
|
||||
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
@@ -100,12 +100,12 @@ int main(void)
|
||||
|
||||
// Update Camera Postion in the ray march shader.
|
||||
SetShaderValue(shdrRaymarch, marchLocs.camPos, &(camera.position), RL_SHADER_UNIFORM_VEC3);
|
||||
|
||||
|
||||
// Update Camera Looking Vector. Vector length determines FOV.
|
||||
Vector3 camDir = Vector3Scale( Vector3Normalize( Vector3Subtract(camera.target, camera.position)) , camDist);
|
||||
SetShaderValue(shdrRaymarch, marchLocs.camDir, &(camDir), RL_SHADER_UNIFORM_VEC3);
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
// Draw into our custom render texture (framebuffer)
|
||||
@@ -117,7 +117,7 @@ int main(void)
|
||||
BeginShaderMode(shdrRaymarch);
|
||||
DrawRectangleRec((Rectangle){0,0, (float)screenWidth, (float)screenHeight},WHITE);
|
||||
EndShaderMode();
|
||||
|
||||
|
||||
// Rasterize Scene
|
||||
BeginMode3D(camera);
|
||||
BeginShaderMode(shdrRaster);
|
||||
@@ -130,10 +130,10 @@ int main(void)
|
||||
EndMode3D();
|
||||
EndTextureMode();
|
||||
|
||||
// Draw into screen our custom render texture
|
||||
// Draw into screen our custom render texture
|
||||
BeginDrawing();
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
DrawTextureRec(target.texture, (Rectangle) { 0, 0, (float)screenWidth, (float)-screenHeight }, (Vector2) { 0, 0 }, WHITE);
|
||||
DrawFPS(10, 10);
|
||||
EndDrawing();
|
||||
|
||||
@@ -167,7 +167,7 @@ int main(void)
|
||||
// do not represent full screen coordinates (space where want to apply shader)
|
||||
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), BLACK);
|
||||
EndTextureMode();
|
||||
|
||||
|
||||
BeginDrawing();
|
||||
ClearBackground(BLACK); // Clear screen background
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ int main(void)
|
||||
// Load a new texcoords2 attributes buffer
|
||||
mesh.vboId[SHADER_LOC_VERTEX_TEXCOORD02] = rlLoadVertexBuffer(mesh.texcoords2, mesh.vertexCount*2*sizeof(float), false);
|
||||
rlEnableVertexArray(mesh.vaoId);
|
||||
|
||||
|
||||
// Index 5 is for texcoords2
|
||||
rlSetVertexAttribute(5, 2, RL_FLOAT, 0, 0, 0);
|
||||
rlEnableVertexAttribute(5);
|
||||
@@ -156,10 +156,10 @@ int main(void)
|
||||
(Vector2){ 0.0, 0.0 },
|
||||
0.0,
|
||||
WHITE);
|
||||
|
||||
|
||||
DrawText("lightmap", GetRenderWidth() - 66, 16 + MAP_SIZE*8, 10, GRAY);
|
||||
DrawText("10x10 pixels", GetRenderWidth() - 76, 30 + MAP_SIZE*8, 10, GRAY);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ int main(void)
|
||||
Vector3 axis = Vector3Normalize((Vector3){ (float)GetRandomValue(0, 360), (float)GetRandomValue(0, 360), (float)GetRandomValue(0, 360) });
|
||||
float angle = (float)GetRandomValue(0, 180)*DEG2RAD;
|
||||
Matrix rotation = MatrixRotate(axis, angle);
|
||||
|
||||
|
||||
transforms[i] = MatrixMultiply(rotation, translation);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [shaders] example - Multiple sample2D with default batch system
|
||||
* raylib [shaders] example - multi sample2D
|
||||
*
|
||||
* Example complexity rating: [★★☆☆] 2/4
|
||||
*
|
||||
@@ -38,7 +38,7 @@ int main(void)
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib - multiple sample2D");
|
||||
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - multi sample2D");
|
||||
|
||||
Image imRed = GenImageColor(800, 450, (Color){ 255, 0, 0, 255 });
|
||||
Texture texRed = LoadTextureFromImage(imRed);
|
||||
@@ -93,7 +93,7 @@ int main(void)
|
||||
// an additional texture units is enabled for texBlue [sampler2D texture1]
|
||||
DrawTexture(texRed, 0, 0, WHITE);
|
||||
|
||||
EndShaderMode(); // Texture sampler2D is reseted, needs to be set again for next frame
|
||||
EndShaderMode(); // Texture sampler2D is reseted, needs to be set again for next frame
|
||||
|
||||
DrawText("Use KEY_LEFT/KEY_RIGHT to move texture mixing in shader!", 80, GetScreenHeight() - 40, 20, RAYWHITE);
|
||||
|
||||
|
||||
@@ -141,7 +141,7 @@ int main(void)
|
||||
DrawGrid(10, 1.0f); // Draw a grid
|
||||
EndMode3D(); // End 3d mode drawing, returns to orthographic 2d mode
|
||||
EndTextureMode(); // End drawing to texture (now we have a texture available for next passes)
|
||||
|
||||
|
||||
BeginDrawing();
|
||||
ClearBackground(RAYWHITE); // Clear screen background
|
||||
|
||||
|
||||
@@ -173,7 +173,7 @@ int main(void)
|
||||
|
||||
// Draw the same exact things as we drew in the shadowmap!
|
||||
DrawScene(cube, robot);
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
DrawText("Shadows in raylib using the shadowmapping algorithm!", screenWidth - 320, screenHeight - 20, 10, GRAY);
|
||||
|
||||
@@ -97,7 +97,7 @@ int main(void)
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateCamera(&camera, CAMERA_FIRST_PERSON);
|
||||
|
||||
|
||||
framesCounter++;
|
||||
rotation.x += 0.01f;
|
||||
rotation.y += 0.005f;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [shaders] example - Apply an shdrOutline to a texture
|
||||
* raylib [shaders] example - texture outline
|
||||
*
|
||||
* Example complexity rating: [★★★☆] 3/4
|
||||
*
|
||||
@@ -36,7 +36,7 @@ int main(void)
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - Apply an outline to a texture");
|
||||
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - texture outline");
|
||||
|
||||
Texture2D texture = LoadTexture("resources/fudesumi.png");
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ int main(void)
|
||||
// Load a cube model
|
||||
Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f);
|
||||
Model model = LoadModelFromMesh(cube);
|
||||
|
||||
|
||||
// Load a texture and assign to cube model
|
||||
Texture2D texture = LoadTexture("resources/cubicmap_atlas.png");
|
||||
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture;
|
||||
@@ -77,17 +77,17 @@ int main(void)
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
|
||||
BeginShaderMode(shader);
|
||||
DrawModel(model, (Vector3){ 0.0f, 0.0f, 0.0f }, 2.0f, WHITE);
|
||||
EndShaderMode();
|
||||
|
||||
DrawGrid(10, 1.0f);
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
DrawText("Use mouse to rotate the camera", 10, 10, 20, DARKGRAY);
|
||||
@@ -104,6 +104,6 @@ int main(void)
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ int main(void)
|
||||
Shader shader = LoadShader(
|
||||
TextFormat("resources/shaders/glsl%i/vertex_displacement.vs", GLSL_VERSION),
|
||||
TextFormat("resources/shaders/glsl%i/vertex_displacement.fs", GLSL_VERSION));
|
||||
|
||||
|
||||
// Load perlin noise texture
|
||||
Image perlinNoiseImage = GenImagePerlinNoise(512, 512, 0, 0, 1.0f);
|
||||
Texture perlinNoiseMap = LoadTextureFromImage(perlinNoiseImage);
|
||||
@@ -64,7 +64,7 @@ int main(void)
|
||||
rlActiveTextureSlot(1);
|
||||
rlEnableTexture(perlinNoiseMap.id);
|
||||
rlSetUniformSampler(perlinNoiseMapLoc, 1);
|
||||
|
||||
|
||||
// Create a plane mesh and model
|
||||
Mesh planeMesh = GenMeshPlane(50, 50, 50, 50);
|
||||
Model planeModel = LoadModelFromMesh(planeMesh);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [shader] example - render depth texture
|
||||
* raylib [shaders] example - render depth texture
|
||||
*
|
||||
* Example complexity rating: [★★★☆] 3/4
|
||||
*
|
||||
@@ -36,7 +36,7 @@ int main(void)
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [shader] example - render depth texture");
|
||||
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - render depth texture");
|
||||
|
||||
// Init camera
|
||||
Camera camera = { 0 };
|
||||
@@ -76,7 +76,7 @@ int main(void)
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginTextureMode(target);
|
||||
ClearBackground(WHITE);
|
||||
|
||||
|
||||
BeginMode3D(camera);
|
||||
DrawModel(cube, (Vector3){ 0.0f, 0.0f, 0.0f }, 3.0f, YELLOW);
|
||||
DrawModel(floor, (Vector3){ 10.0f, 0.0f, 2.0f }, 2.0f, RED);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [shaders] example - Depth buffer writing
|
||||
* raylib [shaders] example - depth buffer writing
|
||||
*
|
||||
* Example complexity rating: [★★☆☆] 2/4
|
||||
*
|
||||
@@ -60,7 +60,7 @@ int main(void)
|
||||
.fovy = 45.0f, // Camera field-of-view Y
|
||||
.projection = CAMERA_PERSPECTIVE // Camera projection type
|
||||
};
|
||||
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
@@ -71,13 +71,13 @@ int main(void)
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateCamera(&camera, CAMERA_ORBITAL);
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
// Draw into our custom render texture (framebuffer)
|
||||
BeginTextureMode(target);
|
||||
ClearBackground(WHITE);
|
||||
|
||||
|
||||
BeginMode3D(camera);
|
||||
BeginShaderMode(shader);
|
||||
DrawCubeWiresV((Vector3){ 0.0f, 0.5f, 1.0f }, (Vector3){ 1.0f, 1.0f, 1.0f }, RED);
|
||||
@@ -89,7 +89,7 @@ int main(void)
|
||||
EndMode3D();
|
||||
EndTextureMode();
|
||||
|
||||
// Draw into screen our custom render texture
|
||||
// Draw into screen our custom render texture
|
||||
BeginDrawing();
|
||||
ClearBackground(RAYWHITE);
|
||||
DrawTextureRec(target.texture, (Rectangle) { 0, 0, (float)screenWidth, (float)-screenHeight }, (Vector2) { 0, 0 }, WHITE);
|
||||
|
||||
Reference in New Issue
Block a user