Starting up on skybox work
This commit is contained in:
parent
1525f40a24
commit
2457231dbd
BIN
BaseGLProject/Models/skybox/back.JPG
Normal file
BIN
BaseGLProject/Models/skybox/back.JPG
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
BIN
BaseGLProject/Models/skybox/down.JPG
Normal file
BIN
BaseGLProject/Models/skybox/down.JPG
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.3 KiB |
BIN
BaseGLProject/Models/skybox/front.JPG
Normal file
BIN
BaseGLProject/Models/skybox/front.JPG
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
BIN
BaseGLProject/Models/skybox/left.JPG
Normal file
BIN
BaseGLProject/Models/skybox/left.JPG
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 22 KiB |
BIN
BaseGLProject/Models/skybox/right.JPG
Normal file
BIN
BaseGLProject/Models/skybox/right.JPG
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 28 KiB |
BIN
BaseGLProject/Models/skybox/top.jpg
Normal file
BIN
BaseGLProject/Models/skybox/top.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 80 KiB |
@ -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
96
BaseGLProject/Skybox.cpp
Normal 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
25
BaseGLProject/Skybox.h
Normal 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();
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user