Commit 03d9e394d6455987bb7c1a9cf3cdd55c4dc17b89

Authored by Olav Kjartan Larseng
1 parent 05f0fc6e

added skybox, but needs fix

SpaceShooterV4/app/main.cpp
... ... @@ -24,6 +24,8 @@ int mousePosX, mousePosY;
24 24 float moveX, moveY;
25 25 Text _text;
26 26  
  27 +bool isDown = false;
  28 +
27 29 void init()
28 30 {
29 31 _text.init();
... ... @@ -61,16 +63,38 @@ void display()
61 63 gm->render();
62 64  
63 65 if (keyPressed[KEY_ID_W] == true) gm->getSpaceShip()->moveForward();
64   - if (keyPressed[KEY_ID_A] == true) gm->getCam()->moveLeft(gm->getSpaceShip()->moveLeft());
65   - if (keyPressed[KEY_ID_D] == true) gm->getCam()->moveRight(gm->getSpaceShip()->moveRight());
  66 + if (keyPressed[KEY_ID_A] == true)
  67 + {
  68 + auto offset = gm->getSpaceShip()->moveLeft();
  69 + gm->getCam()->moveLeft(offset);
  70 + gm->getSkybox()->moveLeft(offset);
  71 + }
  72 + if (keyPressed[KEY_ID_D] == true)
  73 + {
  74 + auto offset = gm->getSpaceShip()->moveRight();
  75 + gm->getCam()->moveRight(offset);
  76 + gm->getSkybox()->moveRight(offset);
  77 + }
66 78 if (keyPressed[KEY_ID_S] == true) gm->getSpaceShip()->moveBackward();
67 79  
68   - if (keyPressed[KEY_ID_C] == true) gm->getSpaceShip()->changeWeapon();
  80 + if (keyPressed[KEY_ID_C] == true && !isDown) {
  81 + gm->getSpaceShip()->changeWeapon();
  82 + keyPressed[KEY_ID_C] = false;
  83 + isDown = true;
  84 + }
69 85  
70 86 if (keyPressed[KEY_ID_SPACE] == true) gm->fireFromSpaceship();
71 87  
72   - if (keyPressed[KEY_ID_X] == true) gm->getCam()->moveUp();
73   - if (keyPressed[KEY_ID_Z] == true) gm->getCam()->moveDown();
  88 + if (keyPressed[KEY_ID_X] == true)
  89 + {
  90 + auto offset = gm->getCam()->moveUp();
  91 + gm->getSkybox()->moveUp(offset);
  92 + }
  93 + if (keyPressed[KEY_ID_Z] == true)
  94 + {
  95 + auto offset = gm->getCam()->moveDown();
  96 + gm->getSkybox()->moveDown(offset);
  97 + }
74 98  
75 99  
76 100 /* TEXT */
... ... @@ -169,6 +193,7 @@ void keyUp(unsigned char key, int x, int y)
169 193 keyPressed[KEY_ID_SPACE] = false;
170 194 break;
171 195 case 'c':
  196 + isDown = false;
172 197 keyPressed[KEY_ID_C] = false;
173 198 break;
174 199 case 'x':
... ...
SpaceShooterV4/assets/shaders/skybox.frag
1   -varying vec3 texCoord;
  1 +varying vec4 texCoord;
2 2 uniform samplerCube skybox;
3   -varying vec3 Normal;
4 3  
5 4 void main()
6 5 {
7   - vec4 ref = reflect(-view_vec, Normal);//reflect(-view_vec, Normal);
  6 + //vec4 ref = reflect(-view_vec, Normal);//reflect(-view_vec, Normal);
8 7 //vec3 color = texture2D(skybox, ref);
9   - gl_FragColor = texture2D(skybox, ref.xy);
  8 + gl_FragColor = textureCube(skybox, texCoord.xyz);
10 9 }
11 10 \ No newline at end of file
... ...
SpaceShooterV4/assets/shaders/skybox.vert
1   -varying vec3 texCoords;
2   -varying vec3 Normal;
  1 +varying vec4 texCoord;
3 2  
4 3 void main()
5 4 {
6   - Normal = gl_NormalMatrix * gl_Normal;
7   - gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
8   - texCoords = gl_Vertex;
  5 + texCoord = gl_Vertex;
  6 + gl_Position = gl_ModelViewProjectionMatrix * (gl_Vertex * vec4(1200.0, 1200.0, 1200.0, 1.0));
9 7 }
10 8 \ No newline at end of file
... ...
SpaceShooterV4/assets/shaders/terrain.vert
1 1 uniform sampler2D tex_heightmap;
2 2 varying vec4 texCoord;
3   -varying vec3 normalCoord;
  3 +//varying vec3 normalCoord;
4 4  
5 5 void main()
6 6 {
... ... @@ -9,8 +9,8 @@ void main()
9 9 vec4 pos = gl_Vertex;
10 10 texCoord = gl_MultiTexCoord0;
11 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;
  12 + pos.y = ((texHeight.y * 100.0) - 150.0);
  13 + //pos.x = pos.x * 3.0;
14 14  
15 15 gl_Position = gl_ModelViewProjectionMatrix * pos;
16 16 }
17 17 \ No newline at end of file
... ...
SpaceShooterV4/include/Camera.hpp
... ... @@ -13,10 +13,10 @@ class Camera : public SceneObject
13 13 Camera();
14 14 ~Camera();
15 15  
16   - void moveRight(const float& amount);
17   - void moveLeft(const float& amount);
18   - void moveUp();
19   - void moveDown();
  16 + const float& moveRight(const float& amount);
  17 + const float& moveLeft(const float& amount);
  18 + const float& moveUp();
  19 + const float& moveDown();
20 20 void moveBackward();
21 21 void moveForward();
22 22 void move(const float & x, const float & y, const float & z);
... ...
SpaceShooterV4/include/GameManager.hpp
... ... @@ -24,6 +24,7 @@ class GameManager : public SceneObject
24 24  
25 25 std::shared_ptr<Camera> getCam();
26 26 std::shared_ptr<SpaceShip> getSpaceShip();
  27 + std::shared_ptr<Skybox> getSkybox();
27 28  
28 29 void fireFromSpaceship();
29 30  
... ... @@ -40,6 +41,7 @@ class GameManager : public SceneObject
40 41 virtual bool markedForDeletion();
41 42  
42 43 private:
  44 + bool sendCamera = false;
43 45 std::shared_ptr<BattleField> bf_;
44 46 std::shared_ptr<SpaceShip> spaceship_;
45 47 std::shared_ptr<Camera> cam_;
... ...
SpaceShooterV4/include/Skybox.hpp
... ... @@ -17,6 +17,12 @@ class Skybox : public SceneObject
17 17 explicit Skybox();
18 18 ~Skybox();
19 19  
  20 + void translateMatrix(const glm::mat4& startMatrix);
  21 + const float& moveRight(const float& amount);
  22 + const float& moveLeft(const float& amount);
  23 + const float& moveUp(const float& amount);
  24 + const float& moveDown(const float& amount);
  25 +
20 26 protected:
21 27 void privateInit();
22 28 void privateRender();
... ... @@ -24,6 +30,7 @@ class Skybox : public SceneObject
24 30 bool markedForDeletion();
25 31  
26 32 private:
  33 + GLint _texColormapSampler;
27 34 Shader _skybox;
28 35 GLint _skyboxSampler;
29 36 bool _markDelete = false;
... ... @@ -37,4 +44,19 @@ class Skybox : public SceneObject
37 44 "assets/textures/skybox/skybox_zp.bmp",
38 45 "assets/textures/skybox/skybox_zn.bmp"
39 46 };
  47 + std::vector<unsigned char*> vImages;
  48 +
  49 + float vertexBuffer[18 * 6];
  50 + float textureBuffer[12 * 6];
  51 + float normalBuffer[18 * 6];
  52 +
  53 + std::vector<glm::vec3> vertices;
  54 + std::vector<glm::vec2> texCoords;
  55 + std::vector<int> indices;
  56 +
  57 +
  58 + GLuint boxVBO;
  59 + unsigned int textureID;
  60 +
  61 +
40 62 };
41 63 \ No newline at end of file
... ...
SpaceShooterV4/include/Water.hpp 0 → 100644
  1 +#pragma once
  2 +
  3 +#include <GL/glew.h>
  4 +#include <windows.h>
  5 +#include <../include/GL/freeglut.h>
  6 +#include <gl/gl.h>
  7 +#include <gl/glu.h>
  8 +#include "../include/SceneObject.hpp"
  9 +#include "glm/glm.hpp"
  10 +#include "Shader.hpp"
  11 +
  12 +class Water : public SceneObject
  13 +{
  14 + public:
  15 + Water();
  16 + ~Water();
  17 +
  18 + protected:
  19 + void privateInit();
  20 + void privateRender();
  21 + void privateUpdate();
  22 + bool markedForDeletion();
  23 +
  24 + private:
  25 + std::vector< glm::vec3 > vertexArray_; // Maybe two-dim vector and several arrays
  26 + std::vector< glm::uint > indicesArray_;
  27 + std::vector< glm::vec2 > _texCoordArray;
  28 + // normal array.
  29 + // texture coord array
  30 + GLuint _texture;
  31 + GLint _texColormapSampler;
  32 +
  33 + Shader waterShader;
  34 +
  35 + bool _markDelete = false;
  36 +};
  37 +
