add more examples
This commit is contained in:
parent
032749cff8
commit
1500124ca1
4 changed files with 267 additions and 0 deletions
BIN
examples/shaders/texture_tiling/cubicmap_atlas.png
Normal file
BIN
examples/shaders/texture_tiling/cubicmap_atlas.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 36 KiB |
65
examples/shaders/texture_tiling/main.go
Normal file
65
examples/shaders/texture_tiling/main.go
Normal file
|
@ -0,0 +1,65 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [shaders] example - texture tiling")
|
||||
|
||||
cam := rl.Camera3D{}
|
||||
cam.Position = rl.NewVector3(4, 4, 4)
|
||||
cam.Target = rl.NewVector3(0, 0.5, 0)
|
||||
cam.Up = rl.NewVector3(0, 1, 0)
|
||||
cam.Fovy = 45
|
||||
cam.Projection = rl.CameraPerspective
|
||||
|
||||
cube := rl.GenMeshCube(1, 1, 1)
|
||||
model := rl.LoadModelFromMesh(cube)
|
||||
|
||||
texture := rl.LoadTexture("cubicmap_atlas.png")
|
||||
rl.SetMaterialTexture(model.Materials, rl.MapDiffuse, texture)
|
||||
|
||||
tiling := []float32{3, 3}
|
||||
shader := rl.LoadShader("", "tiling.fs")
|
||||
rl.SetShaderValue(shader, rl.GetShaderLocation(shader, "tiling"), tiling, rl.ShaderUniformVec2)
|
||||
model.Materials.Shader = shader
|
||||
|
||||
rl.DisableCursor()
|
||||
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !rl.WindowShouldClose() {
|
||||
|
||||
rl.UpdateCamera(&cam, rl.CameraOrbital)
|
||||
|
||||
if rl.IsKeyPressed(rl.KeyZ) {
|
||||
cam.Target = rl.NewVector3(0, 0.5, 0)
|
||||
}
|
||||
|
||||
rl.BeginDrawing()
|
||||
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
rl.BeginMode3D(cam)
|
||||
|
||||
rl.BeginShaderMode(shader)
|
||||
rl.DrawModel(model, rl.Vector3Zero(), 2, rl.White)
|
||||
rl.EndShaderMode()
|
||||
|
||||
rl.DrawGrid(10, 1)
|
||||
|
||||
rl.EndMode3D()
|
||||
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
rl.UnloadShader(shader)
|
||||
rl.UnloadModel(model)
|
||||
rl.UnloadTexture(texture)
|
||||
|
||||
rl.CloseWindow()
|
||||
}
|
14
examples/shaders/texture_tiling/tiling.fs
Normal file
14
examples/shaders/texture_tiling/tiling.fs
Normal file
|
@ -0,0 +1,14 @@
|
|||
#version 330 core
|
||||
|
||||
uniform sampler2D diffuseMap;
|
||||
uniform vec2 tiling;
|
||||
|
||||
in vec2 fragTexCoord;
|
||||
|
||||
out vec4 fragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 texCoord = fragTexCoord * tiling;
|
||||
fragColor = texture(diffuseMap, texCoord);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue