Commit 05f0fc6ef8853e11751f573c741c1681f6c24c94

Authored by Olav Kjartan Larseng
1 parent dd3e9339

pushing latest, skybox doesnt work

Showing 48 changed files with 353 additions and 49 deletions   Show diff stats
SpaceShooterV4/SpaceShooterV4.vcxproj
... ... @@ -157,6 +157,7 @@
157 157 <ClInclude Include="include\Input.hpp" />
158 158 <ClInclude Include="include\SceneObject.hpp" />
159 159 <ClInclude Include="include\Shader.hpp" />
  160 + <ClInclude Include="include\Skybox.hpp" />
160 161 <ClInclude Include="include\SpaceShip.hpp" />
161 162 <ClInclude Include="include\Spotlight.h" />
162 163 <ClInclude Include="include\Text.h" />
... ... @@ -171,6 +172,7 @@
171 172 <ClCompile Include="src\GameManager.cpp" />
172 173 <ClCompile Include="src\SceneObject.cpp" />
173 174 <ClCompile Include="src\Shader.cpp" />
  175 + <ClCompile Include="src\Skybox.cpp" />
174 176 <ClCompile Include="src\SpaceShip.cpp" />
175 177 <ClCompile Include="src\Spotlight.cpp" />
176 178 <ClCompile Include="src\Text.cpp" />
... ... @@ -180,8 +182,12 @@
180 182 <None Include="assets\shaders\chess.vert" />
181 183 <None Include="assets\shaders\phong.frag" />
182 184 <None Include="assets\shaders\phong.vert" />
183   - <None Include="red.frag" />
184   - <None Include="red.vert" />
  185 + <None Include="assets\shaders\red.frag" />
  186 + <None Include="assets\shaders\red.vert" />
  187 + <None Include="assets\shaders\skybox.frag" />
  188 + <None Include="assets\shaders\skybox.vert" />
  189 + <None Include="assets\shaders\terrain.frag" />
  190 + <None Include="assets\shaders\terrain.vert" />
185 191 </ItemGroup>
186 192 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
187 193 <ImportGroup Label="ExtensionTargets">
... ...
SpaceShooterV4/SpaceShooterV4.vcxproj.filters
... ... @@ -41,9 +41,6 @@
41 41 <ClInclude Include="include\SceneObject.hpp">
42 42 <Filter>Header Files</Filter>
43 43 </ClInclude>
44   - <ClInclude Include="include\SpaceShip.hpp">
45   - <Filter>Header Files</Filter>
46   - </ClInclude>
47 44 <ClInclude Include="include\Text.h">
48 45 <Filter>Header Files</Filter>
49 46 </ClInclude>
... ... @@ -62,6 +59,12 @@
62 59 <ClInclude Include="include\Spotlight.h">
63 60 <Filter>Header Files</Filter>
64 61 </ClInclude>
  62 + <ClInclude Include="include\SpaceShip.hpp">
  63 + <Filter>Header Files</Filter>
  64 + </ClInclude>
  65 + <ClInclude Include="include\Skybox.hpp">
  66 + <Filter>Header Files</Filter>
  67 + </ClInclude>
65 68 </ItemGroup>
66 69 <ItemGroup>
67 70 <ClCompile Include="app\main.cpp">
... ... @@ -79,9 +82,6 @@
79 82 <ClCompile Include="src\SceneObject.cpp">
80 83 <Filter>Source Files</Filter>
81 84 </ClCompile>
82   - <ClCompile Include="src\SpaceShip.cpp">
83   - <Filter>Source Files</Filter>
84   - </ClCompile>
85 85 <ClCompile Include="src\Text.cpp">
86 86 <Filter>Source Files</Filter>
87 87 </ClCompile>
... ... @@ -100,14 +100,14 @@
100 100 <ClCompile Include="src\Spotlight.cpp">
101 101 <Filter>Source Files</Filter>
102 102 </ClCompile>
  103 + <ClCompile Include="src\SpaceShip.cpp">
  104 + <Filter>Source Files</Filter>
  105 + </ClCompile>
  106 + <ClCompile Include="src\Skybox.cpp">
  107 + <Filter>Source Files</Filter>
  108 + </ClCompile>
103 109 </ItemGroup>
104 110 <ItemGroup>
105   - <None Include="red.vert">
106   - <Filter>Shaders</Filter>
107   - </None>
108   - <None Include="red.frag">
109   - <Filter>Shaders</Filter>
110   - </None>
111 111 <None Include="assets\shaders\chess.frag">
112 112 <Filter>Shaders</Filter>
113 113 </None>
... ... @@ -120,5 +120,23 @@
120 120 <None Include="assets\shaders\phong.vert">
121 121 <Filter>Shaders</Filter>
122 122 </None>
  123 + <None Include="assets\shaders\terrain.frag">
  124 + <Filter>Shaders</Filter>
  125 + </None>
  126 + <None Include="assets\shaders\terrain.vert">
  127 + <Filter>Shaders</Filter>
  128 + </None>
  129 + <None Include="assets\shaders\red.frag">
  130 + <Filter>Shaders</Filter>
  131 + </None>
  132 + <None Include="assets\shaders\red.vert">
  133 + <Filter>Shaders</Filter>
  134 + </None>
  135 + <None Include="assets\shaders\skybox.frag">
  136 + <Filter>Shaders</Filter>
  137 + </None>
  138 + <None Include="assets\shaders\skybox.vert">
  139 + <Filter>Shaders</Filter>
  140 + </None>
123 141 </ItemGroup>
124 142 </Project>
125 143 \ No newline at end of file
... ...
SpaceShooterV4/app/main.cpp
... ... @@ -69,49 +69,29 @@ void display()
69 69  
70 70 if (keyPressed[KEY_ID_SPACE] == true) gm->fireFromSpaceship();
71 71  
72   -
73   - // Lets try out text
  72 + if (keyPressed[KEY_ID_X] == true) gm->getCam()->moveUp();
  73 + if (keyPressed[KEY_ID_Z] == true) gm->getCam()->moveDown();
  74 +
74 75  
  76 + /* TEXT */
75 77 glPushMatrix();
76 78 glLoadIdentity();
77 79 // Draw the text
78 80 char buffer[80];
79   - glColor3f(0.0, 0.0, 1.0);
  81 + glColor3f(1.0, 0.0, 0.0);
80 82  
81   - // Write text:
82   - /*
83   - strcpy_s(buffer, "Text example:");
84   - _text.setPos(0.5f, 0.00f, -1.0f);
85   - _text.printString(buffer, Text::FONT_NORMAL);
86   - */
87   - // Write sslf
88 83 sprintf_s(buffer, "WASD: Move, C: Change Weapon, Space: Shoot");
89 84 _text.setPos(-0.5f, -0.5f, -1.0f);
90 85 _text.printString(buffer, Text::FONT_NORMAL);
91 86  
92   - // Write framerate
93   - //sprintf_s(buffer, "More blabla");
94   - //_text.setPos(0.00f, 0.0f, -1.0f);
95   - //_text.printString(buffer, Text::FONT_NORMAL);
96 87  
  88 + glClearColor(0, 0, 0, 1);
97 89 glPopMatrix();
98 90  
99   - //glColor3f(0.0, 1.0, 1.0);
100   - //const unsigned char* c = "hello world";
101   - //char *a = "Hello World!";
102   - //glRasterPos3f(30.0f, 25.0f, 0.0f);
103   - //glRasterPos3f(-30.0f, 0.0f, 0.0f);
104   - //for (auto i = 0; a[i] != '\0'; i++)
105   - // glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, a[i]);
106   -
107   - //glFlush();
108   -
109   - // text end
110   -
111 91  
112 92 glutSwapBuffers();
113 93 glutPostRedisplay();
114   - glClearColor(0, 0, 0, 1);
  94 +
115 95 }
116 96  
117 97 void keyDown(unsigned char key, int x, int y)
... ... @@ -148,6 +128,9 @@ void keyDown(unsigned char key, int x, int y)
148 128 case 'x':
149 129 keyPressed[KEY_ID_X] = true;
150 130 break;
  131 + case 'z':
  132 + keyPressed[KEY_ID_Z] = true;
  133 + break;
151 134 case 't':
152 135 keyPressed[KEY_ID_UPARROW] = true;
153 136 break;
... ... @@ -191,6 +174,9 @@ void keyUp(unsigned char key, int x, int y)
191 174 case 'x':
192 175 keyPressed[KEY_ID_X] = false;
193 176 break;
  177 + case 'z':
  178 + keyPressed[KEY_ID_Z] = false;
  179 + break;
194 180 case 't':
195 181 keyPressed[KEY_ID_UPARROW] = false;
196 182 break;
... ...
SpaceShooterV4/assets/shaders/skybox.frag 0 → 100644
  1 +varying vec3 texCoord;
  2 +uniform samplerCube skybox;
  3 +varying vec3 Normal;
  4 +
  5 +void main()
  6 +{
  7 + vec4 ref = reflect(-view_vec, Normal);//reflect(-view_vec, Normal);
  8 + //vec3 color = texture2D(skybox, ref);
  9 + gl_FragColor = texture2D(skybox, ref.xy);
  10 +}
0 11 \ No newline at end of file
... ...
SpaceShooterV4/assets/shaders/skybox.vert 0 → 100644
  1 +varying vec3 texCoords;
  2 +varying vec3 Normal;
  3 +
  4 +void main()
  5 +{
  6 + Normal = gl_NormalMatrix * gl_Normal;
  7 + gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
  8 + texCoords = gl_Vertex;
  9 +}
0 10 \ No newline at end of file
... ...
SpaceShooterV4/assets/shaders/terrain.frag 0 → 100644
  1 +uniform sampler2D tex_colormap;
  2 +varying vec4 texCoord;
  3 +
  4 +void main()
  5 +{
  6 + gl_FragColor = texture2D(tex_colormap, texCoord.xy);
  7 + //gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
  8 +}
... ...
SpaceShooterV4/assets/shaders/terrain.vert 0 → 100644
  1 +uniform sampler2D tex_heightmap;
  2 +varying vec4 texCoord;
  3 +varying vec3 normalCoord;
  4 +
  5 +void main()
  6 +{
  7 + //vec3 normalCoord = gl_NormalMatrix * gl_Normal;
  8 +
  9 + vec4 pos = gl_Vertex;
  10 + texCoord = gl_MultiTexCoord0;
  11 + vec4 texHeight = texture2D(tex_heightmap, texCoord.xy);
  12 + pos.y = 1.1 * ((texHeight.y * 250.0) - 150.0);
  13 + pos.x = pos.x * 3.0;
  14 +
  15 + gl_Position = gl_ModelViewProjectionMatrix * pos;
  16 +}
0 17 \ No newline at end of file
... ...
SpaceShooterV4/assets/textures/colorMap2012.bmp 0 → 100644
No preview for this file type
SpaceShooterV4/assets/textures/color_height.bmp 0 → 100644
No preview for this file type
SpaceShooterV4/assets/textures/heightMap2012.bmp 0 → 100644
No preview for this file type
SpaceShooterV4/assets/textures/heightmap.bmp 0 → 100644
No preview for this file type
SpaceShooterV4/assets/textures/lightMap2012.bmp 0 → 100644
No preview for this file type
SpaceShooterV4/assets/textures/normalMap2012.bmp 0 → 100644
No preview for this file type
SpaceShooterV4/assets/textures/skybox/skybox_xn.bmp 0 → 100644
No preview for this file type
SpaceShooterV4/assets/textures/skybox/skybox_xp.bmp 0 → 100644
No preview for this file type
SpaceShooterV4/assets/textures/skybox/skybox_yn.bmp 0 → 100644
No preview for this file type
SpaceShooterV4/assets/textures/skybox/skybox_yp.bmp 0 → 100644
No preview for this file type
SpaceShooterV4/assets/textures/skybox/skybox_zn.bmp 0 → 100644
No preview for this file type
SpaceShooterV4/assets/textures/skybox/skybox_zp.bmp 0 → 100644
No preview for this file type
SpaceShooterV4/include/BattleField.hpp
... ... @@ -8,6 +8,7 @@
8 8  
9 9 #include "../include/SceneObject.hpp"
10 10 #include "glm/glm.hpp"
  11 +#include "Shader.hpp"
11 12  
12 13 class BattleField : public SceneObject
13 14 {
... ... @@ -28,6 +29,14 @@ class BattleField : public SceneObject
28 29 // normal array.
29 30 // texture coord array
30 31 GLuint _texture;
  32 + GLuint _texture1;
  33 + GLuint _texture2;
  34 + GLint _texColormapSampler;
  35 + GLint _texHeightmapSampler;
  36 + GLint _texNormalmapSampler;
  37 +
  38 + Shader terrain;
  39 +
31 40 bool _markDelete = false;
32 41 };
33 42  
... ...
SpaceShooterV4/include/Enemy.h
... ... @@ -43,6 +43,7 @@ class Enemy : public SceneObject
43 43 float _counter = 0;
44 44 float _inc_speed = 0.01f;
45 45 GLuint _texture;
  46 +
46 47 Trajectory _trajectory = Trajectory::FORWARD;
47 48  
48 49 Shader phong;
... ...
SpaceShooterV4/include/GameManager.hpp
... ... @@ -10,6 +10,7 @@
10 10 #include "Enemy.h"
11 11 #include "Spotlight.h"
12 12 #include "Bullet.h"
  13 +#include "Skybox.hpp"
13 14  
14 15 #include <random>
15 16  
... ... @@ -42,12 +43,13 @@ class GameManager : public SceneObject
42 43 std::shared_ptr<BattleField> bf_;
43 44 std::shared_ptr<SpaceShip> spaceship_;
44 45 std::shared_ptr<Camera> cam_;
45   -
  46 + std::shared_ptr<Skybox> _skybox;
46 47 std::shared_ptr<Enemy> _enemy;
47 48 std::shared_ptr<Spotlight> _spotlight;
48 49  
49 50 std::shared_ptr<Bullet> _bullet;
50 51  
  52 +
51 53 std::random_device rd;
52 54  
53 55  
... ...
SpaceShooterV4/include/Input.hpp
... ... @@ -11,5 +11,6 @@ const int KEY_ID_LEFTARROW = 7;
11 11 const int KEY_ID_RIGHTARROW = 8;
12 12 const int KEY_ID_UPARROW = 9;
13 13 const int KEY_ID_DOWNARROW = 10;
  14 +const int KEY_ID_Z = 11;
14 15  
15 16 const int MOUSE_LEFT_BUTTON_DOWN = 20;
... ...
SpaceShooterV4/include/Skybox.hpp 0 → 100644
  1 +#pragma once
  2 +#include <GL/glew.h>
  3 +#include <windows.h>
  4 +#include <../include/GL/freeglut.h>
  5 +#include <gl/gl.h>
  6 +#include <gl/glu.h>
  7 +#include "../include/SceneObject.hpp"
  8 +#include "include/Shader.hpp"
  9 +#include "include/Skybox.hpp"
  10 +#include <vector>
  11 +#include "glm/glm.hpp"
  12 +
  13 +
  14 +class Skybox : public SceneObject
  15 +{
  16 + public:
  17 + explicit Skybox();
  18 + ~Skybox();
  19 +
  20 + protected:
  21 + void privateInit();
  22 + void privateRender();
  23 + void privateUpdate();
  24 + bool markedForDeletion();
  25 +
  26 + private:
  27 + Shader _skybox;
  28 + GLint _skyboxSampler;
  29 + bool _markDelete = false;
  30 + GLuint _texture;
  31 + std::vector<GLuint> _textures;
  32 + std::vector<const char*> _textureNames{
  33 + "assets/textures/skybox/skybox_xp.bmp",
  34 + "assets/textures/skybox/skybox_xn.bmp",
  35 + "assets/textures/skybox/skybox_yp.bmp",
  36 + "assets/textures/skybox/skybox_yn.bmp",
  37 + "assets/textures/skybox/skybox_zp.bmp",
  38 + "assets/textures/skybox/skybox_zn.bmp"
  39 + };
  40 +};
0 41 \ No newline at end of file
... ...
SpaceShooterV4/src/BattleField.cpp
... ... @@ -14,9 +14,11 @@ BattleField::~BattleField()
14 14  
15 15 void BattleField::privateInit()
16 16 {
  17 + terrain.initShaders("assets/shaders/terrain");
  18 +
17 19 _texture = SOIL_load_OGL_texture
18 20 (
19   - "assets/textures/tex_soil.jpg",
  21 + "assets/textures/colorMap2012.bmp",
20 22 SOIL_LOAD_AUTO,
21 23 SOIL_CREATE_NEW_ID,
22 24 SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
... ... @@ -28,6 +30,44 @@ void BattleField::privateInit()
28 30 printf("SOIL loading error: '%s'\n", SOIL_last_result());
29 31 }
30 32  
  33 + _texture1 = SOIL_load_OGL_texture
  34 + (
  35 + "assets/textures/heightMap2012.bmp",
  36 + SOIL_LOAD_AUTO,
  37 + SOIL_CREATE_NEW_ID,
  38 + SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
  39 + );
  40 +
  41 +
  42 + /* check for an error during the load process */
  43 + if (0 == _texture1)
  44 + {
  45 + printf("SOIL loading error: '%s'\n", SOIL_last_result());
  46 + }
  47 +
  48 + _texture1 = SOIL_load_OGL_texture
  49 + (
  50 + "assets/textures/normalMap2012.bmp",
  51 + SOIL_LOAD_AUTO,
  52 + SOIL_CREATE_NEW_ID,
  53 + SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
  54 + );
  55 +
  56 + /* check for an error during the load process */
  57 + if (0 == _texture1)
  58 + {
  59 + printf("SOIL loading error: '%s'\n", SOIL_last_result());
  60 + }
  61 +
  62 + terrain.enable();
  63 + _texColormapSampler = glGetUniformLocation(terrain.getProg(), "tex_colormap");
  64 + _texHeightmapSampler = glGetUniformLocation(terrain.getProg(), "tex_heightmap");
  65 + _texNormalmapSampler = glGetUniformLocation(terrain.getProg(), "tex_normalmap");
  66 + glUniform1i(_texColormapSampler, 0); // Set ”tex_colormap” to use GL_TEXTURE0
  67 + glUniform1i(_texHeightmapSampler, 1); // Set ”tex_heightmap” to use GL_TEXTURE1
  68 + glUniform1i(_texNormalmapSampler, 2); // Set ”tex_normalmap” to use GL_TEXTURE2
  69 + terrain.disable();
  70 +
31 71 const int
32 72 BLOCK_SIZE = 32,
33 73 BLOCK_DIVIDED = BLOCK_SIZE / 2,
... ... @@ -60,10 +100,24 @@ void BattleField::privateInit()
60 100  
61 101 void BattleField::privateRender()
62 102 {
  103 + terrain.enable();
63 104 // Render the battlefield
  105 + // GL ENABLE BOTH TEXTURES
  106 + glActiveTexture(GL_TEXTURE0);
64 107 glEnable(GL_TEXTURE_2D);
65 108 glBindTexture(GL_TEXTURE_2D, _texture);
66 109  
  110 +
  111 + glActiveTexture(GL_TEXTURE1);
  112 + glEnable(GL_TEXTURE_2D);
  113 + glBindTexture(GL_TEXTURE_2D, _texture1);
  114 +
  115 + glActiveTexture(GL_TEXTURE2);
  116 + glEnable(GL_TEXTURE_2D);
  117 + glBindTexture(GL_TEXTURE_2D, _texture2);
  118 +
  119 +
  120 +
67 121 glEnableClientState(GL_VERTEX_ARRAY);
68 122 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
69 123 glEnable(GL_PRIMITIVE_RESTART);
... ... @@ -86,9 +140,20 @@ void BattleField::privateRender()
86 140 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
87 141  
88 142 glDisable(GL_PRIMITIVE_RESTART);
  143 +
  144 + // GL DISABLE BOTH TEXTURES
  145 + glActiveTexture(GL_TEXTURE2);
89 146 glDisable(GL_TEXTURE_2D);
90   - glBindTexture(GL_TEXTURE_2D, 0);
  147 +
  148 + glActiveTexture(GL_TEXTURE1);
  149 + glDisable(GL_TEXTURE_2D);
  150 +
  151 + glActiveTexture(GL_TEXTURE0);
  152 + glDisable(GL_TEXTURE_2D);
  153 +
  154 + //glBindTexture(GL_TEXTURE_2D, 0);
91 155 glClearColor(0.0, 0.0, 0.0, 1.0);
  156 + terrain.disable();
92 157 }
93 158  
94 159 void BattleField::privateUpdate()
... ...
SpaceShooterV4/src/Enemy.cpp
... ... @@ -37,6 +37,7 @@ Enemy::~Enemy()
37 37  
38 38 void Enemy::privateInit()
39 39 {
  40 + /*
40 41 _texture = SOIL_load_OGL_texture
41 42 (
42 43 "assets/textures/tex_brick.jpg",
... ... @@ -45,12 +46,12 @@ void Enemy::privateInit()
45 46 SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
46 47 );
47 48  
48   - /* check for an error during the load process */
  49 + // check for an error during the load process
49 50 if (0 == _texture)
50 51 {
51 52 printf("SOIL loading error: '%s'\n", SOIL_last_result());
52 53 }
53   -
  54 + */
54 55 phong.initShaders("assets/shaders/phong");
55 56 }
56 57  
... ... @@ -64,7 +65,7 @@ void Enemy::privateRender()
64 65 //glEnable(GL_COLOR_MATERIAL);
65 66 //glColorMaterial(GL_FRONT, GL_DIFFUSE);
66 67  
67   - glEnable(GL_LIGHT0);
  68 + //glEnable(GL_LIGHT0);
68 69 GLfloat ambient[] = { 0.0, 0.0, 0.0, 1.0 };
69 70 GLfloat spec[] = { 1.0, 1.0, 1.0, 1.0 };
70 71 GLfloat diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
... ... @@ -76,6 +77,7 @@ void Enemy::privateRender()
76 77 glColor3f(1.0f, 1.0f, 1.0f);
77 78  
78 79 glutSolidSphere(10, 30, 30);
  80 +
79 81 /*
80 82 glBegin(GL_QUADS);
81 83 float size = 5.0f;
... ... @@ -88,7 +90,7 @@ void Enemy::privateRender()
88 90 */
89 91 //glBindTexture(GL_TEXTURE_2D, 0);
90 92 //glDisable(GL_TEXTURE_2D);
91   - glDisable(GL_COLOR_MATERIAL);
  93 + //glDisable(GL_COLOR_MATERIAL);
92 94 phong.disable();
93 95 }
94 96  
... ...
SpaceShooterV4/src/GameManager.cpp
... ... @@ -26,6 +26,9 @@ void GameManager::privateInit()
26 26 this->addSubObject(cam_);
27 27 //matrix_.translate(0.0f, 0.0f, -99.0f);
28 28  
  29 + _skybox.reset(new Skybox());
  30 + this->addSubObject(_skybox);
  31 +
29 32 bf_.reset(new BattleField());
30 33 this->addSubObject(bf_);
31 34  
... ... @@ -94,12 +97,14 @@ int GameManager::random(const T &amp; from, const T &amp; to)
94 97  
95 98 void GameManager::fireFromSpaceship()
96 99 {
  100 + // Reminder: Such redundant code, needs to be fixed
97 101 int nextFire = 200;
98 102 if (!fireFlag)
99 103 {
100 104 fireFlag = true;
101 105 _lastFire = Rolex::now();
102 106 auto spaceshipmatrix = spaceship_->getMatrix();
  107 +
103 108 switch (this->getSpaceShip()->getWeapon())
104 109 {
105 110 case 0:
... ...
SpaceShooterV4/src/Skybox.cpp 0 → 100644
  1 +#pragma once
  2 +#include <GL/glew.h>
  3 +#include <GL/glut.h>
  4 +#include "..\include\Skybox.hpp"
  5 +#include "include\soil\SOIL.h"
  6 +
  7 +
  8 +Skybox::Skybox()
  9 +{
  10 +}
  11 +
  12 +Skybox::~Skybox()
  13 +{
  14 +}
  15 +
  16 +void Skybox::privateInit()
  17 +{
  18 + _skybox.initShaders("assets/shaders/skybox");
  19 +
  20 +
  21 + for (auto name : _textureNames)
  22 + {
  23 + GLuint tex = SOIL_load_OGL_texture
  24 + (
  25 + name,
  26 + SOIL_LOAD_AUTO,
  27 + SOIL_CREATE_NEW_ID,
  28 + SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
  29 + );
  30 +
  31 + /* check for an error during the load process */
  32 + if (0 == tex)
  33 + {
  34 + printf("SOIL loading error: '%s'\n", SOIL_last_result());
  35 + }
  36 +
  37 + _textures.push_back(tex);
  38 + }
  39 + /*
  40 + const int width = 512, height = 512;
  41 + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
  42 + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
  43 + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
  44 + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
  45 + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
  46 + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
  47 + */
  48 +
  49 + _texture = SOIL_load_OGL_cubemap
  50 + (
  51 + _textureNames[0],
  52 + _textureNames[1],
  53 + _textureNames[2],
  54 + _textureNames[3],
  55 + _textureNames[4],
  56 + _textureNames[5],
  57 + SOIL_LOAD_AUTO,
  58 + SOIL_CREATE_NEW_ID,
  59 + SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
  60 + );
  61 +
  62 + _skybox.enable();
  63 + _skyboxSampler = glGetUniformLocation(_skybox.getProg(), "skybox");
  64 + glUniform1i(_skyboxSampler, 0); // Set ”skybox” to use GL_TEXTURE0
  65 + _skybox.disable();
  66 +}
  67 +
  68 +void Skybox::privateRender()
  69 +{
  70 +
  71 + //glCullFace(GL_BACK);
  72 + //glFrontFace(GL_CW);
  73 + glDisable(GL_DEPTH_TEST);
  74 + /*
  75 +
  76 +
  77 +
  78 +
  79 + glEnable(GL_TEXTURE_GEN_S);
  80 + glEnable(GL_TEXTURE_GEN_T);
  81 + glEnable(GL_TEXTURE_GEN_R);
  82 + glEnable(GL_TEXTURE_CUBE_MAP);
  83 +
  84 +
  85 + glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP);
  86 + glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP);
  87 + glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP);
  88 +
  89 + glEnable(GL_TEXTURE_2D);
  90 + glBindTexture(GL_TEXTURE_CUBE_MAP, _texture);
  91 + */
  92 + glEnable(GL_TEXTURE_GEN_S);
  93 + glEnable(GL_TEXTURE_GEN_T);
  94 + glEnable(GL_TEXTURE_GEN_R);
  95 + glEnable(GL_TEXTURE_2D);
  96 + glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP);
  97 + glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP);
  98 + glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP);
  99 + glColor3b(0.0, 1.0, 1.0);
  100 + /*
  101 + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, &_textures.at(0));
  102 + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, &_textures.at(1));
  103 + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, &_textures.at(2));
  104 + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, &_textures.at(3));
  105 + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, &_textures.at(4));
  106 + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, &_textures.at(5));
  107 + */
  108 +
  109 +
  110 + glDisable(GL_TEXTURE_GEN_S);
  111 + glDisable(GL_TEXTURE_GEN_T);
  112 + glDisable(GL_TEXTURE_GEN_R);
  113 + glDisable(GL_TEXTURE_CUBE_MAP);
  114 + glEnable(GL_DEPTH_TEST);
  115 +
  116 +}
  117 +
  118 +void Skybox::privateUpdate()
  119 +{
  120 +}
  121 +
  122 +bool Skybox::markedForDeletion()
  123 +{
  124 + return _markDelete;
  125 +}
