Remove old example code

This commit is contained in:
Not-Nik 2023-09-14 13:05:56 +02:00
parent a378960088
commit a6fa62999e
No known key found for this signature in database
GPG Key ID: 08BB71E672DB3BFD
3 changed files with 0 additions and 443 deletions

View File

@ -1,130 +0,0 @@
//
// models_loading
// Zig version:
// Author: Nikolas Wipper
// Date: 2020-02-15
//
usingnamespace @import("raylib");
const resourceDir = "raylib/examples/models/resources/";
pub fn main() anyerror!void {
// Initialization
//--------------------------------------------------------------------------------------
const screenWidth = 800;
const screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [models] example - models loading");
// Define the camera to look into our 3d world
var camera = Camera{
.position = Vector3{ .x = 50.0, .y = 50.0, .z = 50.0 }, // Camera position
.target = Vector3{ .x = 0.0, .y = 10.0, .z = 0.0 }, // Camera looking at point
.up = Vector3{ .x = 0.0, .y = 1.0, .z = 0.0 }, // Camera up vector (rotation towards target)
.fovy = 45.0, // Camera field-of-view Y
.projection = CameraProjection.CAMERA_PERSPECTIVE, // Camera mode type
};
var model = LoadModel(resourceDir ++ "models/castle.obj"); // Load model
var texture = LoadTexture(resourceDir ++ "models/castle_diffuse.png"); // Load model texture
model.materials[0].maps[@intFromEnum(MAP_DIFFUSE)].texture = texture; // Set map diffuse texture
var position = Vector3{ .x = 0.0, .y = 0.0, .z = 0.0 }; // Set model position
var bounds = MeshBoundingBox(model.meshes[0]); // Set model bounds
// NOTE: bounds are calculated from the original size of the model,
// if model is scaled on drawing, bounds must be also scaled
camera.SetMode(CameraMode.CAMERA_FREE); // Set a free camera mode
var selected = false; // Selected object flag
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
camera.Update();
// Load new models/textures on drag&drop
if (IsFileDropped()) {
var count: c_int = 0;
var droppedFiles = GetDroppedFiles(&count);
if (count == 1) // Only support one file dropped
{
if (IsFileExtension(droppedFiles[0], ".obj") or
IsFileExtension(droppedFiles[0], ".gltf") or
IsFileExtension(droppedFiles[0], ".iqm")) // Model file formats supported
{
UnloadModel(model); // Unload previous model
model = LoadModel(droppedFiles[0]); // Load new model
// Set current map diffuse texture
model.materials[0].maps[@intFromEnum(MAP_DIFFUSE)].texture = texture;
bounds = MeshBoundingBox(model.meshes[0]);
// TODO: Move camera position from target enough distance to visualize model properly
} else if (IsFileExtension(droppedFiles[0], ".png")) // Texture file formats supported
{
// Unload current model texture and load new one
UnloadTexture(texture);
texture = LoadTexture(droppedFiles[0]);
model.materials[0].maps[@intFromEnum(MAP_DIFFUSE)].texture = texture;
}
}
ClearDroppedFiles(); // Clear internal buffers
}
// Select model on mouse click
if (IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON)) {
// Check collision between ray and box
if (CheckCollisionRayBox(GetMouseRay(GetMousePosition(), camera), bounds)) {
selected = !selected;
} else {
selected = false;
}
}
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
camera.Begin();
DrawModel(model, position, 1.0, WHITE); // Draw 3d model with texture
DrawGrid(20, 10.0); // Draw a grid
if (selected) DrawBoundingBox(bounds, GREEN); // Draw selection box
camera.End();
DrawText("Drag & drop model to load mesh/texture.", 10, GetScreenHeight() - 20, 10, DARKGRAY);
if (selected) DrawText("MODEL SELECTED", GetScreenWidth() - 110, 10, 10, GREEN);
DrawText("(c) Castle 3D model by Alberto Cano", screenWidth - 200, screenHeight - 20, 10, GRAY);
DrawFPS(10, 10);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
UnloadTexture(texture); // Unload texture
UnloadModel(model); // Unload model
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
}

View File

