-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSkybox.cpp
More file actions
98 lines (83 loc) · 2.46 KB
/
Skybox.cpp
File metadata and controls
98 lines (83 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// Created by adamyuan on 4/24/18.
//
#include "Skybox.hpp"
#include "Resources.hpp"
#include <iostream>
void Skybox::Initialize()
{
texture_.Initialize();
texture_.Bind();
for(int i = 0; i < 6; ++i)
{
std::string filename{"skybox/"};
filename += std::to_string(i) + ".png";
mygl3::ImageLoader skybox{filename.c_str()};
const mygl3::ImageInfo &info = skybox.GetInfo();
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, info.internal_format,
info.width, info.height, 0,
info.format, info.type, info.data);
}
glGenerateMipmap(GL_TEXTURE_CUBE_MAP);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
float skybox_vertices[] =
{
// positions
-1.0f, 1.0f, -1.0f,
-1.0f, -1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, -1.0f,
-1.0f, -1.0f, 1.0f,
-1.0f, -1.0f, -1.0f,
-1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, 1.0f,
-1.0f, -1.0f, 1.0f,
1.0f, -1.0f, -1.0f,
1.0f, -1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, -1.0f, 1.0f,
-1.0f, -1.0f, 1.0f,
-1.0f, 1.0f, -1.0f,
1.0f, 1.0f, -1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,
-1.0f, 1.0f, -1.0f,
-1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, 1.0f,
1.0f, -1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, 1.0f,
1.0f, -1.0f, 1.0f
};
object_.Initialize();
object_.SetData(skybox_vertices, 108, GL_STATIC_DRAW);
object_.SetAttributes(0, 3);
shader_.Initialize();
shader_.SetUProjection(res::cam_projection);
}
void Skybox::Render()
{
glDepthFunc(GL_LEQUAL); // change depth function so depth test passes when values are equal to depth buffer's content
glCullFace(GL_BACK);
glm::mat4 view = glm::mat4(glm::mat3(res::cam_view));
shader_.SetUView(res::cam_view);
texture_.Bind(0);
shader_.Use();
object_.Render(GL_TRIANGLES);
glDepthFunc(GL_LESS); // set depth function back to default
}