From 2051be3825afb89e7dc01711c573827491e14789 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Mon, 9 Oct 2017 10:13:02 +0200 Subject: [PATCH] Add mesh generation example -IN PROGRESS- --- examples/models/models_mesh_generation.c | 89 +++++++++++++++++++++++ examples/models/resources/pixels.png | Bin 0 -> 168 bytes 2 files changed, 89 insertions(+) create mode 100644 examples/models/models_mesh_generation.c create mode 100644 examples/models/resources/pixels.png diff --git a/examples/models/models_mesh_generation.c b/examples/models/models_mesh_generation.c new file mode 100644 index 000000000..2b3d5c5fa --- /dev/null +++ b/examples/models/models_mesh_generation.c @@ -0,0 +1,89 @@ +/******************************************************************************************* +* +* raylib example - procedural mesh generation +* +* This example has been created using raylib 1.8 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2017 Ramon Santamaria (Ray San) +* +********************************************************************************************/ + +#include "raylib.h" + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [models] example - mesh generation"); + + //Model model = LoadModelFromMesh(GenMeshPlane(2, 2, 5, 5)); // Texture coordinates must be divided by resX, resZ + //Model model = LoadModelFromMesh(GenMeshCube(2.0f, 1.0f, 2.0f)); // OK! + //Model model = LoadModelFromMesh(GenMeshSphere(2, 32, 32)); // OK! (par_shapes) + //Model model = LoadModelFromMesh(GenMeshHemiSphere(2, 16, 16)); // OK! (par_shapes) + //Model model = LoadModelFromMesh(GenMeshCylinder(1, 2, 16)); // OK! (par_shapes) + Model model = LoadModelFromMesh(GenMeshTorus(0.25f, 4.0f, 16, 32)); + //Model model = LoadModelFromMesh(GenMeshKnot(1.0f, 2.0f, 16, 128)); + model.material.maps[MAP_DIFFUSE].texture = LoadTexture("resources/pixels.png"); + + // Debug information + /* + printf("model.mesh.vertexCount: %i\n", model.mesh.vertexCount); + printf("model.mesh.triangleCount: %i\n", model.mesh.triangleCount); + printf("model.mesh.vboId (position): %i\n", model.mesh.vboId[0]); + printf("model.mesh.vboId (texcoords): %i\n", model.mesh.vboId[1]); + printf("model.mesh.vboId (normals): %i\n", model.mesh.vboId[2]); + printf("model.mesh.vboId (indices): %i\n", model.mesh.vboId[6]); + */ + + // Define the camera to look into our 3d world + Camera camera = {{ 5.0f, 5.0f, 5.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f }; + + Vector3 position = { 0.0f, 0.0f, 0.0f }; + + SetCameraMode(camera, CAMERA_FREE); // Set a free 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 + //---------------------------------------------------------------------------------- + UpdateCamera(&camera); // Update internal camera and our camera + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + Begin3dMode(camera); + + DrawModel(model, position, 1.0f, WHITE); + + DrawGrid(10, 1.0); + + End3dMode(); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadModel(model); + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} \ No newline at end of file diff --git a/examples/models/resources/pixels.png b/examples/models/resources/pixels.png new file mode 100644 index 0000000000000000000000000000000000000000..c9a4134b730536a1c776430d86ae4e8c6407f240 GIT binary patch literal 168 zcmeAS@N?(olHy`uVBq!ia0vp^Od!m`1|*BN@u~nR#^NA%Cx&(BWL^R}Ea{HEjtmSN z`?>!lvI6;>1s;*b3=DjSL74G){)!Z!pk#?_L`iUdT1k0gQ7S`0VrE{6US4X6f{C7i zo}syM-uz^sA_-3y#}J9|hVJoO0{`fBpZ)f7ltkZgSdB&6)cdsD{DQ)z4*} HQ$iB}<8&|i literal 0 HcmV?d00001