@ -1,126 +0,0 @@
// This is a zig port of rlights.h by Ryan Roden-Corrent (rcorre).
// The original notice follows:
//
// *********************************************************************************************
//
// raylib.lights - Some useful functions to deal with lights data
//
// CONFIGURATION:
//
// #define RLIGHTS_IMPLEMENTATION
// Generates the implementation of the library into the included file.
// If not defined, the library is in header only mode and can be included
// in other headers or source files without problems. But only ONE file should
// hold the implementation.
//
// LICENSE: zlib/libpng
//
// Copyright (c) 2017-2020 Victor Fisac (@victorfisac) and Ramon Santamaria
// (@raysan5)
//
// This software is provided "as-is", without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the
// use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software in a
// product, an acknowledgment in the product documentation would be appreciated
// but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not
// be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
// *********************************************************************************************/
const std = @import("std");
usingnamespace @import("raylib");
const max_lights = 4;
pub const Light = struct {
type: LightType,
position: Vector3,
target: Vector3,
color: Color,
enabled: bool,
// Shader locations
enabledLoc: i32,
typeLoc: i32,
posLoc: i32,
targetLoc: i32,
colorLoc: i32,
};
// Light type
pub const LightType = enum { directional, point };
var lightsCount: u32 = 0;
fn getShaderLoc(shader: Shader, name: []const u8) !i32 {
// TODO: Below code doesn't look good to me,
// it assumes a specific shader naming and structure
// Probably this implementation could be improved
// (note from original C implementation, I don't have a better idea)
var buf: [32]u8 = undefined;
const key = try std.fmt.bufPrintZ(buf[0..], "lights[{}].{s}", .{ lightsCount, name });
return GetShaderLocation(shader, key);
}
// Create a light and get shader locations
pub fn CreateLight(typ: LightType, position: Vector3, target: Vector3, color: Color, shader: Shader) !Light {
if (lightsCount >= max_lights) {
return error.TooManyLights;
}
const light = Light{
.enabled = true,
.type = typ,
.position = position,
.target = target,
.color = color,
.enabledLoc = try getShaderLoc(shader, "enabled"),
.typeLoc = try getShaderLoc(shader, "type"),
.posLoc = try getShaderLoc(shader, "position"),
.targetLoc = try getShaderLoc(shader, "target"),
.colorLoc = try getShaderLoc(shader, "color"),
};
UpdateLightValues(shader, light);
lightsCount += 1;
return light;
}
// Send light properties to shader
// NOTE: Light shader locations should be available
pub fn UpdateLightValues(shader: Shader, light: Light) void {
// Send to shader light enabled state and type
SetShaderValue(shader, light.enabledLoc, &light.enabled, @enumToInt(ShaderUniformDataType.SHADER_UNIFORM_INT));
SetShaderValue(shader, light.typeLoc, &light.type, @enumToInt(ShaderUniformDataType.SHADER_UNIFORM_INT));
// Send to shader light position values
const position = [3]f32{ light.position.x, light.position.y, light.position.z };
SetShaderValue(shader, light.posLoc, &position, @enumToInt(ShaderUniformDataType.SHADER_UNIFORM_VEC3));
// Send to shader light target position values
const target = [3]f32{ light.target.x, light.target.y, light.target.z };
SetShaderValue(shader, light.targetLoc, &target, @enumToInt(ShaderUniformDataType.SHADER_UNIFORM_VEC3));
// Send to shader light color values
const color = [4]f32{
@intToFloat(f32, light.color.r) / 255.0,
@intToFloat(f32, light.color.g) / 255.0,
@intToFloat(f32, light.color.b) / 255.0,
@intToFloat(f32, light.color.a) / 255.0,
};
SetShaderValue(shader, light.colorLoc, &color, @enumToInt(ShaderUniformDataType.SHADER_UNIFORM_VEC4));
}

View File

