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 package main
import ( import (
"fmt"
"github.com/gen2brain/raylib-go/raylib" "github.com/gen2brain/raylib-go/raylib"
) )
@ -17,20 +15,16 @@ func main() {
camera.Target = rl.NewVector3(0.0, 0.0, 0.0) camera.Target = rl.NewVector3(0.0, 0.0, 0.0)
camera.Up = rl.NewVector3(0.0, 1.0, 0.0) camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
camera.Fovy = 45.0 camera.Fovy = 45.0
camera.Type = rl.CameraPerspective
image := rl.LoadImage("cubicmap.png") // Load cubicmap image (RAM) image := rl.LoadImage("cubicmap.png") // Load cubicmap image (RAM)
cubicmap := rl.LoadTextureFromImage(image) // Convert image to texture to display (VRAM) cubicmap := rl.LoadTextureFromImage(image) // Convert image to texture to display (VRAM)
mesh := rl.GenMeshCubicmap(*image, rl.NewVector3(1.0, 1.0, 1.0)) mesh := rl.GenMeshCubicmap(*image, rl.NewVector3(1.0, 1.0, 1.0))
fmt.Printf("%+v\n", mesh)
model := rl.LoadModelFromMesh(mesh) model := rl.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 := rl.LoadTexture("cubicmap_atlas.png") // Load map texture texture := rl.LoadTexture("cubicmap_atlas.png") // Load map texture
model.Materials = make([]rl.Material, 1) rl.SetMaterialTexture(model.Materials, rl.MapDiffuse, texture) // Set map diffuse texture
model.Materials[0].Maps[rl.MapDiffuse].Texture = texture // Set map diffuse texture
mapPosition := rl.NewVector3(-16.0, 0.0, -8.0) // Set model position 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) texture := rl.LoadTextureFromImage(image) // Convert image to texture (VRAM)
mesh := rl.GenMeshHeightmap(*image, rl.NewVector3(16, 8, 16)) // Generate heightmap mesh (RAM and 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
model := rl.LoadModelFromMesh(mesh) // Load model from generated mesh
//fmt.Printf("%+v\n", model) rl.SetMaterialTexture(model.Materials, rl.MapDiffuse, texture) // Set map diffuse texture
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
mapPosition := rl.NewVector3(-8.0, 0.0, -8.0) // Set model position
rl.UnloadImage(image) // Unload heightmap image from RAM, already uploaded to VRAM 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") rl.InitWindow(screenWidth, screenHeight, "raylib [models] example - obj model loading")
camera := rl.Camera{} camera := rl.Camera{}
camera.Position = rl.NewVector3(3.0, 3.0, 3.0) camera.Position = rl.NewVector3(50.0, 50.0, 50.0)
camera.Target = rl.NewVector3(0.0, 1.5, 0.0) camera.Target = rl.NewVector3(0.0, 10.0, 0.0)
camera.Up = rl.NewVector3(0.0, 1.0, 0.0) camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
camera.Fovy = 45.0 camera.Fovy = 45.0
camera.Type = rl.CameraPerspective
obj := rl.LoadModel("castle.obj") // Load OBJ model obj := rl.LoadModel("castle.obj") // Load OBJ model
texture := rl.LoadTexture("castle_diffuse.png") // Load model texture texture := rl.LoadTexture("castle_diffuse.png") // Load model texture
obj.Materials = make([]rl.Material, 1) rl.SetMaterialTexture(obj.Materials, rl.MapDiffuse, texture) // Set map diffuse texture
obj.Materials[0].Maps[rl.MapDiffuse].Texture = texture // Set castle model diffuse texture
position := rl.NewVector3(0.0, 0.0, 0.0) // Set model position position := rl.NewVector3(0.0, 0.0, 0.0) // Set model position
@ -33,9 +33,9 @@ func main() {
rl.BeginMode3D(camera) 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() rl.EndMode3D()

View file

@ -21,12 +21,11 @@ func main() {
dwarf := rl.LoadModel("dwarf.obj") // Load OBJ model dwarf := rl.LoadModel("dwarf.obj") // Load OBJ model
texture := rl.LoadTexture("dwarf_diffuse.png") // Load model texture texture := rl.LoadTexture("dwarf_diffuse.png") // Load model texture
dwarf.Materials = make([]rl.Material, 1) rl.SetMaterialTexture(dwarf.Materials, rl.MapDiffuse, texture) // Set dwarf model diffuse texture
dwarf.Materials[0].Maps[rl.MapDiffuse].Texture = texture // Set dwarf model diffuse texture
position := rl.NewVector3(0.0, 0.0, 0.0) // Set model position position := rl.NewVector3(0.0, 0.0, 0.0) // Set model position
shader := rl.LoadShader("glsl330/base.vs", "glsl330/swirl.fs") // Load postpro shader shader := rl.LoadShader("", "glsl330/swirl.fs")
// Get variable (uniform) location on the shader to connect with the program // Get variable (uniform) location on the shader to connect with the program
// NOTE: If uniform variable could not be found in the shader, function returns -1 // NOTE: If uniform variable could not be found in the shader, function returns -1
@ -53,7 +52,7 @@ func main() {
swirlCenter[1] = float32(screenHeight) - mousePosition.Y swirlCenter[1] = float32(screenHeight) - mousePosition.Y
// Send new value to the shader to be used on drawing // Send new value to the shader to be used on drawing
rl.SetShaderValue(shader, swirlCenterLoc, swirlCenter, 2) rl.SetShaderValue(shader, swirlCenterLoc, swirlCenter, 1)
rl.UpdateCamera(&camera) // Update camera rl.UpdateCamera(&camera) // Update camera

View file

@ -24,9 +24,8 @@ func main() {
texture := rl.LoadTexture("dwarf_diffuse.png") // Load model texture texture := rl.LoadTexture("dwarf_diffuse.png") // Load model texture
shader := rl.LoadShader("glsl330/base.vs", "glsl330/grayscale.fs") // Load model shader shader := rl.LoadShader("glsl330/base.vs", "glsl330/grayscale.fs") // Load model shader
dwarf.Materials = make([]rl.Material, 1) rl.SetMaterialTexture(dwarf.Materials, rl.MapDiffuse, texture)
dwarf.Materials[0].Shader = shader // Set shader effect to 3d model dwarf.Materials.Shader = shader // Set shader effect to 3d model
dwarf.Materials[0].Maps[rl.MapDiffuse].Texture = texture // Set dwarf model diffuse texture
position := rl.NewVector3(0.0, 0.0, 0.0) // Set model position position := rl.NewVector3(0.0, 0.0, 0.0) // Set model position

File diff suppressed because it is too large Load diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 350 KiB

File diff suppressed because it is too large Load diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

View file

@ -15,7 +15,7 @@ out vec4 finalColor;
const vec2 size = vec2(800, 450); // render size const vec2 size = vec2(800, 450); // render size
const float samples = 5.0; // pixels per axis; higher = bigger glow, worse performance const float samples = 5.0; // pixels per axis; higher = bigger glow, worse performance
const float quality = 2.5; // lower = smaller glow, better quality const float quality = 2.5; // lower = smaller glow, better quality
void main() void main()
{ {

View file

@ -31,4 +31,4 @@ void main()
color = color/9.5; color = color/9.5;
fragColor = color; fragColor = color;
} }

View file

@ -16,26 +16,26 @@ uniform vec2 resolution = vec2(800, 450);
void main() void main()
{ {
float x = 1.0/resolution.x; float x = 1.0/resolution.x;
float y = 1.0/resolution.y; float y = 1.0/resolution.y;
vec4 horizEdge = vec4(0.0); vec4 horizEdge = vec4(0.0);
horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0; horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0;
horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y ))*2.0; horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y ))*2.0;
horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0; horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0;
horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0; horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0;
horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y ))*2.0; horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y ))*2.0;
horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0; horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0;
vec4 vertEdge = vec4(0.0); vec4 vertEdge = vec4(0.0);
vertEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0; vertEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0;
vertEdge -= texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y - y))*2.0; vertEdge -= texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y - y))*2.0;
vertEdge -= texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0; vertEdge -= texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0;
vertEdge += texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0; vertEdge += texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0;
vertEdge += texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y + y))*2.0; vertEdge += texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y + y))*2.0;
vertEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0; vertEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0;
vec3 edge = sqrt((horizEdge.rgb*horizEdge.rgb) + (vertEdge.rgb*vertEdge.rgb)); vec3 edge = sqrt((horizEdge.rgb*horizEdge.rgb) + (vertEdge.rgb*vertEdge.rgb));
finalColor = vec4(edge, texture2D(texture0, fragTexCoord).a); finalColor = vec4(edge, texture2D(texture0, fragTexCoord).a);
} }