... ...
SpaceShooterV4/x64/Debug/BattleField.obj
No preview for this file type
SpaceShooterV4/x64/Debug/Bullet.obj
No preview for this file type
SpaceShooterV4/x64/Debug/Collision.obj
No preview for this file type
SpaceShooterV4/x64/Debug/Enemy.obj
No preview for this file type
SpaceShooterV4/x64/Debug/GameManager.obj
No preview for this file type
SpaceShooterV4/x64/Debug/Shader.obj
No preview for this file type
SpaceShooterV4/x64/Debug/Skybox.obj 0 → 100644
No preview for this file type
SpaceShooterV4/x64/Debug/SpaceShooterV4.log
1   - GameManager.cpp
  1 + Skybox.cpp
  2 +d:\csmaster\opengl projects\projects\spaceshooterv4\spaceshooterv4\spaceshooterv4\src\skybox.cpp(99): warning C4244: 'argument': conversion from 'double' to 'GLbyte', possible loss of data
2 3 SOIL.lib(SOIL.obj) : MSIL .netmodule or module compiled with /GL found; restarting link with /LTCG; add /LTCG to the link command line to improve linker performance
3 4 LINK : warning LNK4075: ignoring '/INCREMENTAL' due to '/LTCG' specification
4 5 LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
... ...
SpaceShooterV4/x64/Debug/SpaceShooterV4.tlog/CL.command.1.tlog
1 1 Binary files a/SpaceShooterV4/x64/Debug/SpaceShooterV4.tlog/CL.command.1.tlog and b/SpaceShooterV4/x64/Debug/SpaceShooterV4.tlog/CL.command.1.tlog differ
... ...
SpaceShooterV4/x64/Debug/SpaceShooterV4.tlog/CL.read.1.tlog
1 1 Binary files a/SpaceShooterV4/x64/Debug/SpaceShooterV4.tlog/CL.read.1.tlog and b/SpaceShooterV4/x64/Debug/SpaceShooterV4.tlog/CL.read.1.tlog differ
... ...
SpaceShooterV4/x64/Debug/SpaceShooterV4.tlog/CL.write.1.tlog
1 1 Binary files a/SpaceShooterV4/x64/Debug/SpaceShooterV4.tlog/CL.write.1.tlog and b/SpaceShooterV4/x64/Debug/SpaceShooterV4.tlog/CL.write.1.tlog differ
... ...
SpaceShooterV4/x64/Debug/SpaceShooterV4.tlog/SpaceShooterV4.write.1u.tlog
1 1 Binary files a/SpaceShooterV4/x64/Debug/SpaceShooterV4.tlog/SpaceShooterV4.write.1u.tlog and b/SpaceShooterV4/x64/Debug/SpaceShooterV4.tlog/SpaceShooterV4.write.1u.tlog differ
... ...
SpaceShooterV4/x64/Debug/SpaceShooterV4.tlog/link.command.1.tlog
1 1 Binary files a/SpaceShooterV4/x64/Debug/SpaceShooterV4.tlog/link.command.1.tlog and b/SpaceShooterV4/x64/Debug/SpaceShooterV4.tlog/link.command.1.tlog differ
... ...
SpaceShooterV4/x64/Debug/SpaceShooterV4.tlog/link.read.1.tlog
1 1 Binary files a/SpaceShooterV4/x64/Debug/SpaceShooterV4.tlog/link.read.1.tlog and b/SpaceShooterV4/x64/Debug/SpaceShooterV4.tlog/link.read.1.tlog differ
... ...
SpaceShooterV4/x64/Debug/SpaceShooterV4.tlog/link.write.1.tlog
1 1 Binary files a/SpaceShooterV4/x64/Debug/SpaceShooterV4.tlog/link.write.1.tlog and b/SpaceShooterV4/x64/Debug/SpaceShooterV4.tlog/link.write.1.tlog differ
... ...
SpaceShooterV4/x64/Debug/main.obj
No preview for this file type
SpaceShooterV4/x64/Debug/vc141.idb
No preview for this file type
SpaceShooterV4/x64/Debug/vc141.pdb
No preview for this file type
x64/Debug/SpaceShooterV4.exe
No preview for this file type
x64/Debug/SpaceShooterV4.pdb
No preview for this file type