@ -1,187 +0,0 @@
//
// shaders_basic_lighting
// Zig version:
// Author: Ryan Roden-Corrent
// Date: 2021-07-24
//
// 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.
//
// NOTE: Shaders used in this example are #version 330 (OpenGL 3.3).
usingnamespace @import("raylib");
usingnamespace @import("rlights.zig");
usingnamespace @import("raylib-math");
const resourceDir = "raylib/examples/shaders/resources/";
pub fn main() !void {
// Initialization
//--------------------------------------------------------------------------------------
const screenWidth = 800;
const screenHeight = 450;
//SetConfigFlags(.FLAG_MSAA_4X_HINT); // Enable Multi Sampling Anti Aliasing 4x
// (if available)
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - basic lighting");
// Define the camera to look into our 3d world
const camera = Camera{
.position = .{ .x = 2.0, .y = 2.0, .z = 6.0 }, // Camera position
.target = .{ .x = 0.0, .y = 0.5, .z = 0.0 }, // Camera looking at point
.up = .{ .x = 0.0, .y = 1.0, .z = 0.0 }, // Camera up vector (rotation towards target)
.fovy = 45.0, // Camera field-of-view Y
.projection = CameraProjection.CAMERA_PERSPECTIVE, // Camera mode type
};
// Load models
var modelA = LoadModelFromMesh(GenMeshTorus(0.4, 1.0, 16, 32));
var modelB = LoadModelFromMesh(GenMeshCube(1.0, 1.0, 1.0));
var modelC = LoadModelFromMesh(GenMeshSphere(0.5, 32, 32));
// Load models texture
const texture = LoadTexture(resourceDir ++ "texel_checker.png");
// Assign texture to default model material
modelA.materials[0].maps[@intFromEnum(MAP_DIFFUSE)].texture = texture;
modelB.materials[0].maps[@intFromEnum(MAP_DIFFUSE)].texture = texture;
modelC.materials[0].maps[@intFromEnum(MAP_DIFFUSE)].texture = texture;
var shader = LoadShader(
resourceDir ++ "/shaders/glsl330/base_lighting.vs",
resourceDir ++ "/shaders/glsl330/lighting.fs",
);
// Get some shader loactions
shader.locs[@intFromEnum(ShaderLocationIndex.SHADER_LOC_MATRIX_MODEL)] = GetShaderLocation(shader, "matModel");
shader.locs[@intFromEnum(ShaderLocationIndex.SHADER_LOC_VECTOR_VIEW)] = GetShaderLocation(shader, "viewPos");
// ambient light level
const ambientLoc = GetShaderLocation(shader, "ambient");
const ambientVals = [4]f32{ 0.2, 0.2, 0.2, 1.0 };
SetShaderValue(shader, ambientLoc, &ambientVals, @intFromEnum(ShaderUniformDataType.SHADER_UNIFORM_VEC4));
var angle: f32 = 6.282;
// All models use the same shader
modelA.materials[0].shader = shader;
modelB.materials[0].shader = shader;
modelC.materials[0].shader = shader;
// Using 4 point lights, white, red, green and blue
var lights = [_]Light{
try CreateLight(LightType.point, .{ .x = 4, .y = 2, .z = 4 }, Vector3Zero(), WHITE, shader),
try CreateLight(LightType.point, .{ .x = 4, .y = 2, .z = 4 }, Vector3Zero(), RED, shader),
try CreateLight(LightType.point, .{ .x = 0, .y = 4, .z = 2 }, Vector3Zero(), GREEN, shader),
try CreateLight(LightType.point, .{ .x = 0, .y = 4, .z = 2 }, Vector3Zero(), BLUE, shader),
};
SetCameraMode(camera, CameraMode.CAMERA_ORBITAL); // Set an orbital camera mode
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
if (IsKeyPressed(KeyboardKey.KEY_W)) {
lights[0].enabled = !lights[0].enabled;
}
if (IsKeyPressed(KeyboardKey.KEY_R)) {
lights[1].enabled = !lights[1].enabled;
}
if (IsKeyPressed(KeyboardKey.KEY_G)) {
lights[2].enabled = !lights[2].enabled;
}
if (IsKeyPressed(KeyboardKey.KEY_B)) {
lights[3].enabled = !lights[3].enabled;
}
//UpdateCamera(&camera); // Update camera
// Make the lights do differing orbits
angle -= 0.02;
lights[0].position.x = @cos(angle) * 4.0;
lights[0].position.z = @sin(angle) * 4.0;
lights[1].position.x = @cos(-angle * 0.6) * 4.0;
lights[1].position.z = @sin(-angle * 0.6) * 4.0;
lights[2].position.y = @cos(angle * 0.2) * 4.0;
lights[2].position.z = @sin(angle * 0.2) * 4.0;
lights[3].position.y = @cos(-angle * 0.35) * 4.0;
lights[3].position.z = @sin(-angle * 0.35) * 4.0;
UpdateLightValues(shader, lights[0]);
UpdateLightValues(shader, lights[1]);
UpdateLightValues(shader, lights[2]);
UpdateLightValues(shader, lights[3]);
// Rotate the torus
modelA.transform =
MatrixMultiply(modelA.transform, MatrixRotateX(-0.025));
modelA.transform =
MatrixMultiply(modelA.transform, MatrixRotateZ(0.012));
// Update the light shader with the camera view position
const cameraPos = [3]f32{ camera.position.x, camera.position.y, camera.position.z };
SetShaderValue(
shader,
shader.locs[@intFromEnum(ShaderLocationIndex.SHADER_LOC_VECTOR_VIEW)],
&cameraPos,
@intFromEnum(ShaderUniformDataType.SHADER_UNIFORM_VEC3),
);
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
BeginMode3D(camera);
// Draw the three models
DrawModel(modelA, Vector3Zero(), 1.0, WHITE);
DrawModel(modelB, .{ .x = -1.6, .y = 0, .z = 0 }, 1.0, WHITE);
DrawModel(modelC, .{ .x = 1.6, .y = 0, .z = 0 }, 1.0, WHITE);
// Draw markers to show where the lights are
if (lights[0].enabled) {
DrawSphereEx(lights[0].position, 0.2, 8, 8, WHITE);
}
if (lights[1].enabled) {
DrawSphereEx(lights[1].position, 0.2, 8, 8, RED);
}
if (lights[2].enabled) {
DrawSphereEx(lights[2].position, 0.2, 8, 8, GREEN);
}
if (lights[3].enabled) {
DrawSphereEx(lights[3].position, 0.2, 8, 8, BLUE);
}
DrawGrid(10, 1.0);
EndMode3D();
DrawFPS(10, 10);
DrawText("Use keys RGBW to toggle lights", 10, 30, 20, DARKGRAY);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
UnloadModel(modelA); // Unload the modelA
UnloadModel(modelB); // Unload the modelB
UnloadModel(modelC); // Unload the modelC
UnloadTexture(texture); // Unload the texture
UnloadShader(shader); // Unload shader
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
}