• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

zenith391/didot: Zig 3D game engine.

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

zenith391/didot

开源软件地址:

https://github.com/zenith391/didot

开源编程语言:

Zig 99.5%

开源软件介绍:

Didot

A Zig 3D game engine.


Demo featuring skybox, karts, grass and a cube

Introduction

Didot is a multi-threaded 3D game engine programmed in Zig and aimed at high-level constructs: you manipulate game objects and meshes instead of OpenGL calls and batches.

It improves developers life by splitting the engine into multiple modules in order to have easier porting to other platforms. For example, you can change the windowing module from didot-glfw to didot-x11 to use Xlib instead of depending on GLFW without any change to your game's code, as porting (except for shaders) is transparent to the developer's code.

Installation

Prerequisites:

  • Zig compiler (master branch, didot is currently tested with commit 0aef1fa)

You only need to launch your terminal and execute those commands in an empty directory:

git clone https://github.com/zenith391/didot
zig init-exe

And then, change the resulting build.zig file looks like this:

const didot = @import("didot/build.zig");
const Builder = @import("std").build.Builder;

pub fn build(b: *Builder) void {
    // ...
    exe.setBuildMode(mode);
    try didot.addEngineToExe(exe, .{
        .prefix = "didot/"
    });
    exe.install();
    // ...
}

Using Didot

Showing a cube:

const std = @import("std");
const zlm = @import("zlm");
usingnamespace @import("didot-graphics");
usingnamespace @import("didot-objects");
usingnamespace @import("didot-app");

const Vec3 = zlm.Vec3;
const Allocator = std.mem.Allocator;

fn init(allocator: *Allocator, app: *Application) !void {
    var shader = try ShaderProgram.create(@embedFile("vert.glsl"), @embedFile("frag.glsl"));

    var camera = try GameObject.createObject(allocator, null);
    camera.getComponent(Transform).?.* = .{
        .position = Vec3.new(1.5, 1.5, -0.5),
        .rotation = Vec3.new(-120.0, -15.0, 0).toRadians()
    };
    try camera.addComponent(Camera { .shader = shader });
    try app.scene.add(camera);
    
    var cube = try GameObject.createObject(allocator, "Mesh/Cube");
    cube.getComponent(Transform).?.position = Vec3.new(-1.2, 0.75, -3);
    try app.scene.add(cube);
}

pub fn main() !void {
    var gp = std.heap.GeneralPurposeAllocator(.{}) {};
    const allocator = &gp.allocator;

    var scene = try Scene.create(allocator, null);
    comptime var systems = Systems {};
    var app = Application(systems) {
        .title = "Test Cube",
        .initFn = init
    };
    try app.run(allocator, scene);
}

And to make that into a textured cube, only a few lines are necessary:

try scene.assetManager.put("Texture/Grass", try TextureAsset.init2D(allocator, "assets/textures/grass.png", "png"));
var material = Material { .texturePath = "Texture/Grass" };
cube.material = material;

First line loads assets/textures/grass.png to Texture/Grass.
Second line creates a Material with the Texture/Grass texture.
Third line links the cube to the newly created Material.

You can also look at the example to see how to make camera movement or load models from OBJ files or even load scenes from JSON files.

Systems (currently):

fn exampleSystem(query: Query(.{*Transform})) !void {
    var iterator = query.iterator();
    while (iterator.next()) |o| {
        std.log.info("Someone's at position {} !", .{o.transform.position});
    }
}

pub fn main() !void {
    // ...
    comptime var systems = Systems {};
    systems.addSystem(exampleSystem);
    var app = Application(systems) {
        .title = "Test Cube",
        .initFn = init
    };
    try app.run(allocator, scene);
}

API reference

Features

  • Scene editor
  • Assets manager
  • OpenGL backend
    • Shaders
    • Meshes
    • Materials
    • Textures
  • Windowing
    • GLFW backend
    • X11 backend
  • Model loader
    • OBJ files
  • Image loader
    • BMP files
    • PNG files
  • Application system for easier use
  • Game objects system



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
n-paukov/swengine: StarWind Game Engine发布时间:2022-06-08
下一篇:
qiciengine/qiciengine-cookbook: QICI Engine Game Development Cookbook发布时间:2022-06-08
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap