Skip to content

Commit 0491229

Browse files
committed
Working on skybox
Former-commit-id: ea5dbd3
1 parent 79c0a7a commit 0491229

File tree

10 files changed

+144
-92
lines changed

10 files changed

+144
-92
lines changed

README.md

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# gl_engine
1+
# GL Engine
2+
GL Engine is simple real time rendering engine built with C++ and OpenGL. The
3+
aim of the project is to get acquainted with OpenGL and use it to implement some
4+
advanced real time lighting features.
5+
26
- Working with OpenGL to create a functional realtime rendering engine.
37

48
- OpenGL version: 4.40
@@ -9,7 +13,7 @@
913

1014
- SDL for window display.
1115

12-
## Current features:
16+
# Features
1317
- Cameras
1418
- Target camera for orbiting
1519
- Free camera
@@ -35,16 +39,25 @@
3539
- Deferred rendering
3640
- Screen space ambient occlusion
3741
- Glow effect
38-
39-
## Screenshots
42+
43+
# Screenshots
4044
![Demo 01](https://raw.githubusercontent.com/russkev/opengl/master/screenshots/demo_01.jpg)
4145
![Demo 02](https://raw.githubusercontent.com/russkev/opengl/master/screenshots/demo_02.jpg)
4246
![Demo 04](https://raw.githubusercontent.com/russkev/opengl/master/screenshots/demo_04.jpg)
4347
![Demo 05](https://raw.githubusercontent.com/russkev/opengl/master/screenshots/demo_05.jpg)
4448
![Demo 06](https://raw.githubusercontent.com/russkev/opengl/master/screenshots/demo_06.jpg)
4549
![Demo 07](https://raw.githubusercontent.com/russkev/opengl/master/screenshots/demo_07a.jpg)
4650

47-
## Big thank you to:
48-
- [Aleksandras Ševčenko](https://github.com/Coldberg) for being an excellent guide while I've been fumbling around.
49-
- [Joey Devries](https://joeydevries.com/#home) for his excellent tutorials and his example game engine here on github.
51+
52+
# Included Libraries
53+
- Glew
54+
- GLM
55+
- SDL
56+
- ZLib
57+
58+
# Acknowledgements
59+
- [Aleksandras Ševčenko](https://github.com/Coldberg) has been an excellent guide while I've been fumbling around.
60+
61+
# References
62+
- [Joey Devries](https://joeydevries.com/#home) has some excellent tutorials and an example game engine here on github.
5063
- [OpenGL Tutorial](http://www.opengl-tutorial.org/). Another excellent resource.

data/Skybox.frag

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ out layout(location = 0) vec4 frag_color;
55
in vec3 uv;
66

77
uniform samplerCube skybox;
8+
//uniform sampler2D skybox;
89

910
void main()
1011
{

gl_demo/scenes/SkyBoxDemo.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace gl_demo
2020
targetCam.focus(glm::vec3{ 0.0f, 0.0f, 0.0f });
2121
targetCam.set_clip_far(1000.0f);
2222

23-
glen::Texture uv_template_texture{ "leather_09_diffuse.tga" };
23+
//glen::Texture uv_template_texture{ "leather_09_diffuse.tga" };
2424

2525
glen::CubeMapMaterial skybox_material{ "Skybox Material" };
2626
glen::Texture skybox_texture{ glen::Texture::create_cubemap_texture({
@@ -32,11 +32,17 @@ namespace gl_demo
3232
"pond/negz.tga"
3333
})};
3434
glen::Mesh skybox_mesh = glen::Cube::create_cube();
35+
skybox_mesh.reverse_triangles();
36+
glm::mat4 skybox_transform = glm::translate(glm::mat4{ 1.0f }, glm::vec3{ 0.0f, -1.0f, 0.0f });
37+
skybox_mesh.transform(skybox_transform);
3538
skybox_material.set_texture(skybox_material.k_skybox, &skybox_texture);
3639
glen::MeshNode skybox_mesh_node{ "Skybox node", &skybox_mesh, &skybox_material };
3740

3841
glen::Renderer render{ &targetCam_node, glm::uvec2{ width, height } };
3942
render.add_node(&skybox_mesh_node);
43+
render.disable_ao();
44+
render.disable_deferred_render();
45+
render.disable_post_effects();
4046

4147
glen::Timer timer;
4248

gl_engine/Readme.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1-
## Guide for adding a new shader type
1+
# Guide for adding a new shader type
22
1. In `../data` folder, create appropriate fragment / vertex / etc. shader(s).
33
2. If a new type of texture is required, go to the factory inside `shading/Texture.h` and make a new create method there.
44
3. Inside `shading/Texture.cpp`, fill out the definition with the appropriate set methods for the gl texture.
55
4. Go to `material/MaterialLibrary.h` and make a new material that inherits from the `Material` class.
66
5. Use `inline static const` to fill out the names of any uniforms you are using in the shader.
77
6. Add update and init methods as required (see existing materials for examples).
88
7. Giva a definition for these files in the `material/MaterialLibrary.cpp` file. Models and materials should have any matrix transform methods you require.
9+
10+
## Textures
11+
Textures can be solid colours or files.
12+
13+
#### Note about `m_data`:
14+
15+
This usually contains a pointer to the actual pixel data of the texture.
16+
However, if multiple image files are required (in the case of a skybox
17+
for example), `m_data` will only point to the first image. If more are needed,
18+
it is better to cycle through the vector m_surface and access the data from
19+
each element using `m_surface.at(i)->data`.

gl_engine/material/MaterialLibrary.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,12 +352,16 @@ namespace glen
352352

353353
void CubeMapMaterial::init()
354354
{
355-
set_uniform("skybox", 0);
355+
//set_uniform("skybox", 0);
356356
}
357357

358358
void CubeMapMaterial::update_view(const CameraNode* camera_node, const Node* model_node)
359359
{
360-
set_uniform(k_transform_model_to_projection, camera_node->world_to_projection() * model_node->world_to_node());
360+
auto view = camera_node->world_to_cam();
361+
auto projection = camera_node->camera()->cam_to_projection();
362+
view = glm::mat4(glm::mat3(view));
363+
//p_matrix = glm::mat4(glm::mat3(p_matrix));
364+
set_uniform(k_transform_model_to_projection, projection * view);
361365
}
362366

363367
// DEPTH
@@ -374,7 +378,7 @@ namespace glen
374378

375379
void DepthMaterial::init()
376380
{
377-
set_uniform(k_transform_model_to_projection, glm::mat4{ 1.0f });
381+
//
378382
}
379383

380384
void DepthMaterial::update_view(const CameraNode* camera_node, const Node* mesh_node)

gl_engine/mesh/Mesh.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,16 @@ namespace glen
100100
// // ----- Triangles ----- // //
101101
void Mesh::reverse_triangles()
102102
{
103-
auto length = m_vertices->size();
103+
auto length = m_indices->size();
104104
if (length % 3 != 0)
105105
{
106106
printf("Mesh: %d does not appear to be triangles. Unable to reverse.", m_id);
107107
}
108-
for (auto i = 0; i < length; i+=3)
108+
for (auto i = 0; i < length; i+= 3)
109109
{
110-
auto temp = m_vertices->at(i+2);
111-
m_vertices->at(i + 2) = m_vertices->at(i + 3);
112-
m_vertices->at(i + 3) = temp;
110+
auto temp = m_indices->at(i + 1);
111+
m_indices->at(i + 1) = m_indices->at(i + 2);
112+
m_indices->at(i + 2) = temp;
113113
}
114114
}
115115

gl_engine/render/Renderer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ namespace glen
229229
{
230230
clear_screen();
231231

232+
//glDepthMask(false);
233+
232234
m_camera_node->update();
233235

234236
for (Material* material : m_materials)

0 commit comments

Comments
 (0)