Update examples

This commit is contained in:
Milan Nikolic 2017-10-26 19:03:17 +02:00
parent 2a0340eb70
commit ee66ee4d8e
14 changed files with 46 additions and 43 deletions

View file

@ -16,17 +16,19 @@ func main() {
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0)
camera.Fovy = 45.0
image := raylib.LoadImage("cubicmap.png") // Load cubicmap image (RAM)
cubic := raylib.LoadTextureFromImage(image) // Convert image to texture to display (VRAM)
cubicmap := raylib.LoadCubicmap(image) // Load cubicmap model (generate model from image)
image := raylib.LoadImage("cubicmap.png") // Load cubicmap image (RAM)
cubicmap := raylib.LoadTextureFromImage(image) // Convert image to texture to display (VRAM)
mesh := raylib.GenMeshCubicmap(*image, raylib.NewVector3(1.0, 1.0, 1.0))
model := raylib.LoadModelFromMesh(mesh)
// NOTE: By default each cube is mapped to one part of texture atlas
texture := raylib.LoadTexture("cubicmap_atlas.png") // Load map texture
cubicmap.Material.TexDiffuse = texture // Set map diffuse texture
texture := raylib.LoadTexture("cubicmap_atlas.png") // Load map texture
model.Material.Maps[raylib.MapDiffuse].Texture = texture // Set map diffuse texture
mapPosition := raylib.NewVector3(-16.0, 0.0, -8.0) // Set model position
raylib.UnloadImage(image) // Unload cubesmap image from RAM, already uploaded to VRAM
raylib.UnloadImage(image) // Unload cubicmap image from RAM, already uploaded to VRAM
raylib.SetCameraMode(camera, raylib.CameraOrbital) // Set an orbital camera mode
@ -45,12 +47,12 @@ func main() {
raylib.Begin3dMode(camera)
raylib.DrawModel(cubicmap, mapPosition, 1.0, raylib.White)
raylib.DrawModel(model, mapPosition, 1.0, raylib.White)
raylib.End3dMode()
raylib.DrawTextureEx(cubic, raylib.NewVector2(float32(screenWidth-cubic.Width*4-20), 20), 0.0, 4.0, raylib.White)
raylib.DrawRectangleLines(screenWidth-cubic.Width*4-20, 20, cubic.Width*4, cubic.Height*4, raylib.Green)
raylib.DrawTextureEx(cubicmap, raylib.NewVector2(float32(screenWidth-cubicmap.Width*4-20), 20), 0.0, 4.0, raylib.White)
raylib.DrawRectangleLines(screenWidth-cubicmap.Width*4-20, 20, cubicmap.Width*4, cubicmap.Height*4, raylib.Green)
raylib.DrawText("cubicmap image used to", 658, 90, 10, raylib.Gray)
raylib.DrawText("generate map 3d model", 658, 104, 10, raylib.Gray)
@ -60,9 +62,9 @@ func main() {
raylib.EndDrawing()
}
raylib.UnloadTexture(cubic) // Unload cubicmap texture
raylib.UnloadTexture(texture) // Unload map texture
raylib.UnloadModel(cubicmap) // Unload map model
raylib.UnloadTexture(cubicmap) // Unload cubicmap texture
raylib.UnloadTexture(texture) // Unload map texture
raylib.UnloadModel(model) // Unload map model
raylib.CloseWindow()
}

View file

@ -16,13 +16,16 @@ func main() {
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0)
camera.Fovy = 45.0
image := raylib.LoadImage("heightmap.png") // Load heightmap image (RAM)
texture := raylib.LoadTextureFromImage(image) // Convert image to texture (VRAM)
hmap := raylib.LoadHeightmap(image, raylib.NewVector3(16, 8, 16)) // Load heightmap model with defined size
hmap.Material.TexDiffuse = texture // Set map diffuse texture
mapPosition := raylib.NewVector3(-8.0, 0.0, -8.0) // Set model position
image := raylib.LoadImage("heightmap.png") // Load heightmap image (RAM)
texture := raylib.LoadTextureFromImage(image) // Convert image to texture (VRAM)
raylib.UnloadImage(image) // Unload cubesmap image from RAM, already uploaded to VRAM
mesh := raylib.GenMeshHeightmap(*image, raylib.NewVector3(16, 8, 16)) // Generate heightmap mesh (RAM and VRAM)
model := raylib.LoadModelFromMesh(mesh) // Load model from generated mesh
model.Material.Maps[raylib.MapDiffuse].Texture = texture // Set map diffuse texture
mapPosition := raylib.NewVector3(-8.0, 0.0, -8.0) // Set model position
raylib.UnloadImage(image) // Unload heightmap image from RAM, already uploaded to VRAM
raylib.SetCameraMode(camera, raylib.CameraOrbital) // Set an orbital camera mode
@ -41,8 +44,7 @@ func main() {
raylib.Begin3dMode(camera)
// NOTE: Model is scaled to 1/4 of its original size (128x128 units)
raylib.DrawModel(hmap, mapPosition, 1.0, raylib.Red)
raylib.DrawModel(model, mapPosition, 1.0, raylib.Red)
raylib.DrawGrid(20, 1.0)
@ -57,7 +59,7 @@ func main() {
}
raylib.UnloadTexture(texture) // Unload map texture
raylib.UnloadModel(hmap) // Unload map model
raylib.UnloadModel(model) // Unload map model
raylib.CloseWindow()
}

View file

@ -19,7 +19,7 @@ func main() {
dwarf := raylib.LoadModel("dwarf.obj") // Load OBJ model
texture := raylib.LoadTexture("dwarf_diffuse.png") // Load model texture
dwarf.Material.TexDiffuse = texture // Set dwarf model diffuse texture
dwarf.Material.Maps[raylib.MapDiffuse].Texture = texture // Set dwarf model diffuse texture
position := raylib.NewVector3(0.0, 0.0, 0.0) // Set model position