diff options
| author | Ray <[email protected]> | 2017-10-20 00:17:24 +0200 |
|---|---|---|
| committer | Ray <[email protected]> | 2017-10-20 00:17:24 +0200 |
| commit | 48daec567f8d22e4492eb47b878d7ff86024f97a (patch) | |
| tree | 14dfb6feec1e4a7a6c03e0a37825aa7703de57d3 /examples/src | |
| parent | 1be9753752eaee413d584b4e9b1de383ba217ecf (diff) | |
| download | raylib.com-48daec567f8d22e4492eb47b878d7ff86024f97a.tar.gz raylib.com-48daec567f8d22e4492eb47b878d7ff86024f97a.zip | |
Reviewed examples code to 1.8
Diffstat (limited to 'examples/src')
| -rw-r--r-- | examples/src/core/core_3d_picking.c | 1 | ||||
| -rw-r--r-- | examples/src/models/models_cubicmap.c | 12 | ||||
| -rw-r--r-- | examples/src/models/models_heightmap.c | 20 | ||||
| -rw-r--r-- | examples/src/models/models_mesh_picking.c | 28 | ||||
| -rw-r--r-- | examples/src/models/models_obj_loading.c | 2 | ||||
| -rw-r--r-- | examples/src/physac/physics_demo.c | 6 | ||||
| -rw-r--r-- | examples/src/physac/physics_friction.c | 5 | ||||
| -rw-r--r-- | examples/src/physac/physics_movement.c | 5 | ||||
| -rw-r--r-- | examples/src/physac/physics_restitution.c | 5 | ||||
| -rw-r--r-- | examples/src/physac/physics_shatter.c | 5 | ||||
| -rw-r--r-- | examples/src/shaders/shaders_custom_uniform.c | 2 | ||||
| -rw-r--r-- | examples/src/shaders/shaders_model_shader.c | 4 | ||||
| -rw-r--r-- | examples/src/shaders/shaders_postprocessing.c | 2 | ||||
| -rw-r--r-- | examples/src/shaders/shaders_shapes_textures.c | 2 | ||||
| -rw-r--r-- | examples/src/shapes/shapes_basic_shapes.c | 2 | ||||
| -rw-r--r-- | examples/src/textures/textures_image_drawing.c | 8 |
16 files changed, 63 insertions, 46 deletions
diff --git a/examples/src/core/core_3d_picking.c b/examples/src/core/core_3d_picking.c index bd5c334..7658b39 100644 --- a/examples/src/core/core_3d_picking.c +++ b/examples/src/core/core_3d_picking.c @@ -48,7 +48,6 @@ int main() if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) { - // NOTE: This function is NOT WORKING properly! ray = GetMouseRay(GetMousePosition(), camera); // Check collision between ray and box diff --git a/examples/src/models/models_cubicmap.c b/examples/src/models/models_cubicmap.c index 0e61302..d8be932 100644 --- a/examples/src/models/models_cubicmap.c +++ b/examples/src/models/models_cubicmap.c @@ -2,7 +2,7 @@ * * raylib [models] example - Cubicmap loading and drawing * -* This example has been created using raylib 1.3 (www.raylib.com) +* 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) 2015 Ramon Santamaria (@raysan5) @@ -25,11 +25,13 @@ int main() Image image = LoadImage("resources/cubicmap.png"); // Load cubicmap image (RAM) Texture2D cubicmap = LoadTextureFromImage(image); // Convert image to texture to display (VRAM) - Model map = LoadCubicmap(image); // Load cubicmap model (generate model from image) + + Mesh mesh = GenMeshCubicmap(image, (Vector3){ 1.0f, 1.0f, 1.0f }); + Model model = LoadModelFromMesh(mesh); // NOTE: By default each cube is mapped to one part of texture atlas Texture2D texture = LoadTexture("resources/cubicmap_atlas.png"); // Load map texture - map.material.texDiffuse = texture; // Set map diffuse texture + model.material.maps[MAP_DIFFUSE].texture = texture; // Set map diffuse texture Vector3 mapPosition = { -16.0f, 0.0f, -8.0f }; // Set model position @@ -56,7 +58,7 @@ int main() Begin3dMode(camera); - DrawModel(map, mapPosition, 1.0f, WHITE); + DrawModel(model, mapPosition, 1.0f, WHITE); End3dMode(); @@ -76,7 +78,7 @@ int main() //-------------------------------------------------------------------------------------- UnloadTexture(cubicmap); // Unload cubicmap texture UnloadTexture(texture); // Unload map texture - UnloadModel(map); // Unload map model + UnloadModel(model); // Unload map model CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- diff --git a/examples/src/models/models_heightmap.c b/examples/src/models/models_heightmap.c index 10069e0..e476d1b 100644 --- a/examples/src/models/models_heightmap.c +++ b/examples/src/models/models_heightmap.c @@ -2,7 +2,7 @@ * * raylib [models] example - Heightmap loading and drawing * -* This example has been created using raylib 1.3 (www.raylib.com) +* 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) 2015 Ramon Santamaria (@raysan5) @@ -23,11 +23,14 @@ int main() // Define our custom camera to look into our 3d world Camera camera = {{ 18.0f, 16.0f, 18.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f }; - Image image = LoadImage("resources/heightmap.png"); // Load heightmap image (RAM) - Texture2D texture = LoadTextureFromImage(image); // Convert image to texture (VRAM) - Model map = LoadHeightmap(image, (Vector3){ 16, 8, 16 }); // Load heightmap model with defined size - map.material.texDiffuse = texture; // Set map diffuse texture - Vector3 mapPosition = { -8.0f, 0.0f, -8.0f }; // Set model position (depends on model scaling!) + Image image = LoadImage("resources/heightmap.png"); // Load heightmap image (RAM) + Texture2D texture = LoadTextureFromImage(image); // Convert image to texture (VRAM) + + Mesh mesh = GenMeshHeightmap(image, (Vector3){ 16, 8, 16 }); // Generate heightmap mesh (RAM and VRAM) + Model model = LoadModelFromMesh(mesh); // Load model from generated mesh + + model.material.maps[MAP_DIFFUSE].texture = texture; // Set map diffuse texture + Vector3 mapPosition = { -8.0f, 0.0f, -8.0f }; // Define model position UnloadImage(image); // Unload heightmap image from RAM, already uploaded to VRAM @@ -52,8 +55,7 @@ int main() Begin3dMode(camera); - // NOTE: Model is scaled to 1/4 of its original size (128x128 units) - DrawModel(map, mapPosition, 1.0f, RED); + DrawModel(model, mapPosition, 1.0f, RED); DrawGrid(20, 1.0f); @@ -71,7 +73,7 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- UnloadTexture(texture); // Unload texture - UnloadModel(map); // Unload model + UnloadModel(model); // Unload model CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- diff --git a/examples/src/models/models_mesh_picking.c b/examples/src/models/models_mesh_picking.c index 0b5247e..e150fe9 100644 --- a/examples/src/models/models_mesh_picking.c +++ b/examples/src/models/models_mesh_picking.c @@ -35,7 +35,7 @@ int main() Model tower = LoadModel("resources/tower.obj"); // Load OBJ model Texture2D texture = LoadTexture("resources/tower.png"); // Load model texture - tower.material.texDiffuse = texture; // Set model diffuse texture + tower.material.maps[MAP_DIFFUSE].texture = texture; // Set model diffuse texture Vector3 towerPos = { 0.0f, 0.0f, 0.0f }; // Set model position BoundingBox towerBBox = CalculateBoundingBox(tower.mesh); @@ -89,7 +89,7 @@ int main() cursorColor = PURPLE; hitObjectName = "Triangle"; - bary = VectorBarycenter(nearestHit.hitPosition, ta, tb, tc); + bary = Vector3Barycenter(nearestHit.position, ta, tb, tc); hitTriangle = true; } else hitTriangle = false; @@ -136,15 +136,15 @@ int main() // If we hit something, draw the cursor at the hit point if (nearestHit.hit) { - DrawCube(nearestHit.hitPosition, 0.3, 0.3, 0.3, cursorColor); - DrawCubeWires(nearestHit.hitPosition, 0.3, 0.3, 0.3, RED); + DrawCube(nearestHit.position, 0.3, 0.3, 0.3, cursorColor); + DrawCubeWires(nearestHit.position, 0.3, 0.3, 0.3, RED); Vector3 normalEnd; - normalEnd.x = nearestHit.hitPosition.x + nearestHit.hitNormal.x; - normalEnd.y = nearestHit.hitPosition.y + nearestHit.hitNormal.y; - normalEnd.z = nearestHit.hitPosition.z + nearestHit.hitNormal.z; + normalEnd.x = nearestHit.position.x + nearestHit.normal.x; + normalEnd.y = nearestHit.position.y + nearestHit.normal.y; + normalEnd.z = nearestHit.position.z + nearestHit.normal.z; - DrawLine3D(nearestHit.hitPosition, normalEnd, RED); + DrawLine3D(nearestHit.position, normalEnd, RED); } DrawRay(ray, MAROON); @@ -163,14 +163,14 @@ int main() DrawText(FormatText("Distance: %3.2f", nearestHit.distance), 10, ypos, 10, BLACK); DrawText(FormatText("Hit Pos: %3.2f %3.2f %3.2f", - nearestHit.hitPosition.x, - nearestHit.hitPosition.y, - nearestHit.hitPosition.z), 10, ypos + 15, 10, BLACK); + nearestHit.position.x, + nearestHit.position.y, + nearestHit.position.z), 10, ypos + 15, 10, BLACK); DrawText(FormatText("Hit Norm: %3.2f %3.2f %3.2f", - nearestHit.hitNormal.x, - nearestHit.hitNormal.y, - nearestHit.hitNormal.z), 10, ypos + 30, 10, BLACK); + nearestHit.normal.x, + nearestHit.normal.y, + nearestHit.normal.z), 10, ypos + 30, 10, BLACK); if (hitTriangle) DrawText(FormatText("Barycenter: %3.2f %3.2f %3.2f", bary.x, bary.y, bary.z), 10, ypos + 45, 10, BLACK); } diff --git a/examples/src/models/models_obj_loading.c b/examples/src/models/models_obj_loading.c index 50d42d2..70f9216 100644 --- a/examples/src/models/models_obj_loading.c +++ b/examples/src/models/models_obj_loading.c @@ -25,7 +25,7 @@ int main() Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture - dwarf.material.texDiffuse = texture; // Set dwarf model diffuse texture + dwarf.material.maps[MAP_DIFFUSE].texture = texture; // Set map diffuse texture Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position SetTargetFPS(60); // Set our game to run at 60 frames-per-second diff --git a/examples/src/physac/physics_demo.c b/examples/src/physac/physics_demo.c index 5558836..1b54d51 100644 --- a/examples/src/physac/physics_demo.c +++ b/examples/src/physac/physics_demo.c @@ -28,7 +28,6 @@ int main() SetConfigFlags(FLAG_MSAA_4X_HINT); InitWindow(screenWidth, screenHeight, "Physac [raylib] - Physics demo"); - SetTargetFPS(60); // Physac logo drawing position int logoX = screenWidth - MeasureText("Physac", 30) - 10; @@ -44,6 +43,8 @@ int main() // Create obstacle circle physics body PhysicsBody circle = CreatePhysicsBodyCircle((Vector2){ screenWidth/2, screenHeight/2 }, 45, 10); circle->enabled = false; // Disable body state to convert it to static (no dynamics, but collisions) + + SetTargetFPS(60); //-------------------------------------------------------------------------------------- // Main game loop @@ -119,7 +120,8 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- - ClosePhysics(); // Uninitialize physics + ClosePhysics(); // Unitialize physics + CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- diff --git a/examples/src/physac/physics_friction.c b/examples/src/physac/physics_friction.c index 6ce1d40..9472729 100644 --- a/examples/src/physac/physics_friction.c +++ b/examples/src/physac/physics_friction.c @@ -28,7 +28,6 @@ int main() SetConfigFlags(FLAG_MSAA_4X_HINT); InitWindow(screenWidth, screenHeight, "Physac [raylib] - Physics friction"); - SetTargetFPS(60); // Physac logo drawing position int logoX = screenWidth - MeasureText("Physac", 30) - 10; @@ -63,6 +62,8 @@ int main() bodyB->staticFriction = 1; bodyB->dynamicFriction = 1; SetPhysicsBodyRotation(bodyB, 330*DEG2RAD); + + SetTargetFPS(60); //-------------------------------------------------------------------------------------- // Main game loop @@ -133,7 +134,7 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- - ClosePhysics(); // Uninitialize physics + ClosePhysics(); // Unitialize physics CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- diff --git a/examples/src/physac/physics_movement.c b/examples/src/physac/physics_movement.c index 534997b..4b2c9ab 100644 --- a/examples/src/physac/physics_movement.c +++ b/examples/src/physac/physics_movement.c @@ -30,7 +30,6 @@ int main() SetConfigFlags(FLAG_MSAA_4X_HINT); InitWindow(screenWidth, screenHeight, "Physac [raylib] - Physics movement"); - SetTargetFPS(60); // Physac logo drawing position int logoX = screenWidth - MeasureText("Physac", 30) - 10; @@ -56,6 +55,8 @@ int main() // Create movement physics body PhysicsBody body = CreatePhysicsBodyRectangle((Vector2){ screenWidth/2, screenHeight/2 }, 50, 50, 1); body->freezeOrient = true; // Constrain body rotation to avoid little collision torque amounts + + SetTargetFPS(60); //-------------------------------------------------------------------------------------- // Main game loop @@ -119,7 +120,7 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- - ClosePhysics(); // Uninitialize physics + ClosePhysics(); // Unitialize physics CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- diff --git a/examples/src/physac/physics_restitution.c b/examples/src/physac/physics_restitution.c index 0809697..2be8f42 100644 --- a/examples/src/physac/physics_restitution.c +++ b/examples/src/physac/physics_restitution.c @@ -28,7 +28,6 @@ int main() SetConfigFlags(FLAG_MSAA_4X_HINT); InitWindow(screenWidth, screenHeight, "Physac [raylib] - Physics restitution"); - SetTargetFPS(60); // Physac logo drawing position int logoX = screenWidth - MeasureText("Physac", 30) - 10; @@ -49,6 +48,8 @@ int main() circleB->restitution = 0.5f; PhysicsBody circleC = CreatePhysicsBodyCircle((Vector2){ screenWidth*0.75f, screenHeight/2 }, 30, 10); circleC->restitution = 1; + + SetTargetFPS(60); //-------------------------------------------------------------------------------------- // Main game loop @@ -112,7 +113,7 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- - ClosePhysics(); // Uninitialize physics + ClosePhysics(); // Unitialize physics CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- diff --git a/examples/src/physac/physics_shatter.c b/examples/src/physac/physics_shatter.c index b237bfc..6b474cd 100644 --- a/examples/src/physac/physics_shatter.c +++ b/examples/src/physac/physics_shatter.c @@ -28,7 +28,6 @@ int main() SetConfigFlags(FLAG_MSAA_4X_HINT); InitWindow(screenWidth, screenHeight, "Physac [raylib] - Body shatter"); - SetTargetFPS(60); // Physac logo drawing position int logoX = screenWidth - MeasureText("Physac", 30) - 10; @@ -40,6 +39,8 @@ int main() // Create random polygon physics body to shatter PhysicsBody body = CreatePhysicsBodyPolygon((Vector2){ screenWidth/2, screenHeight/2 }, GetRandomValue(80, 200), GetRandomValue(3, 8), 10); + + SetTargetFPS(60); //-------------------------------------------------------------------------------------- // Main game loop @@ -104,7 +105,7 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- - ClosePhysics(); // Uninitialize physics + ClosePhysics(); // Unitialize physics CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- diff --git a/examples/src/shaders/shaders_custom_uniform.c b/examples/src/shaders/shaders_custom_uniform.c index 89f87df..a0f6fd2 100644 --- a/examples/src/shaders/shaders_custom_uniform.c +++ b/examples/src/shaders/shaders_custom_uniform.c @@ -34,7 +34,7 @@ int main() Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture (diffuse map) - dwarf.material.texDiffuse = texture; // Set dwarf model diffuse texture + dwarf.material.maps[MAP_DIFFUSE].texture = texture; // Set dwarf model diffuse texture Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position diff --git a/examples/src/shaders/shaders_model_shader.c b/examples/src/shaders/shaders_model_shader.c index 51e9c1b..f1a349c 100644 --- a/examples/src/shaders/shaders_model_shader.c +++ b/examples/src/shaders/shaders_model_shader.c @@ -37,8 +37,8 @@ int main() Shader shader = LoadShader("resources/shaders/glsl330/base.vs", "resources/shaders/glsl330/grayscale.fs"); // Load model shader - dwarf.material.shader = shader; // Set shader effect to 3d model - dwarf.material.texDiffuse = texture; // Bind texture to model + dwarf.material.shader = shader; // Set shader effect to 3d model + dwarf.material.maps[MAP_DIFFUSE].texture = texture; // Bind texture to model Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position diff --git a/examples/src/shaders/shaders_postprocessing.c b/examples/src/shaders/shaders_postprocessing.c index bb239ef..4aac5f9 100644 --- a/examples/src/shaders/shaders_postprocessing.c +++ b/examples/src/shaders/shaders_postprocessing.c @@ -76,7 +76,7 @@ int main() Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture (diffuse map) - dwarf.material.texDiffuse = texture; // Set dwarf model diffuse texture + dwarf.material.maps[MAP_DIFFUSE].texture = texture; // Set dwarf model diffuse texture Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position diff --git a/examples/src/shaders/shaders_shapes_textures.c b/examples/src/shaders/shaders_shapes_textures.c index 40e99a8..e8c36a1 100644 --- a/examples/src/shaders/shaders_shapes_textures.c +++ b/examples/src/shaders/shaders_shapes_textures.c @@ -65,7 +65,7 @@ int main() DrawText("USING CUSTOM SHADER", 190, 40, 10, RED); DrawRectangle(250 - 60, 90, 120, 60, RED); - DrawRectangleGradient(250 - 90, 170, 180, 130, MAROON, GOLD); + DrawRectangleGradientH(250 - 90, 170, 180, 130, MAROON, GOLD); DrawRectangleLines(250 - 40, 320, 80, 60, ORANGE); // Activate our default shader for next drawings diff --git a/examples/src/shapes/shapes_basic_shapes.c b/examples/src/shapes/shapes_basic_shapes.c index 6b2719f..4b7cc26 100644 --- a/examples/src/shapes/shapes_basic_shapes.c +++ b/examples/src/shapes/shapes_basic_shapes.c @@ -46,7 +46,7 @@ int main() DrawCircleLines(screenWidth/4, 340, 80, DARKBLUE); DrawRectangle(screenWidth/4*2 - 60, 100, 120, 60, RED); - DrawRectangleGradient(screenWidth/4*2 - 90, 170, 180, 130, MAROON, GOLD); + DrawRectangleGradientH(screenWidth/4*2 - 90, 170, 180, 130, MAROON, GOLD); DrawRectangleLines(screenWidth/4*2 - 40, 320, 80, 60, ORANGE); DrawTriangle((Vector2){screenWidth/4*3, 80}, diff --git a/examples/src/textures/textures_image_drawing.c b/examples/src/textures/textures_image_drawing.c index 1c6a1fb..ac128af 100644 --- a/examples/src/textures/textures_image_drawing.c +++ b/examples/src/textures/textures_image_drawing.c @@ -36,6 +36,14 @@ int main() ImageCrop(&parrots, (Rectangle){ 0, 50, parrots.width, parrots.height - 100 }); // Crop resulting image UnloadImage(cat); // Unload image from RAM + + // Load custom font for frawing on image + SpriteFont font = LoadSpriteFont("resources/custom_jupiter_crash.png"); + + // Draw over image using custom font + ImageDrawTextEx(&parrots, (Vector2){ 300, 230 }, font, "PARROTS & CAT", font.baseSize, -2, WHITE); + + UnloadSpriteFont(font); // Unload custom spritefont (already drawn used on image) Texture2D texture = LoadTextureFromImage(parrots); // Image converted to texture, uploaded to GPU memory (VRAM) UnloadImage(parrots); // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM |
