summaryrefslogtreecommitdiffhomepage
path: root/examples/web/models/models_heightmap.c
diff options
context:
space:
mode:
authorRay <[email protected]>2019-05-20 16:40:30 +0200
committerRay <[email protected]>2019-05-20 16:40:30 +0200
commit3d7d174c70b2d00fd879ade64c5085d4ff34d4aa (patch)
tree3b690948f186f855aa2ee8bab312b3ca28a56200 /examples/web/models/models_heightmap.c
parent0b56b996bd053ec875c229e9793f7806b666839c (diff)
downloadraylib.com-3d7d174c70b2d00fd879ade64c5085d4ff34d4aa.tar.gz
raylib.com-3d7d174c70b2d00fd879ade64c5085d4ff34d4aa.zip
Review and recompile ALL examples
Diffstat (limited to 'examples/web/models/models_heightmap.c')
-rw-r--r--examples/web/models/models_heightmap.c37
1 files changed, 18 insertions, 19 deletions
diff --git a/examples/web/models/models_heightmap.c b/examples/web/models/models_heightmap.c
index 009b50e..73ff4a3 100644
--- a/examples/web/models/models_heightmap.c
+++ b/examples/web/models/models_heightmap.c
@@ -18,16 +18,16 @@
//----------------------------------------------------------------------------------
// Global Variables Definition
//----------------------------------------------------------------------------------
-int screenWidth = 800;
-int screenHeight = 450;
+const int screenWidth = 800;
+const int screenHeight = 450;
// 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 };
-Texture2D texture;
-Model map;
+Texture2D texture = { 0 };
+Model model = { 0 };
-Vector3 mapPosition = { -8.0f, 0.0f, -8.0f }; // Set model position (depends on model scaling!)
+Vector3 mapPosition = { -8.0f, 0.0f, -8.0f }; // Set model position (depends on model scaling!)
//----------------------------------------------------------------------------------
// Module Functions Declaration
@@ -35,7 +35,7 @@ Vector3 mapPosition = { -8.0f, 0.0f, -8.0f }; // Set model position (depends on
void UpdateDrawFrame(void); // Update and Draw one frame
//----------------------------------------------------------------------------------
-// Main Enry Point
+// Program Main Entry Point
//----------------------------------------------------------------------------------
int main(void)
{
@@ -45,13 +45,13 @@ int main(void)
Image image = LoadImage("resources/heightmap.png"); // Load heightmap image (RAM)
texture = LoadTextureFromImage(image); // Convert image to texture (VRAM)
-
+
Mesh mesh = GenMeshHeightmap(image, (Vector3){ 16, 8, 16 }); // Generate heightmap mesh (RAM and VRAM)
- map = LoadModelFromMesh(mesh); // Load model from generated mesh
- map.material.maps[MAP_DIFFUSE].texture = texture; // Set map diffuse texture
-
+ model = LoadModelFromMesh(mesh); // Load model from generated mesh
+ model.materials[0].maps[MAP_DIFFUSE].texture = texture; // Set map diffuse texture
+
UnloadImage(image); // Unload heightmap image from RAM, already uploaded to VRAM
-
+
SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode
#if defined(PLATFORM_WEB)
@@ -59,7 +59,7 @@ int main(void)
#else
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
-
+
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
@@ -70,7 +70,7 @@ int main(void)
// De-Initialization
//--------------------------------------------------------------------------------------
UnloadTexture(texture); // Unload texture
- UnloadModel(map); // Unload model
+ UnloadModel(model); // Unload model
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
@@ -94,15 +94,14 @@ void UpdateDrawFrame(void)
ClearBackground(RAYWHITE);
- Begin3dMode(camera);
+ BeginMode3D(camera);
+
+ DrawModel(model, mapPosition, 1.0f, RED);
- // NOTE: Model is scaled to 1/4 of its original size (128x128 units)
- DrawModel(map, mapPosition, 1.0f, RED);
+ DrawGrid(20, 1.0f);
- DrawGrid(20, 1.0f);
+ EndMode3D();
- End3dMode();
-
DrawTexture(texture, screenWidth - texture.width - 20, 20, WHITE);
DrawRectangleLines(screenWidth - texture.width - 20, 20, texture.width, texture.height, GREEN);