Mercurial > games > semicongine
annotate README.md @ 1293:b94b648df33c
add: nicer string output for integer vecs
author | sam <sam@basx.dev> |
---|---|
date | Sun, 04 Aug 2024 20:50:38 +0700 |
parents | 9d6ce3c34c38 |
children | bf92a730c83a |
rev | line source |
---|---|
922 | 1 Note: If you are reading this on Github, please not that this is only a mirror |
1266 | 2 repository and the newest code is hosted on my mercurial repository at |
3 https://hg.basx.dev/games/semicongine/. | |
922 | 4 |
289 | 5 # Semicongine |
41 | 6 |
926
f8974736e446
did: smile, just for the sake of testing mercurial hooks :)
sam <sam@basx.dev>
parents:
925
diff
changeset
|
7 Hi there |
8 | 8 |
213
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
202
diff
changeset
|
9 This is a little game engine, mainly trying to wrap around vulkan and the |
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
202
diff
changeset
|
10 operating system's windowing, input and audio system. I am using the last |
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
202
diff
changeset
|
11 programming language you will ever need, [Nim](https://nim-lang.org/) |
41 | 12 |
1266 | 13 ## Features |
14 | |
15 The engine currently features the following: | |
16 | |
17 - No dependencies outside of this repo (except zip/unzip on Linux). All | |
1275 | 18 dependencies are included (`libs` for library dependencies, `tools` for |
19 binaries/scripts, `semicongine/thirdparty` for code dependencies) | |
1266 | 20 - Low-level, Vulkan-base rendering system |
1275 | 21 - All vertex/uniform/descriptors/shader-formats can and must be defined |
22 "freely". The only restriction that we currently have, is that vertex data is | |
23 non-interleaved. | |
1266 | 24 - A ton of compiletime checks to ensure the defined mesh-data and shaders are |
25 compatible for rendering | |
26 - Simple audio mixer, should suffice for most things | |
27 - Simple input-system, no controller support at this time | |
1275 | 28 - Resource packaging of images, audio and 3D files as either folders, zip files or embedded in the executable |
1267 | 29 - Simple font and text rendering |
1266 | 30 - A few additional utils like a simple storage API, a few algorithms for |
31 collision detection, noise generation and texture packing, and a simple | |
32 settings API with hot-reloading | |
33 | |
34 ## Hello world example | |
35 | |
36 Attention, this project is not optimized for "hello world"-scenarios, so you | |
37 have quite a few lines to get something to display: | |
38 | |
1269 | 39 ```nim |
1266 | 40 |
41 import semicongine | |
42 | |
43 # required | |
44 InitVulkan() | |
45 | |
46 # set up a simple render pass to render the displayed frame | |
47 var renderpass = CreateDirectPresentationRenderPass(depthBuffer = false, samples = VK_SAMPLE_COUNT_1_BIT) | |
48 | |
49 # the swapchain, needs to be attached to the main renderpass | |
50 SetupSwapchain(renderpass = renderpass) | |
51 | |
52 # render data is used for memory management on the GPU | |
53 var renderdata = InitRenderData() | |
54 | |
55 type | |
56 # define a push constant, to have something moving | |
57 PushConstant = object | |
58 scale: float32 | |
59 # This is how we define shaders: the interface needs to be "typed" | |
60 # but the shader code itself can freely be written in glsl | |
61 Shader = object | |
62 position {.VertexAttribute.}: Vec3f | |
63 color {.VertexAttribute.}: Vec3f | |
64 pushConstant {.PushConstantAttribute.}: PushConstant | |
65 fragmentColor {.Pass.}: Vec3f | |
66 outColor {.ShaderOutput.}: Vec4f | |
67 # code | |
68 vertexCode: string = """void main() { | |
69 fragmentColor = color; | |
70 gl_Position = vec4(position * pushConstant.scale, 1);}""" | |
71 fragmentCode: string = """void main() { | |
72 outColor = vec4(fragmentColor, 1);}""" | |
73 # And we also need to define our Mesh, which does describe the vertex layout | |
74 TriangleMesh = object | |
75 position: GPUArray[Vec3f, VertexBuffer] | |
76 color: GPUArray[Vec3f, VertexBuffer] | |
77 | |
78 # instantiate the mesh and fill with data | |
79 var mesh = TriangleMesh( | |
80 position: asGPUArray([NewVec3f(-0.5, -0.5), NewVec3f(0, 0.5), NewVec3f(0.5, -0.5)], VertexBuffer), | |
81 color: asGPUArray([NewVec3f(0, 0, 1), NewVec3f(0, 1, 0), NewVec3f(1, 0, 0)], VertexBuffer), | |
82 ) | |
83 | |
84 # this allocates GPU data, uploads the data to the GPU and flushes any thing that is host-cached | |
85 # this is a shortcut version, more fine-grained control is possible | |
86 AssignBuffers(renderdata, mesh) | |
87 renderdata.FlushAllMemory() | |
88 | |
89 # Now we need to instantiate the shader as a pipeline object that is attached to a renderpass | |
90 var pipeline = CreatePipeline[Shader](renderPass = vulkan.swapchain.renderPass) | |
91 | |
92 # the main render-loop will exit if we get a kill-signal from the OS | |
93 while UpdateInputs(): | |
94 | |
95 # starts the drawing for the next frame and provides us necesseary framebuffer and commandbuffer objects in this scope | |
96 WithNextFrame(framebuffer, commandbuffer): | |
97 | |
98 # start the main (and only) renderpass we have, needs to know the target framebuffer and a commandbuffer | |
99 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): | |
100 | |
101 # now activate our shader-pipeline | |
102 WithPipeline(commandbuffer, pipeline): | |
103 | |
104 # and finally, draw the mesh and set a single parameter | |
105 # more complicated setups with descriptors/uniforms are of course possible | |
106 RenderWithPushConstant(commandbuffer = commandbuffer, pipeline = pipeline, mesh = mesh, pushConstant = PushConstant(scale: 0.3)) | |
107 | |
108 # cleanup | |
109 checkVkResult vkDeviceWaitIdle(vulkan.device) | |
110 DestroyPipeline(pipeline) | |
111 DestroyRenderData(renderdata) | |
112 vkDestroyRenderPass(vulkan.device, renderpass.vk, nil) | |
113 DestroyVulkan() | |
114 | |
115 ``` | |
116 | |
1275 | 117 ## Future development |
41 | 118 |
1266 | 119 For now all features that I need are implemented. I will gradually add more |
120 stuff that I need, based on the games that I am developing. Here are a few | |
121 things that I consider integrating at a later point, once I have gather some | |
122 more experience what can/should be used across different projects: | |
194
93f661a20f74
did: a bit of cleanup with the config, also add some documentation
Sam <sam@basx.dev>
parents:
187
diff
changeset
|
123 |
1269 | 124 - [ ] More support for glTF format (JPEG textures, animations, morphing) |
1275 | 125 - [ ] Some often used utils like camera-controllers, offscreen-rendering, shadow-map rendering, etc. |
126 - [ ] Some UI-stuff | |
1269 | 127 - [ ] Controller support |