11[ ![ vxr engine logo] ( /assets/textures/readme/logo.png )] ( https://avilapa.github.io )
22
3- _ version 0.1 .1_
3+ _ version 0.2 .1_
44
55# What is [ vxr] ( https://github.com/avilapa/vxr ) ?
66
@@ -56,6 +56,7 @@ A list of examples are provided within the solution to showcase the engine's cap
5656 - Transform
5757 - Mesh Filter
5858 - Renderer
59+ - Light
5960 - Camera
6061 - Custom Component
6162- Model loading (_ .obj_ )
@@ -91,29 +92,34 @@ namespace vxr
9192 mesh_ = Asset::loadModelOBJ("../../assets/meshes/obj/teapot_mesh.obj");
9293 mesh_->set_name("Teapot");
9394 mesh_->transform()->set_local_rotation(vec3(glm::radians(90.0f), 0.0f, 0.0f));
95+
96+ // 4. Create a light
97+ light_.alloc()->set_name("Sun");
98+ light_->addComponent<Light>()->set_color(Color::Random());
99+ light_->transform()->set_local_position(vec3(0.8, 0.3, 2.0));
94100
95- // 4 . Create a Scene, parent the objects and load.
101+ // 5 . Create a Scene, parent the objects and load.
96102 ref_ptr<Scene> scene_;
97103 scene_.alloc();
98104
99105 scene_->addObject(cam_);
100106 scene_->addObject(mesh_);
107+ scene_->addObject(light_);
101108
102109 Engine::ref().loadScene(scene_);
103110
104- // 5 . Submit the UI function.
111+ // 6 . Submit the UI function.
105112 Engine::ref().submitUIFunction([this]() { ui::Editor(); });
106113
107114 Application::start();
108115 }
109116
110117 void Main::update()
111118 {
112- // 6 . Rotate the mesh in update() instead of renderUpdate() to make the rotation framerate independent
119+ // 7 . Rotate the mesh in update() instead of renderUpdate() to make the rotation framerate independent
113120 // by multiplying it by deltaTime(). The update() method may be executed several times in a frame to
114121 // 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());
122+ mesh_ ->transform()->set_local_rotation(mesh_ ->transform()->local_rotation() + vec3(0.21, 0.12, 0.5) * deltaTime());
117123
118124 Application::update();
119125 }
@@ -127,8 +133,6 @@ namespace vxr
127133// 0. Define the entry point.
128134VXR_DEFINE_APP_MAIN(vxr::Main)
129135
130- #define GLSL(...) "#version 330\n" #__VA_ARGS__
131-
132136namespace vxr
133137{
134138 static float vertex_data[] = {
@@ -145,25 +149,31 @@ namespace vxr
145149 {
146150 // 1. Create vertex and index buffer for the triangle.
147151 vertex_buffer_ = Engine::ref().gpu()->createBuffer({ BufferType::Vertex,
148- sizeof(vertex_data),
152+ sizeof(vertex_data),
149153 Usage::Static });
150154 index_buffer_ = Engine::ref().gpu()->createBuffer({ BufferType::Index,
151- sizeof(index_data),
155+ sizeof(index_data),
152156 Usage::Static });
153157
154158 // 2. Initialize shader data and vertex attributes data and create material for the triangle.
159+ // Shader version 330 and a set of helper functions are provided by default. You can also use
160+ // the function 'Shader::Load(std::string file)' to load the shader from a file.
155161 gpu::Material::Info mat_info;
156- mat_info.shader.vert = GLSL(
157- in vec3 a_position;
158- in vec3 a_color;
159- out vec3 color;
160- void main() { gl_Position = vec4(a_position, 1.0); color = a_color; }
161- );
162- mat_info.shader.frag = GLSL(
163- in vec3 color;
164- out vec4 fragColor;
165- void main() { fragColor = vec4(color, 1.0); }
166- );
162+ mat_info.shader.vert =
163+ "in vec3 a_position; \n"
164+ "in vec3 a_color; \n"
165+ "out vec3 color; \n"
166+ "void main() \n"
167+ "{ \n"
168+ " gl_Position = vec4(a_position, 1.0); \n"
169+ " color = a_color; \n"
170+ "} \n";
171+ mat_info.shader.frag =
172+ "in vec3 color; \n"
173+ "void main() \n"
174+ "{ \n"
175+ " setFragmentColor(color); \n"
176+ "} \n";
167177
168178 mat_info.attribs[0] = { "a_position", VertexFormat::Float3 };
169179 mat_info.attribs[1] = { "a_color", VertexFormat::Float3 };
0 commit comments