New materials system example

This commit is contained in:
Ray 2017-07-08 21:51:18 +02:00
parent 783c187ea8
commit a7c1850af1

View File

@ -11,6 +11,8 @@
#include "raylib.h" #include "raylib.h"
#include "raymath.h"
int main() int main()
{ {
// Initialization // Initialization
@ -25,11 +27,15 @@ int main()
Image image = LoadImage("resources/cubicmap.png"); // Load cubicmap image (RAM) Image image = LoadImage("resources/cubicmap.png"); // Load cubicmap image (RAM)
Texture2D cubicmap = LoadTextureFromImage(image); // Convert image to texture to display (VRAM) Texture2D cubicmap = LoadTextureFromImage(image); // Convert image to texture to display (VRAM)
Model map = LoadCubicmap(image); // Load cubicmap model (generate model from image)
Model model;
model.mesh = LoadMeshCubicmap(image); // Load cubicmap mesh (generated from image)
model.transform = MatrixIdentity(); // Set default transform matrix
model.material = LoadMaterialDefault(); // Load default material
// NOTE: By default each cube is mapped to one part of texture atlas // NOTE: By default each cube is mapped to one part of texture atlas
Texture2D texture = LoadTexture("resources/cubicmap_atlas.png"); // Load map texture Texture2D texture = LoadTexture("resources/cubicmap_atlas.png"); // Load map texture
map.material.texDiffuse = texture; // Set map diffuse texture model.material.maps[TEXMAP_DIFFUSE].tex = texture; // Set map diffuse texture
Vector3 mapPosition = { -16.0f, 0.0f, -8.0f }; // Set model position Vector3 mapPosition = { -16.0f, 0.0f, -8.0f }; // Set model position
@ -56,7 +62,7 @@ int main()
Begin3dMode(camera); Begin3dMode(camera);
DrawModel(map, mapPosition, 1.0f, WHITE); DrawModel(model, mapPosition, 1.0f, WHITE);
End3dMode(); End3dMode();
@ -76,7 +82,7 @@ int main()
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadTexture(cubicmap); // Unload cubicmap texture UnloadTexture(cubicmap); // Unload cubicmap texture
UnloadTexture(texture); // Unload map texture UnloadTexture(texture); // Unload map texture
UnloadModel(map); // Unload map model UnloadModel(model); // Unload map model
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------