Fix examples

This commit is contained in:
Milan Nikolic 2021-05-26 11:42:32 +02:00
parent c42d027833
commit ad07f2586d
No known key found for this signature in database
GPG key ID: 9229D0EAA3AA4E75
14 changed files with 5164 additions and 55024 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Before After
Before After

View file

@ -1,8 +1,6 @@
package main
import (
"fmt"
"github.com/gen2brain/raylib-go/raylib"
)
@ -17,20 +15,16 @@ func main() {
camera.Target = rl.NewVector3(0.0, 0.0, 0.0)
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
camera.Fovy = 45.0
camera.Type = rl.CameraPerspective
image := rl.LoadImage("cubicmap.png") // Load cubicmap image (RAM)
cubicmap := rl.LoadTextureFromImage(image) // Convert image to texture to display (VRAM)
mesh := rl.GenMeshCubicmap(*image, rl.NewVector3(1.0, 1.0, 1.0))
fmt.Printf("%+v\n", mesh)
model := rl.LoadModelFromMesh(mesh)
// NOTE: By default each cube is mapped to one part of texture atlas
texture := rl.LoadTexture("cubicmap_atlas.png") // Load map texture
model.Materials = make([]rl.Material, 1)
model.Materials[0].Maps[rl.MapDiffuse].Texture = texture // Set map diffuse texture
texture := rl.LoadTexture("cubicmap_atlas.png") // Load map texture
rl.SetMaterialTexture(model.Materials, rl.MapDiffuse, texture) // Set map diffuse texture
mapPosition := rl.NewVector3(-16.0, 0.0, -8.0) // Set model position

View file

@ -22,12 +22,11 @@ func main() {
texture := rl.LoadTextureFromImage(image) // Convert image to texture (VRAM)
mesh := rl.GenMeshHeightmap(*image, rl.NewVector3(16, 8, 16)) // Generate heightmap mesh (RAM and VRAM)
//fmt.Printf("%+v\n", mesh)
model := rl.LoadModelFromMesh(mesh) // Load model from generated mesh
//fmt.Printf("%+v\n", model)
model.Materials = make([]rl.Material, 1)
model.Materials[0].Maps[rl.MapDiffuse].Texture = texture // Set map diffuse texture
mapPosition := rl.NewVector3(-8.0, 0.0, -8.0) // Set model position
model := rl.LoadModelFromMesh(mesh) // Load model from generated mesh
rl.SetMaterialTexture(model.Materials, rl.MapDiffuse, texture) // Set map diffuse texture
mapPosition := rl.NewVector3(-8.0, 0.0, -8.0) // Set model position
rl.UnloadImage(image) // Unload heightmap image from RAM, already uploaded to VRAM

View file

@ -11,16 +11,16 @@ func main() {
rl.InitWindow(screenWidth, screenHeight, "raylib [models] example - obj model loading")
camera := rl.Camera{}
camera.Position = rl.NewVector3(3.0, 3.0, 3.0)
camera.Target = rl.NewVector3(0.0, 1.5, 0.0)
camera.Position = rl.NewVector3(50.0, 50.0, 50.0)
camera.Target = rl.NewVector3(0.0, 10.0, 0.0)
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
camera.Fovy = 45.0
camera.Type = rl.CameraPerspective
obj := rl.LoadModel("castle.obj") // Load OBJ model
texture := rl.LoadTexture("castle_diffuse.png") // Load model texture
obj.Materials = make([]rl.Material, 1)
obj.Materials[0].Maps[rl.MapDiffuse].Texture = texture // Set castle model diffuse texture
rl.SetMaterialTexture(obj.Materials, rl.MapDiffuse, texture) // Set map diffuse texture
position := rl.NewVector3(0.0, 0.0, 0.0) // Set model position
@ -33,9 +33,9 @@ func main() {
rl.BeginMode3D(camera)
rl.DrawModel(obj, position, 2.0, rl.White) // Draw 3d model with texture
rl.DrawModel(obj, position, 1.0, rl.White) // Draw 3d model with texture
rl.DrawGrid(10, 1.0) // Draw a grid
rl.DrawGrid(20, 10.0) // Draw a grid
rl.EndMode3D()