View file

@ -40,20 +40,19 @@ func main() {
screenWidth := int32(800) screenWidth := int32(800)
screenHeight := int32(450) screenHeight := int32(450)
rl.SetConfigFlags(rl.FlagMsaa4xHint | rl.FlagVsyncHint) // Enable Multi Sampling Anti Aliasing 4x (if available) rl.SetConfigFlags(rl.FlagMsaa4xHint) // Enable Multi Sampling Anti Aliasing 4x (if available)
rl.InitWindow(screenWidth, screenHeight, "raylib [shaders] example - postprocessing shader") rl.InitWindow(screenWidth, screenHeight, "raylib [shaders] example - postprocessing shader")
camera := rl.Camera{} camera := rl.Camera{}
camera.Position = rl.NewVector3(3.0, 3.0, 3.0) camera.Position = rl.NewVector3(2.0, 3.0, 2.0)
camera.Target = rl.NewVector3(0.0, 1.5, 0.0) camera.Target = rl.NewVector3(0.0, 1.0, 0.0)
camera.Up = rl.NewVector3(0.0, 1.0, 0.0) camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
camera.Fovy = 45.0 camera.Fovy = 45.0
dwarf := rl.LoadModel("dwarf.obj") // Load OBJ model obj := rl.LoadModel("church.obj") // Load OBJ model
texture := rl.LoadTexture("dwarf_diffuse.png") // Load model texture texture := rl.LoadTexture("church_diffuse.png") // Load model texture
dwarf.Materials = make([]rl.Material, 1) rl.SetMaterialTexture(obj.Materials, rl.MapDiffuse, texture) // Set obj model diffuse texture
dwarf.Materials[0].Maps[rl.MapDiffuse].Texture = texture // Set dwarf model diffuse texture
position := rl.NewVector3(0.0, 0.0, 0.0) // Set model position position := rl.NewVector3(0.0, 0.0, 0.0) // Set model position
@ -105,7 +104,7 @@ func main() {
rl.BeginMode3D(camera) rl.BeginMode3D(camera)
rl.DrawModel(dwarf, position, 2.0, rl.White) // Draw 3d model with texture rl.DrawModel(obj, position, 0.1, rl.White) // Draw 3d model with texture
rl.DrawGrid(10, 1.0) // Draw a grid rl.DrawGrid(10, 1.0) // Draw a grid
@ -123,7 +122,7 @@ func main() {
rl.DrawRectangle(0, 9, 580, 30, rl.Fade(rl.LightGray, 0.7)) rl.DrawRectangle(0, 9, 580, 30, rl.Fade(rl.LightGray, 0.7))
rl.DrawText("(c) Dwarf 3D model by David Moreno", screenWidth-200, screenHeight-20, 10, rl.DarkGray) rl.DrawText("(c) Church 3D model by Alberto Cano", screenWidth-200, screenHeight-20, 10, rl.DarkGray)
rl.DrawText("CURRENT POSTPRO SHADER:", 10, 15, 20, rl.Black) rl.DrawText("CURRENT POSTPRO SHADER:", 10, 15, 20, rl.Black)
rl.DrawText(postproShaderText[currentShader], 330, 15, 20, rl.Red) rl.DrawText(postproShaderText[currentShader], 330, 15, 20, rl.Red)
@ -140,7 +139,7 @@ func main() {
} }
rl.UnloadTexture(texture) // Unload texture rl.UnloadTexture(texture) // Unload texture
rl.UnloadModel(dwarf) // Unload model rl.UnloadModel(obj) // Unload model
rl.UnloadRenderTexture(target) // Unload render texture rl.UnloadRenderTexture(target) // Unload render texture
rl.CloseWindow() rl.CloseWindow()