Starting up on skybox work

This commit is contained in:
Hugo Willaume 2019-04-02 07:59:39 +09:00
parent 1525f40a24
commit 2457231dbd
9 changed files with 122 additions and 1 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

View File

@ -161,7 +161,7 @@ void MyGlWindow::setup()
//meshes.emplace("Mountain", new Mesh("mountain/mount.blend1.obj", shaders["TexBaseLight"]));
meshes.emplace("Sponza", new Mesh("sponza/sponza.obj", shaders["TexBaseLight"]));
meshes["Sponza"]->addTranslation(glm::vec4(0, -200, 0, 1));
//meshes["Sponza"]->addTranslation(glm::vec4(0, -200, 0, 1));

96
BaseGLProject/Skybox.cpp Normal file
View File

@ -0,0 +1,96 @@
#include "Skybox.h"
Skybox::Skybox()
{
float side = 50.0f; //size of cube
float side2 = side / 2.0f;
float v[24 * 3] = {
// Front
-side2, -side2, side2,
side2, -side2, side2,
side2, side2, side2,
-side2, side2, side2,
// Right
side2, -side2, side2,
side2, -side2, -side2,
side2, side2, -side2,
side2, side2, side2,
// Back
-side2, -side2, -side2,
-side2, side2, -side2,
side2, side2, -side2,
side2, -side2, -side2,
// Left
-side2, -side2, side2, //12
-side2, side2, side2, //13
-side2, side2, -side2, //14
-side2, -side2, -side2, //15
// Bottom
-side2, -side2, side2,
-side2, -side2, -side2,
side2, -side2, -side2,
side2, -side2, side2,
// Top
-side2, side2, side2,
side2, side2, side2,
side2, side2, -side2,
-side2, side2, -side2
};
GLuint el[] = {
0,2,1, 0,3,2, 4,6,5, 4,7,6,
8,10,9, 8,11,10, 12,14,13, 12,15,14,
16,18,17, 16,19,18, 20,22,21, 20,23,22
};
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glGenBuffers(1, &vector_vbo);
glBindBuffer(GL_ARRAY_BUFFER, vector_vbo);
glBufferData(GL_ARRAY_BUFFER, 24 * 3 * sizeof(GLfloat), v, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 3, NULL);
glEnableVertexAttribArray(0);
glGenBuffers(1, &ibo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, 36 * sizeof(GLuint), el, GL_STATIC_DRAW);
glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, 0, NULL);
glEnableVertexAttribArray(4);
glActiveTexture(GL_TEXTURE0);
glGenTextures(1, &texID); //set the texID as a member variable
glBindTexture(GL_TEXTURE_CUBE_MAP, texID);
const char * suffixes[] = { "left", "right", "top", "down", "back", "front" };
GLuint targets[] = {
GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
};
for (int i = 0; i < 6; i++) {
int channel;
int width, height;
std::string filename;
filename = std::string("Models/skybox/" + suffixes[i]) + string(".jpg");
unsigned char * image = SOIL_load_image(filename.c_str(), &width, &height, &channel, SOIL_LOAD_RGB);
glTexImage2D(targets[i], 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
glGenerateMipmap(GL_TEXTURE_2D);
SOIL_free_image_data(image);
}
}
Skybox::~Skybox()
{
}
void Skybox::draw()
{
}

25
BaseGLProject/Skybox.h Normal file
View File

@ -0,0 +1,25 @@
#pragma once
#include <string>
#include <iostream>
#include <vector>
#include <GL/glew.h>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/mat4x4.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/matrix_inverse.hpp>
#include "Loader.h"
class Skybox
{
private:
unsigned int vao;
unsigned int vector_vbo;
unsigned int ibo;
GLuint texID;
public:
Skybox();
~Skybox();
void draw();
};