... ...
SpaceShooterV4/src/BattleField.cpp
... ... @@ -45,7 +45,7 @@ void BattleField::privateInit()
45 45 printf("SOIL loading error: '%s'\n", SOIL_last_result());
46 46 }
47 47  
48   - _texture1 = SOIL_load_OGL_texture
  48 + _texture2 = SOIL_load_OGL_texture
49 49 (
50 50 "assets/textures/normalMap2012.bmp",
51 51 SOIL_LOAD_AUTO,
... ... @@ -54,7 +54,7 @@ void BattleField::privateInit()
54 54 );
55 55  
56 56 /* check for an error during the load process */
57   - if (0 == _texture1)
  57 + if (0 == _texture2)
58 58 {
59 59 printf("SOIL loading error: '%s'\n", SOIL_last_result());
60 60 }
... ... @@ -62,14 +62,14 @@ void BattleField::privateInit()
62 62 terrain.enable();
63 63 _texColormapSampler = glGetUniformLocation(terrain.getProg(), "tex_colormap");
64 64 _texHeightmapSampler = glGetUniformLocation(terrain.getProg(), "tex_heightmap");
65   - _texNormalmapSampler = glGetUniformLocation(terrain.getProg(), "tex_normalmap");
  65 + //_texNormalmapSampler = glGetUniformLocation(terrain.getProg(), "tex_normalmap");
66 66 glUniform1i(_texColormapSampler, 0); // Set ”tex_colormap” to use GL_TEXTURE0
67 67 glUniform1i(_texHeightmapSampler, 1); // Set ”tex_heightmap” to use GL_TEXTURE1
68   - glUniform1i(_texNormalmapSampler, 2); // Set ”tex_normalmap” to use GL_TEXTURE2
  68 + //glUniform1i(_texNormalmapSampler, 2); // Set ”tex_normalmap” to use GL_TEXTURE2
69 69 terrain.disable();
70 70  
71 71 const int
72   - BLOCK_SIZE = 32,
  72 + BLOCK_SIZE = 64,
73 73 BLOCK_DIVIDED = BLOCK_SIZE / 2,
74 74 BLOCK_LENGTH = 512,
75 75 SCALAR_X = 10,
... ... @@ -112,11 +112,11 @@ void BattleField::privateRender()
112 112 glEnable(GL_TEXTURE_2D);
113 113 glBindTexture(GL_TEXTURE_2D, _texture1);
114 114  
  115 + /*
115 116 glActiveTexture(GL_TEXTURE2);
116 117 glEnable(GL_TEXTURE_2D);
117 118 glBindTexture(GL_TEXTURE_2D, _texture2);
118   -
119   -
  119 + */
120 120  
121 121 glEnableClientState(GL_VERTEX_ARRAY);
122 122 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
... ... @@ -142,8 +142,10 @@ void BattleField::privateRender()
142 142 glDisable(GL_PRIMITIVE_RESTART);
143 143  
144 144 // GL DISABLE BOTH TEXTURES
  145 + /*
145 146 glActiveTexture(GL_TEXTURE2);
146 147 glDisable(GL_TEXTURE_2D);
  148 + */
147 149  
148 150 glActiveTexture(GL_TEXTURE1);
149 151 glDisable(GL_TEXTURE_2D);
... ...
SpaceShooterV4/src/Camera.cpp
... ... @@ -42,22 +42,31 @@ void Camera::move(const float&amp; x, const float&amp; y, const float&amp; z)
42 42 matrix_ = glm::translate(matrix_, glm::vec3(x * _deltaTime, y * _deltaTime, z * _deltaTime));
43 43 }
44 44  
45   -void Camera::moveRight(const float& amount)
  45 +const float& Camera::moveRight(const float& amount)
46 46 {
47 47 matrix_ = glm::translate(matrix_, glm::vec3(amount, 0.0f, 0.0f));
  48 + return amount;
48 49 }
49   -void Camera::moveLeft(const float& amount)
  50 +const float& Camera::moveLeft(const float& amount)
50 51 {
51 52 matrix_ = glm::translate(matrix_, glm::vec3(amount, 0.0f, 0.0f));
  53 + return amount;
52 54 }
53   -void Camera::moveUp()
  55 +
  56 +const float& Camera::moveUp()
54 57 {
55   - matrix_ = glm::translate(matrix_, glm::vec3(0.0f, -_speed * _deltaTime, 0.0f));
  58 + const float amount = -_speed * _deltaTime;
  59 + matrix_ = glm::translate(matrix_, glm::vec3(0.0f, amount, 0.0f));
  60 + return amount;
56 61 }
57   -void Camera::moveDown()
  62 +
  63 +const float& Camera::moveDown()
58 64 {
59   - matrix_ = glm::translate(matrix_, glm::vec3(0.0f, _speed * _deltaTime, 0.0f));
  65 + const float amount = _speed * _deltaTime;
  66 + matrix_ = glm::translate(matrix_, glm::vec3(0.0f, amount, 0.0f));
  67 + return amount;
60 68 }
  69 +
61 70 void Camera::moveForward()
62 71 {
63 72 matrix_ = glm::translate(matrix_, glm::vec3(0.0f, 0.0f, _speed * _deltaTime));
... ...
SpaceShooterV4/src/GameManager.cpp
... ... @@ -28,6 +28,7 @@ void GameManager::privateInit()
28 28  
29 29 _skybox.reset(new Skybox());
30 30 this->addSubObject(_skybox);
  31 +
31 32  
32 33 bf_.reset(new BattleField());
33 34 this->addSubObject(bf_);
... ... @@ -53,6 +54,7 @@ void GameManager::privateInit()
53 54 this->addSubObject(_enemy);
54 55 }
55 56  
  57 + //_skybox->setMatrix(cam_->getMatrix());
56 58  
57 59 //_spotlight.reset(new Spotlight(glm::vec3{0,0,200}, 60, 80));
58 60 //this->addSubObject(_spotlight);
... ... @@ -66,10 +68,18 @@ void GameManager::privateRender()
66 68  
67 69 void GameManager::privateUpdate()
68 70 {
  71 +
69 72 // Instead of adding alle objects in the scene as subobject to the camera they are added as subobjects
70 73 // to the game manager. Therefore, we set the game manager matrix equal to the camera matrix.
71 74 this->matrix_ = cam_->getMatrix();
72 75 this->fireFromEnemy();
  76 +
  77 + // Dirty af
  78 + if (!sendCamera)
  79 + {
  80 + sendCamera = true;
  81 + this->getSkybox()->translateMatrix(this->getCam()->getMatrix());
  82 + }
73 83 }
74 84  
75 85 bool GameManager::markedForDeletion()
... ... @@ -87,6 +97,11 @@ std::shared_ptr&lt;SpaceShip&gt; GameManager::getSpaceShip()
87 97 return spaceship_;
88 98 }
89 99  
  100 +std::shared_ptr<Skybox> GameManager::getSkybox()
  101 +{
  102 + return _skybox;
  103 +}
  104 +
90 105 template <typename T>
91 106 int GameManager::random(const T & from, const T & to)
92 107 {
... ...
SpaceShooterV4/src/Skybox.cpp
... ... @@ -3,21 +3,74 @@
3 3 #include <GL/glut.h>
4 4 #include "..\include\Skybox.hpp"
5 5 #include "include\soil\SOIL.h"
  6 +#include "include/Camera.hpp"
  7 +#include "include/glm/gtc/matrix_transform.hpp"
6 8  
7 9  
8 10 Skybox::Skybox()
9 11 {
  12 + // Same starting point as camera
  13 + //matrix_ = glm::translate(glm::mat4(), glm::vec3(0.0f, -30.0f, -150.0f));
  14 + matrix_ = glm::mat4();
10 15 }
11 16  
  17 +
12 18 Skybox::~Skybox()
13 19 {
14 20 }
15 21  
  22 +void Skybox::translateMatrix(const glm::mat4& startMatrix)
  23 +{
  24 + matrix_ = glm::translate(matrix_, glm::vec3(-startMatrix[3][0], -startMatrix[3][1], -startMatrix[3][2]));
  25 +}
  26 +
  27 +const float & Skybox::moveRight(const float & amount)
  28 +{
  29 + matrix_ = glm::translate(matrix_, glm::vec3(-amount, 0.0f, 0.0f));
  30 + return amount;
  31 +}
  32 +
  33 +const float & Skybox::moveLeft(const float & amount)
  34 +{
  35 + matrix_ = glm::translate(matrix_, glm::vec3(-amount, 0.0f, 0.0f));
  36 + return amount;
  37 +}
  38 +
  39 +const float & Skybox::moveUp(const float & amount)
  40 +{
  41 + matrix_ = glm::translate(matrix_, glm::vec3(0.0f, -amount, 0.0f));
  42 + return amount;
  43 +}
  44 +
  45 +const float & Skybox::moveDown(const float & amount)
  46 +{
  47 + matrix_ = glm::translate(matrix_, glm::vec3(0.0f, -amount, 0.0f));
  48 + return amount;
  49 +}
  50 +
  51 +
  52 +
16 53 void Skybox::privateInit()
17 54 {
18 55 _skybox.initShaders("assets/shaders/skybox");
19 56  
20 57  
  58 + //glGenTextures(1, &textureID);
  59 + //glBindTexture(GL_TEXTURE_CUBE_MAP, textureID);
  60 +
  61 + _texture = SOIL_load_OGL_cubemap
  62 + (
  63 + _textureNames[0],
  64 + _textureNames[1],
  65 + _textureNames[2],
  66 + _textureNames[3],
  67 + _textureNames[4],
  68 + _textureNames[5],
  69 + SOIL_LOAD_AUTO,
  70 + SOIL_CREATE_NEW_ID,
  71 + SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
  72 + );
  73 + /*
21 74 for (auto name : _textureNames)
22 75 {
23 76 GLuint tex = SOIL_load_OGL_texture
... ... @@ -28,7 +81,7 @@ void Skybox::privateInit()
28 81 SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
29 82 );
30 83  
31   - /* check for an error during the load process */
  84 +
32 85 if (0 == tex)
33 86 {
34 87 printf("SOIL loading error: '%s'\n", SOIL_last_result());
... ... @@ -36,6 +89,31 @@ void Skybox::privateInit()
36 89  
37 90 _textures.push_back(tex);
38 91 }
  92 + */
  93 +
  94 + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  95 + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  96 + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  97 + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  98 + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
  99 +
  100 + /*
  101 + int total = 512 * 512;
  102 + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, &_texture[0]);
  103 + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, &_texture[1]);
  104 + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, &_texture[2]);
  105 + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, &_texture[3]);
  106 + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, &_texture[4]);
  107 + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, &_texture[5]);
  108 + */
  109 + /*
  110 + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, &_textures.at(0));
  111 + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, &_textures.at(1));
  112 + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, &_textures.at(2));
  113 + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, &_textures.at(3));
  114 + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, &_textures.at(4));
  115 + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, &_textures.at(5));
  116 + */
39 117 /*
40 118 const int width = 512, height = 512;
41 119 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
... ... @@ -44,8 +122,16 @@ void Skybox::privateInit()
44 122 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
45 123 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
46 124 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
47   - */
48 125  
  126 +
  127 +
  128 + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, &_textures.at(0));
  129 + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, &_textures.at(1));
  130 + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, &_textures.at(2));
  131 + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, &_textures.at(3));
  132 + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, &_textures.at(4));
  133 + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, &_textures.at(5));
  134 +
49 135 _texture = SOIL_load_OGL_cubemap
50 136 (
51 137 _textureNames[0],
... ... @@ -59,18 +145,208 @@ void Skybox::privateInit()
59 145 SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
60 146 );
61 147  
  148 +
62 149 _skybox.enable();
63 150 _skyboxSampler = glGetUniformLocation(_skybox.getProg(), "skybox");
64 151 glUniform1i(_skyboxSampler, 0); // Set ”skybox” to use GL_TEXTURE0
65 152 _skybox.disable();
  153 + */
  154 + int size = 1;
  155 + vertices =
  156 + {
  157 + glm::vec3(-size, -size, -size),
  158 + glm::vec3(size, -size, -size),
  159 + glm::vec3(size, size, -size),
  160 + glm::vec3(-size, size, -size),
  161 + glm::vec3(-size, -size, size),
  162 + glm::vec3(size, -size, size),
  163 + glm::vec3(size, size, size),
  164 + glm::vec3(-size, size, size)
  165 + };
  166 +
  167 + texCoords =
  168 + {
  169 + glm::vec2(0, 0),
  170 + glm::vec2(1, 0),
  171 + glm::vec2(1, 1),
  172 + glm::vec2(0, 1),
  173 + glm::vec2(0, 0),
  174 + glm::vec2(1, 0),
  175 + glm::vec2(1, 1),
  176 + glm::vec2(0, 1)
  177 + };
  178 +
  179 + glm::vec3 normals[6] =
  180 + {
  181 + glm::vec3(0, 0, 1),
  182 + glm::vec3(1, 0, 0),
  183 + glm::vec3(0, 0, -1),
  184 + glm::vec3(-1, 0, 0),
  185 + glm::vec3(0, 1, 0),
  186 + glm::vec3(0, -1, 0)
  187 + };
  188 +
  189 + indices =
  190 + {
  191 + 0, 1, 3, 3, 1, 2,
  192 + 1, 5, 2, 2, 5, 6,
  193 + 5, 4, 6, 6, 4, 7,
  194 + 4, 0, 7, 7, 0, 3,
  195 + 3, 2, 7, 7, 2, 6,
  196 + 4, 5, 0, 0, 5, 1
  197 + };
  198 +
  199 + _skybox.enable();
  200 + _texColormapSampler = glGetUniformLocation(_skybox.getProg(), "skybox");
  201 + glUniform1i(_texColormapSampler, 0); // Set ”tex_colormap” to use GL_TEXTURE0
  202 + _skybox.disable();
  203 +
  204 + /*
  205 + //VBO BUFFER EXAMPLE
  206 +
  207 + int texInds[6] = { 0, 1, 3, 3, 1, 2 };
  208 +
  209 + for (int i = 0; i < 36; i++) {
  210 + vertexBuffer[i * 3 + 0] = vertices[indices[i]].x;
  211 + vertexBuffer[i * 3 + 1] = vertices[indices[i]].y;
  212 + vertexBuffer[i * 3 + 2] = vertices[indices[i]].z;
  213 + }
  214 +
  215 + for (int i = 0; i < 36; i++) {
  216 + textureBuffer[i * 2 + 0] = texCoords[texInds[i % 4]].x;
  217 + textureBuffer[i * 2 + 1] = texCoords[texInds[i % 4]].y;
  218 + }
  219 +
  220 + for (int i = 0; i < 36; i++) {
  221 + normalBuffer[i * 3 + 0] = normals[indices[i / 6]].x;
  222 + normalBuffer[i * 3 + 1] = normals[indices[i / 6]].y;
  223 + normalBuffer[i * 3 + 2] = normals[indices[i / 6]].z;
  224 + }
  225 +
  226 +
  227 + glGenBuffers(1, &boxVBO);
  228 + glBindBuffer(GL_ARRAY_BUFFER, boxVBO);
  229 + glBufferData(GL_ARRAY_BUFFER, sizeof(vertexBuffer), (void*)vertexBuffer, GL_STATIC_DRAW);
  230 + */
  231 +
66 232 }
67 233  
68 234 void Skybox::privateRender()
69 235 {
  236 + glDisable(GL_DEPTH_TEST);
  237 + _skybox.enable();
  238 + //glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
  239 + //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  240 + // ENABLE
  241 + //glDepthFunc(GL_LEQUAL);
  242 +
  243 + //glColor3f(1.0, 1.0, 1.0);
  244 + glActiveTexture(GL_TEXTURE0);
  245 + glEnable(GL_TEXTURE_CUBE_MAP);
  246 + glBindTexture(GL_TEXTURE_CUBE_MAP, _texture);
  247 +
  248 + /*
  249 + glDepthMask(GL_FALSE);
  250 +
  251 + glBindVertexArray(skyboxVertices);
  252 + glBindTexture(GL_TEXTURE_CUBE_MAP, cubemapTexture);
  253 + glDrawArrays(GL_TRIANGLES, 0, 36);
  254 + glDepthMask(GL_TRUE);
  255 + */
  256 +
  257 +
  258 + glEnableClientState(GL_VERTEX_ARRAY);
  259 + //glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  260 +
  261 + glVertexPointer(3, GL_FLOAT, 0, &vertices[0]);
  262 + //glTexCoordPointer(2, GL_FLOAT, 0, &texCoords[0]);
  263 + /*
  264 + glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP);
  265 + glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP);
  266 + glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP);
  267 + glEnable(GL_TEXTURE_GEN_S);
  268 + glEnable(GL_TEXTURE_GEN_T);
  269 + glEnable(GL_TEXTURE_GEN_R);
  270 + */
  271 + glDrawElements(GL_TRIANGLES,
  272 + indices.size(),
  273 + GL_UNSIGNED_INT,
  274 + &indices[0]);
  275 +
  276 + // DISABLE
  277 + glClearColor(0.0, 0.0, 0.0, 0.0);
  278 + glDisable(GL_TEXTURE_2D);
  279 + glDisableClientState(GL_VERTEX_ARRAY);
  280 + glDisableClientState(GL_TEXTURE_COORD_ARRAY);
  281 + glDisable(GL_TEXTURE_GEN_S);
  282 + glDisable(GL_TEXTURE_GEN_T);
  283 + glDisable(GL_TEXTURE_GEN_R);
  284 + glEnable(GL_DEPTH_TEST);
  285 + //glDepthFunc(GL_LESS);
  286 +
  287 +
  288 + //
  289 + /*
  290 + glColor3f(0.0f, 0.0f, 1.0f);
  291 + glActiveTexture(GL_TEXTURE0);
  292 + glEnable(GL_TEXTURE_CUBE_MAP);
  293 + glEnableClientState(GL_VERTEX_ARRAY);
  294 + glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  295 +
  296 + glBindTexture(GL_TEXTURE_CUBE_MAP, _texture);
  297 +
  298 + glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP);
  299 + glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP);
  300 + glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP);
  301 + glEnable(GL_TEXTURE_GEN_S);
  302 + glEnable(GL_TEXTURE_GEN_T);
  303 + glEnable(GL_TEXTURE_GEN_R);
  304 +
  305 +
  306 + glBindBuffer(GL_ARRAY_BUFFER, boxVBO);
  307 + glTexCoordPointer(2, GL_FLOAT, sizeof(float) * 5, (GLvoid*)3);
  308 + glVertexPointer(3, GL_FLOAT, sizeof(float) * 5, (GLvoid*)0);
  309 + glDrawArrays(GL_QUADS, 0, sizeof(vertexBuffer) / sizeof(float) / 5);
  310 + //glFlush();
  311 +
  312 + glDisableClientState(GL_TEXTURE_COORD_ARRAY);
  313 + glDisableClientState(GL_VERTEX_ARRAY);
  314 + glDisable(GL_TEXTURE_CUBE_MAP);
  315 + glDisable(GL_TEXTURE_GEN_S);
  316 + glDisable(GL_TEXTURE_GEN_T);
  317 + glDisable(GL_TEXTURE_GEN_R);
  318 + glClearColor(0.0, 0.0, 0.0, 1.0);
  319 + */
  320 + //glGenTextures(1, ??)
  321 + // Automatic generation of texture coordinates
  322 + /*
  323 + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
  324 + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
  325 + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  326 + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  327 + */
70 328  
  329 + /*
  330 + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 512, 512, 0,
  331 + GL_RGBA, GL_UNSIGNED_BYTE, &_textures[0]);
  332 + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 512, 512, 0,
  333 + GL_RGBA, GL_UNSIGNED_BYTE, &_textures[1]);
  334 + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 512, 512, 0,
  335 + GL_RGBA, GL_UNSIGNED_BYTE, &_textures[2]);
  336 + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 512, 512, 0,
  337 + GL_RGBA, GL_UNSIGNED_BYTE, &_textures[3]);
  338 + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 512, 512, 0,
  339 + GL_RGBA, GL_UNSIGNED_BYTE, &_textures[4]);
  340 + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 512, 512, 0,
  341 + GL_RGBA, GL_UNSIGNED_BYTE, &_textures[5]);
  342 + */
  343 +
  344 +
  345 + //glCullFace(GL_FRONT);
71 346 //glCullFace(GL_BACK);
72 347 //glFrontFace(GL_CW);
73   - glDisable(GL_DEPTH_TEST);
  348 + //glDisable(GL_DEPTH_TEST);
  349 +
74 350 /*
75 351  
76 352  
... ... @@ -88,7 +364,7 @@ void Skybox::privateRender()
88 364  
89 365 glEnable(GL_TEXTURE_2D);
90 366 glBindTexture(GL_TEXTURE_CUBE_MAP, _texture);
91   - */
  367 +
92 368 glEnable(GL_TEXTURE_GEN_S);
93 369 glEnable(GL_TEXTURE_GEN_T);
94 370 glEnable(GL_TEXTURE_GEN_R);
... ... @@ -96,15 +372,7 @@ void Skybox::privateRender()
96 372 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP);
97 373 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP);
98 374 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   - */
  375 +
108 376  
109 377  
110 378 glDisable(GL_TEXTURE_GEN_S);
... ... @@ -112,7 +380,8 @@ void Skybox::privateRender()
112 380 glDisable(GL_TEXTURE_GEN_R);
113 381 glDisable(GL_TEXTURE_CUBE_MAP);
114 382 glEnable(GL_DEPTH_TEST);
115   -
  383 + */
  384 + _skybox.disable();
116 385 }
117 386  
118 387 void Skybox::privateUpdate()
... ...
SpaceShooterV4/src/Water.cpp 0 → 100644
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/Camera.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/SceneObject.obj
No preview for this file type
SpaceShooterV4/x64/Debug/Skybox.obj
No preview for this file type
SpaceShooterV4/x64/Debug/SpaceShip.obj
No preview for this file type
SpaceShooterV4/x64/Debug/SpaceShooterV4.log
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
  1 + GameManager.cpp
  2 + BattleField.cpp
  3 +d:\csmaster\opengl projects\projects\spaceshooterv4\spaceshooterv4\spaceshooterv4\src\battlefield.cpp(137): warning C4267: 'argument': conversion from 'size_t' to 'GLsizei', possible loss of data
  4 + Generating Code...
3 5 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
4 6 LINK : warning LNK4075: ignoring '/INCREMENTAL' due to '/LTCG' specification
5 7 LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
... ...
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/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