|
|
|
@ -297,12 +297,12 @@ class SDLGLGLWindow {
@@ -297,12 +297,12 @@ class SDLGLGLWindow {
|
|
|
|
|
int width, height, nrChannels; |
|
|
|
|
stbi_set_flip_vertically_on_load(true); |
|
|
|
|
glGenTextures(2, texture); |
|
|
|
|
unsigned char *data = stbi_load("src/assets/blending_transparent_window.png", &width, &height, &nrChannels, 0); |
|
|
|
|
unsigned char *data = stbi_load("src/assets/container.jpg", &width, &height, &nrChannels, 0); |
|
|
|
|
|
|
|
|
|
if (data) {
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, texture[0]); |
|
|
|
|
glCheckError(); |
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); |
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data); |
|
|
|
|
|
|
|
|
|
glGenerateMipmap(GL_TEXTURE_2D); |
|
|
|
|
glCheckError(); |
|
|
|
@ -422,22 +422,23 @@ class SDLGLGLWindow {
@@ -422,22 +422,23 @@ class SDLGLGLWindow {
|
|
|
|
|
glGenBuffers( 1, &gVBO ); |
|
|
|
|
|
|
|
|
|
glBindVertexArray(gVAO); |
|
|
|
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, gVBO); |
|
|
|
|
glBufferData( GL_ARRAY_BUFFER, sizeof cubeVertices, cubeVertices, GL_STATIC_DRAW ); |
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
unsigned int gVertexPos2DLocation = shader->get_attrib("LVertexPos2D"); |
|
|
|
|
unsigned int gtexlocation = shader->get_attrib("aTexCoords"); |
|
|
|
|
unsigned int normloc = shader->get_attrib( "aNormal" ); |
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
glVertexAttribPointer( gVertexPos2DLocation, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), NULL); |
|
|
|
|
glVertexAttribPointer( normloc, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (void *)(3 * sizeof (float))); |
|
|
|
|
glVertexAttribPointer(gtexlocation, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (void *)(6 * sizeof(float))); |
|
|
|
|
glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), NULL); |
|
|
|
|
glVertexAttribPointer( 1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (void *)(3 * sizeof (float))); |
|
|
|
|
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (void *)(6 * sizeof(float))); |
|
|
|
|
|
|
|
|
|
glCheckError(); |
|
|
|
|
glEnableVertexAttribArray(gtexlocation); |
|
|
|
|
glEnableVertexAttribArray(gVertexPos2DLocation); |
|
|
|
|
glEnableVertexAttribArray(normloc); |
|
|
|
|
glEnableVertexAttribArray(0); |
|
|
|
|
glCheckError(); |
|
|
|
|
glEnableVertexAttribArray(1); |
|
|
|
|
glCheckError(); |
|
|
|
|
glEnableVertexAttribArray(2); |
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
/*********** ENDCUBES **************/ |
|
|
|
@ -605,35 +606,6 @@ class SDLGLGLWindow {
@@ -605,35 +606,6 @@ class SDLGLGLWindow {
|
|
|
|
|
|
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
/** draw skybox cubemap */ |
|
|
|
|
// glPolygonMode( GL_FRONT_AND_BACK, GL_LINE);
|
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
glDepthMask(GL_FALSE); |
|
|
|
|
glCheckError(); |
|
|
|
|
skyboxShader->use(); |
|
|
|
|
glCheckError(); |
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
loc = skyboxShader->get_uniform("view"); |
|
|
|
|
glm::mat4 skybox_view = glm::mat4(glm::mat3(view)); |
|
|
|
|
glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(skybox_view)); |
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
loc = skyboxShader->get_uniform("projection");
|
|
|
|
|
glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(projection)); |
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
glBindVertexArray(gVAO); |
|
|
|
|
glBindTexture(GL_TEXTURE_CUBE_MAP, cubemap); |
|
|
|
|
glCheckError(); |
|
|
|
|
glDrawArrays(GL_TRIANGLES, 0, 36); |
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
glDepthMask(GL_TRUE); |
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
printProgramLog(skyboxShader->program); |
|
|
|
|
/** Draw guitar backpack **/ |
|
|
|
|
shader->use(); |
|
|
|
|
glCheckError(); |
|
|
|
@ -647,13 +619,14 @@ class SDLGLGLWindow {
@@ -647,13 +619,14 @@ class SDLGLGLWindow {
|
|
|
|
|
glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(view)); |
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_CUBE_MAP, cubemap); |
|
|
|
|
bp_model->draw(*shader); |
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
//*** Draw random cubes ****/
|
|
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, texture[0]); |
|
|
|
|
shader->use(); |
|
|
|
|
glBindVertexArray(gVAO); |
|
|
|
|
glBindTexture(GL_TEXTURE_2D, texture[0]); |
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
std::map<float, glm::vec3> sorted; |
|
|
|
@ -666,6 +639,7 @@ class SDLGLGLWindow {
@@ -666,6 +639,7 @@ class SDLGLGLWindow {
|
|
|
|
|
|
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
shader->use(); |
|
|
|
|
for(auto it = sorted.rbegin(); it != sorted.rend(); ++it) { |
|
|
|
|
|
|
|
|
|
model = glm::mat4(1.0f); |
|
|
|
@ -682,7 +656,10 @@ class SDLGLGLWindow {
@@ -682,7 +656,10 @@ class SDLGLGLWindow {
|
|
|
|
|
loc = shader->get_uniform("projection");
|
|
|
|
|
glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(projection)); |
|
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_CUBE_MAP, cubemap); |
|
|
|
|
glCheckError(); |
|
|
|
|
glDrawArrays(GL_TRIANGLES, 0, 36); |
|
|
|
|
glCheckError(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
@ -706,6 +683,44 @@ class SDLGLGLWindow {
@@ -706,6 +683,44 @@ class SDLGLGLWindow {
|
|
|
|
|
//
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** draw skybox cubemap */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glCheckError(); |
|
|
|
|
skyboxShader->use(); |
|
|
|
|
glDepthFunc(GL_LEQUAL);
|
|
|
|
|
glCheckError(); |
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
loc = skyboxShader->get_uniform("view"); |
|
|
|
|
glm::mat4 skybox_view = glm::mat4(glm::mat3(view)); |
|
|
|
|
glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(skybox_view)); |
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
loc = skyboxShader->get_uniform("projection");
|
|
|
|
|
glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(projection)); |
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
glBindVertexArray(gVAO); |
|
|
|
|
glBindTexture(GL_TEXTURE_CUBE_MAP, cubemap); |
|
|
|
|
glCheckError(); |
|
|
|
|
glDrawArrays(GL_TRIANGLES, 0, 36); |
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
printProgramLog(skyboxShader->program); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glCheckError(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|