mirror of
https://github.com/Not-Nik/raylib-zig.git
synced 2025-09-09 12:07:27 +00:00
Added heightmap example (#206)
* added heightmap example * better formatting
This commit is contained in:
parent
d3fdd327d5
commit
8e5ef1045d
10
build.zig
10
build.zig
@ -373,11 +373,11 @@ pub fn build(b: *std.Build) !void {
|
|||||||
.desc = "Image loading and texture creation",
|
.desc = "Image loading and texture creation",
|
||||||
},
|
},
|
||||||
|
|
||||||
// .{
|
.{
|
||||||
// .name = "models_loading",
|
.name = "models_heightmap",
|
||||||
// .path = "examples/models/models_loading.zig",
|
.path = "examples/models/models_heightmap.zig",
|
||||||
// .desc = "Loads a model and renders it",
|
.desc = "Heightmap loading and drawing",
|
||||||
// },
|
},
|
||||||
// .{
|
// .{
|
||||||
// .name = "shaders_basic_lighting",
|
// .name = "shaders_basic_lighting",
|
||||||
// .path = "examples/shaders/shaders_basic_lighting.zig",
|
// .path = "examples/shaders/shaders_basic_lighting.zig",
|
||||||
|
49
examples/models/models_heightmap.zig
Normal file
49
examples/models/models_heightmap.zig
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
const rl = @import("raylib");
|
||||||
|
|
||||||
|
pub fn main() anyerror!void {
|
||||||
|
const screenWidth: i32 = 800;
|
||||||
|
const screenHeight: i32 = 450;
|
||||||
|
|
||||||
|
rl.initWindow(screenWidth, screenHeight, "raylib [models] example - heightmap loading and drawing");
|
||||||
|
const cameraPosition: rl.Vector3 = .{ .x = 18, .y = 21, .z = 18 };
|
||||||
|
const cameraTarget: rl.Vector3 = .{ .x = 0, .y = 0, .z = 0 };
|
||||||
|
const cameraUp: rl.Vector3 = .{ .x = 0, .y = 1, .z = 0 };
|
||||||
|
const cameraProjection = rl.CameraProjection.perspective;
|
||||||
|
var camera = rl.Camera{ .fovy = 45.0, .position = cameraPosition, .up = cameraUp, .projection = cameraProjection, .target = cameraTarget };
|
||||||
|
|
||||||
|
const image: rl.Image = try rl.loadImage("examples/models/resources/heightmap.png");
|
||||||
|
|
||||||
|
const texture: rl.Texture2D = try rl.loadTextureFromImage(image);
|
||||||
|
|
||||||
|
const meshSize = rl.Vector3{ .x = 16, .y = 8, .z = 16 };
|
||||||
|
const mesh = rl.genMeshHeightmap(image, meshSize);
|
||||||
|
|
||||||
|
var model = try rl.loadModelFromMesh(mesh);
|
||||||
|
model.materials[0].maps[@intFromEnum(rl.MATERIAL_MAP_DIFFUSE)].texture = texture;
|
||||||
|
|
||||||
|
const mapPosition = rl.Vector3{ .x = -8.0, .y = 0.0, .z = -8.0 };
|
||||||
|
|
||||||
|
rl.unloadImage(image);
|
||||||
|
|
||||||
|
rl.setTargetFPS(60);
|
||||||
|
|
||||||
|
while (!rl.windowShouldClose()) {
|
||||||
|
rl.updateCamera(&camera, rl.CameraMode.orbital);
|
||||||
|
rl.beginDrawing();
|
||||||
|
|
||||||
|
rl.clearBackground(rl.Color.ray_white);
|
||||||
|
rl.beginMode3D(camera);
|
||||||
|
rl.drawModel(model, mapPosition, 1, rl.Color.red);
|
||||||
|
rl.drawGrid(20, 1.0);
|
||||||
|
rl.endMode3D();
|
||||||
|
rl.drawTexture(texture, screenWidth - texture.width - 20, 20, rl.Color.white);
|
||||||
|
rl.drawRectangleLines(screenWidth - texture.width - 20, 20, texture.width, texture.height, rl.Color.green);
|
||||||
|
rl.drawFPS(10, 10);
|
||||||
|
|
||||||
|
rl.endDrawing();
|
||||||
|
}
|
||||||
|
rl.unloadTexture(texture);
|
||||||
|
rl.unloadModel(model);
|
||||||
|
|
||||||
|
rl.closeWindow();
|
||||||
|
}
|
BIN
examples/models/resources/heightmap.png
Normal file
BIN
examples/models/resources/heightmap.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
Loading…
x
Reference in New Issue
Block a user