Update examples
This commit is contained in:
parent
2a0340eb70
commit
ee66ee4d8e
14 changed files with 46 additions and 43 deletions
|
@ -13,7 +13,7 @@ func main() {
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [core] example - vr simulator")
|
raylib.InitWindow(screenWidth, screenHeight, "raylib [core] example - vr simulator")
|
||||||
|
|
||||||
// NOTE: default device (simulator)
|
// NOTE: default device (simulator)
|
||||||
raylib.InitVrSimulator(raylib.HmdOculusRiftCv1) // Init VR device (Oculus Rift CV1)
|
raylib.InitVrSimulator(raylib.GetVrDeviceInfo(raylib.HmdOculusRiftCv1)) // Init VR device (Oculus Rift CV1)
|
||||||
|
|
||||||
camera := raylib.Camera{}
|
camera := raylib.Camera{}
|
||||||
camera.Position = raylib.NewVector3(5.0, 2.0, 5.0) // Camera position
|
camera.Position = raylib.NewVector3(5.0, 2.0, 5.0) // Camera position
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
## Floppy Gopher
|
## Floppy Gopher
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
[Android apk](https://gist.github.com/gen2brain/ae96bc92d2c2e307af35f5583f30ea25/raw/cd771b86ef6c4b03a2c5957fa2a097ee8a3bcbb4/floppy-gopher.apk)
|
|
||||||
|
|
|
@ -16,17 +16,19 @@ func main() {
|
||||||
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0)
|
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0)
|
||||||
camera.Fovy = 45.0
|
camera.Fovy = 45.0
|
||||||
|
|
||||||
image := raylib.LoadImage("cubicmap.png") // Load cubicmap image (RAM)
|
image := raylib.LoadImage("cubicmap.png") // Load cubicmap image (RAM)
|
||||||
cubic := raylib.LoadTextureFromImage(image) // Convert image to texture to display (VRAM)
|
cubicmap := raylib.LoadTextureFromImage(image) // Convert image to texture to display (VRAM)
|
||||||
cubicmap := raylib.LoadCubicmap(image) // Load cubicmap model (generate model from image)
|
|
||||||
|
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
|
// NOTE: By default each cube is mapped to one part of texture atlas
|
||||||
texture := raylib.LoadTexture("cubicmap_atlas.png") // Load map texture
|
texture := raylib.LoadTexture("cubicmap_atlas.png") // Load map texture
|
||||||
cubicmap.Material.TexDiffuse = texture // Set map diffuse texture
|
model.Material.Maps[raylib.MapDiffuse].Texture = texture // Set map diffuse texture
|
||||||
|
|
||||||
mapPosition := raylib.NewVector3(-16.0, 0.0, -8.0) // Set model position
|
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
|
raylib.SetCameraMode(camera, raylib.CameraOrbital) // Set an orbital camera mode
|
||||||
|
|
||||||
|
@ -45,12 +47,12 @@ func main() {
|
||||||
|
|
||||||
raylib.Begin3dMode(camera)
|
raylib.Begin3dMode(camera)
|
||||||
|
|
||||||
raylib.DrawModel(cubicmap, mapPosition, 1.0, raylib.White)
|
raylib.DrawModel(model, mapPosition, 1.0, raylib.White)
|
||||||
|
|
||||||
raylib.End3dMode()
|
raylib.End3dMode()
|
||||||
|
|
||||||
raylib.DrawTextureEx(cubic, raylib.NewVector2(float32(screenWidth-cubic.Width*4-20), 20), 0.0, 4.0, raylib.White)
|
raylib.DrawTextureEx(cubicmap, raylib.NewVector2(float32(screenWidth-cubicmap.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.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("cubicmap image used to", 658, 90, 10, raylib.Gray)
|
||||||
raylib.DrawText("generate map 3d model", 658, 104, 10, raylib.Gray)
|
raylib.DrawText("generate map 3d model", 658, 104, 10, raylib.Gray)
|
||||||
|
@ -60,9 +62,9 @@ func main() {
|
||||||
raylib.EndDrawing()
|
raylib.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.UnloadTexture(cubic) // Unload cubicmap texture
|
raylib.UnloadTexture(cubicmap) // Unload cubicmap texture
|
||||||
raylib.UnloadTexture(texture) // Unload map texture
|
raylib.UnloadTexture(texture) // Unload map texture
|
||||||
raylib.UnloadModel(cubicmap) // Unload map model
|
raylib.UnloadModel(model) // Unload map model
|
||||||
|
|
||||||
raylib.CloseWindow()
|
raylib.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,13 +16,16 @@ func main() {
|
||||||
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0)
|
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0)
|
||||||
camera.Fovy = 45.0
|
camera.Fovy = 45.0
|
||||||
|
|
||||||
image := raylib.LoadImage("heightmap.png") // Load heightmap image (RAM)
|
image := raylib.LoadImage("heightmap.png") // Load heightmap image (RAM)
|
||||||
texture := raylib.LoadTextureFromImage(image) // Convert image to texture (VRAM)
|
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
|
|
||||||
|
|
||||||
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
|
raylib.SetCameraMode(camera, raylib.CameraOrbital) // Set an orbital camera mode
|
||||||
|
|
||||||
|
@ -41,8 +44,7 @@ func main() {
|
||||||
|
|
||||||
raylib.Begin3dMode(camera)
|
raylib.Begin3dMode(camera)
|
||||||
|
|
||||||
// NOTE: Model is scaled to 1/4 of its original size (128x128 units)
|
raylib.DrawModel(model, mapPosition, 1.0, raylib.Red)
|
||||||
raylib.DrawModel(hmap, mapPosition, 1.0, raylib.Red)
|
|
||||||
|
|
||||||
raylib.DrawGrid(20, 1.0)
|
raylib.DrawGrid(20, 1.0)
|
||||||
|
|
||||||
|
@ -57,7 +59,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.UnloadTexture(texture) // Unload map texture
|
raylib.UnloadTexture(texture) // Unload map texture
|
||||||
raylib.UnloadModel(hmap) // Unload map model
|
raylib.UnloadModel(model) // Unload map model
|
||||||
|
|
||||||
raylib.CloseWindow()
|
raylib.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ func main() {
|
||||||
dwarf := raylib.LoadModel("dwarf.obj") // Load OBJ model
|
dwarf := raylib.LoadModel("dwarf.obj") // Load OBJ model
|
||||||
texture := raylib.LoadTexture("dwarf_diffuse.png") // Load model texture
|
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
|
position := raylib.NewVector3(0.0, 0.0, 0.0) // Set model position
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ in vec3 vertexNormal;
|
||||||
in vec4 vertexColor;
|
in vec4 vertexColor;
|
||||||
|
|
||||||
// Input uniform values
|
// Input uniform values
|
||||||
uniform mat4 mvpMatrix;
|
uniform mat4 mvp;
|
||||||
|
|
||||||
// Output vertex attributes (to fragment shader)
|
// Output vertex attributes (to fragment shader)
|
||||||
out vec2 fragTexCoord;
|
out vec2 fragTexCoord;
|
||||||
|
@ -22,5 +22,5 @@ void main()
|
||||||
fragColor = vertexColor;
|
fragColor = vertexColor;
|
||||||
|
|
||||||
// Calculate final vertex position
|
// Calculate final vertex position
|
||||||
gl_Position = mvpMatrix*vec4(vertexPosition, 1.0);
|
gl_Position = mvp*vec4(vertexPosition, 1.0);
|
||||||
}
|
}
|
|
@ -21,7 +21,7 @@ func main() {
|
||||||
dwarf := raylib.LoadModel("dwarf.obj") // Load OBJ model
|
dwarf := raylib.LoadModel("dwarf.obj") // Load OBJ model
|
||||||
texture := raylib.LoadTexture("dwarf_diffuse.png") // Load model texture
|
texture := raylib.LoadTexture("dwarf_diffuse.png") // Load model texture
|
||||||
|
|
||||||
dwarf.Material.TexDiffuse = texture // Bind texture to model
|
dwarf.Material.Maps[raylib.MapDiffuse].Texture = texture // Set dwarf model diffuse texture
|
||||||
|
|
||||||
position := raylib.NewVector3(0.0, 0.0, 0.0) // Set model position
|
position := raylib.NewVector3(0.0, 0.0, 0.0) // Set model position
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ in vec3 vertexNormal;
|
||||||
in vec4 vertexColor;
|
in vec4 vertexColor;
|
||||||
|
|
||||||
// Input uniform values
|
// Input uniform values
|
||||||
uniform mat4 mvpMatrix;
|
uniform mat4 mvp;
|
||||||
|
|
||||||
// Output vertex attributes (to fragment shader)
|
// Output vertex attributes (to fragment shader)
|
||||||
out vec2 fragTexCoord;
|
out vec2 fragTexCoord;
|
||||||
|
@ -22,5 +22,5 @@ void main()
|
||||||
fragColor = vertexColor;
|
fragColor = vertexColor;
|
||||||
|
|
||||||
// Calculate final vertex position
|
// Calculate final vertex position
|
||||||
gl_Position = mvpMatrix*vec4(vertexPosition, 1.0);
|
gl_Position = mvp*vec4(vertexPosition, 1.0);
|
||||||
}
|
}
|
|
@ -24,8 +24,8 @@ func main() {
|
||||||
texture := raylib.LoadTexture("dwarf_diffuse.png") // Load model texture
|
texture := raylib.LoadTexture("dwarf_diffuse.png") // Load model texture
|
||||||
shader := raylib.LoadShader("glsl330/base.vs", "glsl330/grayscale.fs") // Load model shader
|
shader := raylib.LoadShader("glsl330/base.vs", "glsl330/grayscale.fs") // Load model shader
|
||||||
|
|
||||||
dwarf.Material.Shader = shader // Set shader effect to 3d model
|
dwarf.Material.Shader = shader // Set shader effect to 3d model
|
||||||
dwarf.Material.TexDiffuse = texture // Bind texture to model
|
dwarf.Material.Maps[raylib.MapDiffuse].Texture = texture // Set dwarf model diffuse texture
|
||||||
|
|
||||||
position := raylib.NewVector3(0.0, 0.0, 0.0) // Set model position
|
position := raylib.NewVector3(0.0, 0.0, 0.0) // Set model position
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ in vec3 vertexNormal;
|
||||||
in vec4 vertexColor;
|
in vec4 vertexColor;
|
||||||
|
|
||||||
// Input uniform values
|
// Input uniform values
|
||||||
uniform mat4 mvpMatrix;
|
uniform mat4 mvp;
|
||||||
|
|
||||||
// Output vertex attributes (to fragment shader)
|
// Output vertex attributes (to fragment shader)
|
||||||
out vec2 fragTexCoord;
|
out vec2 fragTexCoord;
|
||||||
|
@ -22,5 +22,5 @@ void main()
|
||||||
fragColor = vertexColor;
|
fragColor = vertexColor;
|
||||||
|
|
||||||
// Calculate final vertex position
|
// Calculate final vertex position
|
||||||
gl_Position = mvpMatrix*vec4(vertexPosition, 1.0);
|
gl_Position = mvp*vec4(vertexPosition, 1.0);
|
||||||
}
|
}
|
|
@ -20,7 +20,8 @@ func main() {
|
||||||
|
|
||||||
dwarf := raylib.LoadModel("dwarf.obj") // Load OBJ model
|
dwarf := raylib.LoadModel("dwarf.obj") // Load OBJ model
|
||||||
texture := raylib.LoadTexture("dwarf_diffuse.png") // Load model texture
|
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
|
position := raylib.NewVector3(0.0, 0.0, 0.0) // Set model position
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ in vec3 vertexNormal;
|
||||||
in vec4 vertexColor;
|
in vec4 vertexColor;
|
||||||
|
|
||||||
// Input uniform values
|
// Input uniform values
|
||||||
uniform mat4 mvpMatrix;
|
uniform mat4 mvp;
|
||||||
|
|
||||||
// Output vertex attributes (to fragment shader)
|
// Output vertex attributes (to fragment shader)
|
||||||
out vec2 fragTexCoord;
|
out vec2 fragTexCoord;
|
||||||
|
@ -22,5 +22,5 @@ void main()
|
||||||
fragColor = vertexColor;
|
fragColor = vertexColor;
|
||||||
|
|
||||||
// Calculate final vertex position
|
// Calculate final vertex position
|
||||||
gl_Position = mvpMatrix*vec4(vertexPosition, 1.0);
|
gl_Position = mvp*vec4(vertexPosition, 1.0);
|
||||||
}
|
}
|
|
@ -36,7 +36,7 @@ func main() {
|
||||||
raylib.DrawText("USING CUSTOM SHADER", 190, 40, 10, raylib.Red)
|
raylib.DrawText("USING CUSTOM SHADER", 190, 40, 10, raylib.Red)
|
||||||
|
|
||||||
raylib.DrawRectangle(250-60, 90, 120, 60, raylib.Red)
|
raylib.DrawRectangle(250-60, 90, 120, 60, raylib.Red)
|
||||||
raylib.DrawRectangleGradient(250-90, 170, 180, 130, raylib.Maroon, raylib.Gold)
|
raylib.DrawRectangleGradientH(250-90, 170, 180, 130, raylib.Maroon, raylib.Gold)
|
||||||
raylib.DrawRectangleLines(250-40, 320, 80, 60, raylib.Orange)
|
raylib.DrawRectangleLines(250-40, 320, 80, 60, raylib.Orange)
|
||||||
|
|
||||||
// Activate our default shader for next drawings
|
// Activate our default shader for next drawings
|
||||||
|
|
|
@ -25,7 +25,7 @@ func main() {
|
||||||
raylib.DrawCircleLines(screenWidth/4, 340, 80, raylib.DarkBlue)
|
raylib.DrawCircleLines(screenWidth/4, 340, 80, raylib.DarkBlue)
|
||||||
|
|
||||||
raylib.DrawRectangle(screenWidth/4*2-60, 100, 120, 60, raylib.Red)
|
raylib.DrawRectangle(screenWidth/4*2-60, 100, 120, 60, raylib.Red)
|
||||||
raylib.DrawRectangleGradient(screenWidth/4*2-90, 170, 180, 130, raylib.Maroon, raylib.Gold)
|
raylib.DrawRectangleGradientH(screenWidth/4*2-90, 170, 180, 130, raylib.Maroon, raylib.Gold)
|
||||||
raylib.DrawRectangleLines(screenWidth/4*2-40, 320, 80, 60, raylib.Orange)
|
raylib.DrawRectangleLines(screenWidth/4*2-40, 320, 80, 60, raylib.Orange)
|
||||||
|
|
||||||
raylib.DrawTriangle(raylib.NewVector2(float32(screenWidth)/4*3, 80),
|
raylib.DrawTriangle(raylib.NewVector2(float32(screenWidth)/4*3, 80),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue