Skip to content

Commit 80b348b

Browse files
authored
VXR release 0.1.1 - Improved Documentation
1 parent cbb8a9f commit 80b348b

File tree

1 file changed

+78
-89
lines changed

1 file changed

+78
-89
lines changed

README.md

Lines changed: 78 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[![vxr engine logo](/assets/textures/readme/logo.png)](https://avilapa.github.io)
22

3-
_version 0.1.0_
3+
_version 0.1.1_
44

55
# What is [vxr](https://github.com/avilapa/vxr)?
66

@@ -17,6 +17,8 @@ Project webpage: https://avilapa.github.io/vxr-engine/
1717

1818
# Building
1919

20+
_[A vs2017 + opengl Solution is provided by default]_
21+
2022
This project uses [GENie.lua](https://github.com/bkaradzic/GENie) to create the project solution. From for example [babun](http://babun.github.io/) you will have to execute the following commands:
2123

2224
cd project
@@ -60,9 +62,69 @@ A list of examples are provided within the solution to showcase the engine's cap
6062

6163
# API Reference
6264

65+
66+
### Higher Level API
67+
68+
```c++
69+
// 0. Define the entry point.
70+
VXR_DEFINE_APP_MAIN(vxr::Main)
71+
72+
namespace vxr
73+
{
74+
75+
Main::Main()
76+
{
77+
// 1. Initialize GPU and Window parameters.
78+
Params p;
79+
p.gpu = { 100, 100, 100, 100 };
80+
p.window = { { 1920, 1080} };
81+
Engine::ref().set_preinit_params(p);
82+
}
83+
84+
void Main::start()
85+
{
86+
// 2. Create a camera.
87+
cam_.alloc()->set_name("Camera");
88+
cam_->addComponent<Camera>()->transform()->set_local_position(vec3(0,0,4));
89+
90+
// 3. Load the Teapot mesh and set an initial rotation.
91+
mesh_ = Asset::loadModelOBJ("../../assets/meshes/obj/teapot_mesh.obj");
92+
mesh_->set_name("Teapot");
93+
mesh_->transform()->set_local_rotation(vec3(glm::radians(90.0f), 0.0f, 0.0f));
94+
95+
// 4. Create a Scene, parent the objects and load.
96+
ref_ptr<Scene> scene_;
97+
scene_.alloc();
98+
99+
scene_->addObject(cam_);
100+
scene_->addObject(mesh_);
101+
102+
Engine::ref().loadScene(scene_);
103+
104+
// 5. Submit the UI function.
105+
Engine::ref().submitUIFunction([this]() { ui::Editor(); });
106+
107+
Application::start();
108+
}
109+
110+
void Main::update()
111+
{
112+
// 6. Rotate the mesh in update() instead of renderUpdate() to make the rotation framerate independent
113+
// by multiplying it by deltaTime(). The update() method may be executed several times in a frame to
114+
// catch up with the render thread.
115+
mesh_->transform()->set_local_rotation(mesh_->transform()->local_rotation()
116+
+ vec3(0.21, 0.12, 0.5) * deltaTime());
117+
118+
Application::update();
119+
}
120+
121+
} /* end of vxr namespace */
122+
```
123+
63124
### Lower Level API
64125
65126
```c++
127+
// 0. Define the entry point.
66128
VXR_DEFINE_APP_MAIN(vxr::Main)
67129
68130
#define GLSL(...) "#version 330\n" #__VA_ARGS__
@@ -81,15 +143,15 @@ namespace vxr
81143
82144
void Main::start()
83145
{
84-
window_title_ = (char*)malloc(512 + strlen("VXR Hello World Test"));
85-
146+
// 1. Create vertex and index buffer for the triangle.
86147
vertex_buffer_ = Engine::ref().gpu()->createBuffer({ BufferType::Vertex,
87-
sizeof(vertex_data),
88-
Usage::Static });
148+
sizeof(vertex_data),
149+
Usage::Static });
89150
index_buffer_ = Engine::ref().gpu()->createBuffer({ BufferType::Index,
90-
sizeof(index_data),
91-
Usage::Static });
151+
sizeof(index_data),
152+
Usage::Static });
92153
154+
// 2. Initialize shader data and vertex attributes data and create material for the triangle.
93155
gpu::Material::Info mat_info;
94156
mat_info.shader.vert = GLSL(
95157
in vec3 a_position;
@@ -108,6 +170,8 @@ namespace vxr
108170
109171
material_ = Engine::ref().gpu()->createMaterial(mat_info);
110172
173+
// 3. Create a render command display list to fill the index and vertex buffers with the
174+
// appropriate data once.
111175
DisplayList frame;
112176
frame.fillBufferCommand()
113177
.set_buffer(vertex_buffer_)
@@ -117,24 +181,22 @@ namespace vxr
117181
.set_buffer(index_buffer_)
118182
.set_data(index_data)
119183
.set_size(sizeof(index_data));
184+
185+
// 4. Submit display list to be rendered on the GPU.
120186
Engine::ref().submitDisplayList(std::move(frame));
121187
}
122188
123189
void Main::renderUpdate()
124190
{
125-
sprintf(window_title_,
126-
"%s: %d FPS @ 1280 x 720, Rendering time: %f ms",
127-
"VXR Hello World Test",
128-
fps(), 1.0 / (double)fps());
129-
130-
Engine::ref().window()->set_title(window_title_);
131-
132191
DisplayList frame;
192+
// 5. Clear the screen.
133193
frame.clearCommand()
134194
.set_color(Color::Black);
195+
// 6. Setup the material for rendering with the vertex buffer attached.
135196
frame.setupMaterialCommand()
136197
.set_material(material_)
137198
.set_buffer(0, vertex_buffer_);
199+
// 7. Create render command and submit display list to accummulate with previous commands.
138200
frame.renderCommand()
139201
.set_index_buffer(index_buffer_)
140202
.set_count(sizeof(index_data) / sizeof(uint16))
@@ -147,81 +209,6 @@ namespace vxr
147209
} /* end of vxr namespace */
148210
```
149211

150-
### Higher Level API
151-
152-
```c++
153-
VXR_DEFINE_APP_MAIN(vxr::Main)
154-
155-
namespace vxr
156-
{
157-
158-
Main::Main()
159-
{
160-
window_title_ = (char*)malloc(512 + strlen("VXR Instancing Test"));
161-
Params p;
162-
p.gpu = { 100, 100, 100, 100 };
163-
p.window = { { 1920, 1080} };
164-
Engine::ref().set_preinit_params(p);
165-
}
166-
167-
void Main::init()
168-
{
169-
Application::init();
170-
}
171-
172-
void Main::start()
173-
{
174-
ref_ptr<Scene> scene_;
175-
scene_.alloc();
176-
Engine::ref().loadScene(scene_);
177-
178-
cam_.alloc()->set_name("Camera");
179-
cam_->addComponent<Camera>()->set_background_color(Color(0.0f, 0.125f, 0.3f, 1.0f));
180-
cam_->transform()->set_local_position(vec3(0,0,4));
181-
scene_->addObject(cam_);
182-
183-
mesh_ = Asset::loadModelOBJ("../../assets/meshes/obj/teapot_mesh.obj");
184-
mesh_->set_name("Teapot");
185-
mesh_->transform()->set_local_rotation(vec3(glm::radians(90.0f), 0, 0));
186-
scene_->addObject(mesh_);
187-
188-
Application::start();
189-
}
190-
191-
void Main::update()
192-
{
193-
mesh_->transform()->set_local_rotation(mesh_->transform()->local_rotation()
194-
+ vec3(0.21, 0.12, 0.5) * deltaTime());
195-
Application::update();
196-
}
197-
198-
void Main::renderUpdate()
199-
{
200-
updateWindowTitle();
201-
202-
Engine::ref().submitUIFunction([this]() { ui::Editor(); });
203-
204-
Application::renderUpdate();
205-
}
206-
207-
void Main::stop()
208-
{
209-
Application::stop();
210-
}
211-
212-
void Main::updateWindowTitle()
213-
{
214-
sprintf(window_title_,
215-
"%s: %d FPS @ 1920 x 1080",
216-
"VXR Mesh Example",
217-
fps());
218-
219-
Engine::ref().window()->set_title(window_title_);
220-
}
221-
222-
} /* end of vxr namespace */
223-
```
224-
225212
# Supported Platforms
226213

227214
- Windows
@@ -260,5 +247,7 @@ Special thanks to my previous tutor [PpluX](https://github.com/pplux), top coder
260247
# Contact
261248

262249
Mail: victorap97@gmail.com
250+
263251
Twitter: https://twitter.com/97torvic
252+
264253
Web/Blog/Portfolio: https://avilapa.github.io/

0 commit comments

Comments
 (0)