-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoverScene.cpp
More file actions
127 lines (106 loc) · 3.53 KB
/
overScene.cpp
File metadata and controls
127 lines (106 loc) · 3.53 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "stdafx.h"
#include "overScene.h"
#include "stb_image.h"
extern GameFramework GameManager;
overScene::~overScene()
{
//메모리 해제
vertices_back.clear();
vertices_back.shrink_to_fit();
uvs_back.clear();
uvs_back.shrink_to_fit();
normals_back.clear();
normals_back.shrink_to_fit();
glDeleteShader(ourShader2.ID);
}
void overScene::InitTexture() {
ourShader2.use();
int width;
int height;
int numberOfChannel;
//glGenTextures(1, &texture);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, GL_TEXTURE0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
unsigned char* data1 = stbi_load("over.bmp", &width, &height, &numberOfChannel, 0);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data1);
glGenerateMipmap(GL_TEXTURE_2D);
stbi_image_free(data1);
glUseProgram(0);
}
void overScene::init()
{
loadOBJ("wall.obj", vertices_back, uvs_back, normals_back);
ourShader2.InitShader("vertex2.glsl", "fragment2.glsl"); // 텍스처용쉐이더 생성
ourShader2.use();
glGenVertexArrays(1, &VAO_back);
glGenBuffers(2, VBO_back_position);
//wall 정점버퍼
glBindVertexArray(VAO_back);
glBindBuffer(GL_ARRAY_BUFFER, VBO_back_position[0]);
glBufferData(GL_ARRAY_BUFFER, vertices_back.size() * sizeof(glm::vec3), &vertices_back[0], GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), 0);
glEnableVertexAttribArray(0);
//wall uv버퍼
glBindBuffer(GL_ARRAY_BUFFER, VBO_back_position[1]);
glBufferData(GL_ARRAY_BUFFER, uvs_back.size() * sizeof(glm::vec2), &uvs_back[0], GL_STATIC_DRAW);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), 0);
glEnableVertexAttribArray(1);
InitTexture();
glBindVertexArray(0);
glUseProgram(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
void overScene::processKey(unsigned char key, int x, int y)
{
switch (key)
{
case 'q':
glutLeaveMainLoop();
break;
case 's':
if (stage == 1) {
scene* scene = GameManager.curScene; ////현재 씬을 tmp에 넣고 지워줌
GameManager.curScene = new gameScene;
GameManager.curScene->stage = 1;
GameManager.curScene->init();
GameManager.nowscene = GAME; //다시시작
delete scene;
}
else {
scene* scene = GameManager.curScene; ////현재 씬을 tmp에 넣고 지워줌
GameManager.curScene = new gameScene;
GameManager.curScene->stage = 2;
GameManager.curScene->init();
GameManager.nowscene = GAME; //다시시작
delete scene;
}
break;
}
}
void overScene::Mouse(int button, int state, int x, int y)
{
}
void overScene::MouseMotion(int x, int y)
{
}
void overScene::Update(const float frameTime)
{
}
void overScene::Render()
{
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
ourShader2.use();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, GL_TEXTURE0);
int tLocation1 = glGetUniformLocation(ourShader2.ID, "texture1");
glUniform1i(tLocation1, 0);
glBindVertexArray(VAO_back);
glDrawArrays(GL_TRIANGLES, 0, vertices_back.size());
glBindVertexArray(0);
glUseProgram(0);
}