-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
336 lines (284 loc) · 9.28 KB
/
main.cpp
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
#include <iostream>
#include "glad/glad.h"
#include "GLFW/glfw3.h"
#include "stb_image.h"
#include "aep-core/shader.h"
#include "aep-core/gl_aux.h"
#include "aep-core/AEPFilter.h"
#include "aep-core/AEPComposer.h"
using namespace std;
// settings
static unsigned int SCR_WIDTH = 800;
static unsigned int SCR_HEIGHT = 600;
static void framebuffer_size_callback(GLFWwindow* window, int width, int height);
static CShader* createShader_sample();
static void processInput(GLFWwindow* window);
static unsigned int makeVAO();
int demo_filter()
{
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
if (window == NULL)
{
std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
std::cout << "Failed to initialize GLAD" << std::endl;
return -1;
}
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
ImageTexture* pIT = createImageTexture((char*)"resources/7-enh-qua.jpg");
if (pIT == NULL)
return -1;
CShader* pShader = createShader_sample();
unsigned int texture = createTexture_from_image((char*)"resources/7-enh-qua.jpg");
unsigned int VAO = makeVAO();
pShader->use();
pShader->setInt("texture1", 0);
unsigned int textureColorMap = createTexture_from_image((char*)"resources/filterColor/industry.png");
unsigned int textureTarget = createTexture_from_image((char*)"resources/he-base.jpg");
CAEPFilter* pEffect = new CAEPFilter((char*)"./shader/filter-0-copy.vs", (char*)"./shader/filter-0-copy.fs");
//CAEPFilter* pEffect = new CAEPFilter((char*)"./shader/transition_turnpage.vs", (char*)"./shader/transition_turnpage.fs", FM_Transition);
if (pEffect->Open(pIT->_width, pIT->_height) != 0)
return -1;
//pEffect->Set_ColorMap(textureColorMap);
pEffect->Set_TransitionTarget(textureTarget);
// render loop
// -----------
int count1 = 0;
while (!glfwWindowShouldClose(window))
{
// input
// -----
processInput(window);
#if 1
float fProcess = float(count1%1000) / 1000;
//fProcess = count1*10;
//fProcess = 0.01 * count1;
count1++;
pEffect->Render(fProcess, pIT->_textureID);
glViewport(0, 0, SCR_WIDTH, SCR_HEIGHT);
static int count = 0;
//cout << count++ << endl;
//#else
// render
// ------
glClearColor(0.9f, 0.9f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
// bind Texture
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, pEffect->Get_textureOut());
//glBindTexture(GL_TEXTURE_2D, texture);
// render container
pShader->use();
glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
#endif
// glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)
// -------------------------------------------------------------------------------
glfwSwapBuffers(window);
glfwPollEvents();
}
// optional: de-allocate all resources once they've outlived their purpose:
// ------------------------------------------------------------------------
glDeleteVertexArrays(1, &VAO);
//glDeleteBuffers(1, &VBO);
//glDeleteBuffers(1, &EBO);
// glfw: terminate, clearing all previously allocated GLFW resources.
// ------------------------------------------------------------------
glfwTerminate();
return 0;
}
void set_desc_default(LayerDesc* pDesc, int index)
{
pDesc->_nStartTime_ms = 0;
pDesc->_nEndTime_ms = 100 * 1000;
pDesc->_fStartRotateAngle = 0;
pDesc->_fEndRotateAngle = 360*2;
pDesc->_vecStartPos[0].x = 0.0;
pDesc->_vecStartPos[0].y = 0.0;
pDesc->_vecStartPos[1].x = 1.0;
pDesc->_vecStartPos[1].y = 1.0;
if (index == 0)
{
pDesc->_vecEndPos[0].x = 0.5;
pDesc->_vecEndPos[0].y = 0.5;
pDesc->_vecEndPos[1].x = 1.0;
pDesc->_vecEndPos[1].y = 1.0;
pDesc->_fStartAlpha = 0;
pDesc->_fEndAlpha = 1.0;
}
else
{
pDesc->_vecEndPos[0].x = 0.1;
pDesc->_vecEndPos[0].y = 0.1;
pDesc->_vecEndPos[1].x = 0.3;
pDesc->_vecEndPos[1].y = 0.3;
pDesc->_fStartAlpha = 1.0;
pDesc->_fEndAlpha = 0.0;
}
pDesc->_szImageName = (char *)"resources/he-base.jpg";
pDesc->_eEffectType = ET_TRANSITION;
//pDesc->_eEffectType = ET_NONE;
pDesc->_szTransitionTarget = (char*)"resources/7-enh-qua.jpg";
}
int demo_composer()
{
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "COMPOSER", NULL, NULL);
if (window == NULL)
{
std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
std::cout << "Failed to initialize GLAD" << std::endl;
return -1;
}
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
ImageTexture* pIT = createImageTexture((char*)"resources/7-enh-qua.jpg");
if (pIT == NULL)
return -1;
CShader* pShader = createShader_sample();
unsigned int texture = createTexture_from_image((char*)"resources/7-enh-qua.jpg");
unsigned int VAO = makeVAO();
pShader->use();
pShader->setInt("texture1", 0);
CAEPComposer* pComposer = new CAEPComposer();
pComposer->Open(SCR_WIDTH, SCR_HEIGHT);
for (int i = 0; i < 2; i++)
{
CAEPLayer* pLayer = new CAEPLayer(pComposer);
LayerDesc desc;
set_desc_default(&desc, i);
pLayer->Open(&desc);
pComposer->Add_Layer(pLayer);
}
// render loop
// -----------
int count1 = 0;
while (!glfwWindowShouldClose(window))
{
// input
// -----
processInput(window);
#if 1
float fProcess = float(count1 % 1000) / 1000;
//fProcess = count1*10;
//fProcess = 0.01 * count1;
count1++;
pComposer->Render(count1*4);
glViewport(0, 0, SCR_WIDTH, SCR_HEIGHT);
static int count = 0;
//cout << count++ << endl;
//#else
// render
// ------
glClearColor(0.9f, 0.9f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
// bind Texture
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, pComposer->Get_textureOut());
//glBindTexture(GL_TEXTURE_2D, texture);
// render container
pShader->use();
glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
#endif
// glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)
// -------------------------------------------------------------------------------
glfwSwapBuffers(window);
glfwPollEvents();
}
// optional: de-allocate all resources once they've outlived their purpose:
// ------------------------------------------------------------------------
glDeleteVertexArrays(1, &VAO);
//glDeleteBuffers(1, &VBO);
//glDeleteBuffers(1, &EBO);
// glfw: terminate, clearing all previously allocated GLFW resources.
// ------------------------------------------------------------------
glfwTerminate();
return 0;
}
int main(int argc, char* argv[])
{
cout << "hi, aep render man!" << endl;
//demo_filter();
demo_composer();
return 0;
}
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
// make sure the viewport matches the new window dimensions; note that width and
// height will be significantly larger than specified on retina displays.
SCR_WIDTH = width;
SCR_HEIGHT = height;
glViewport(0, 0, SCR_WIDTH, SCR_HEIGHT);
}
CShader* createShader_sample()
{
CShader* pShader = new CShader("./shader/filter-0-copy.vs", "./shader/filter-0-copy.fs");
if (pShader == NULL)
{
std::cout << "new shader fail\n";
return NULL;
}
return pShader;
}
void processInput(GLFWwindow* window)
{
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window, true);
}
unsigned int makeVAO()
{
// set up vertex data (and buffer(s)) and configure vertex attributes
// ------------------------------------------------------------------
float vertices[] = {
// positions // colors // texture coords
1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, // top right
1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, // bottom right
-1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, // bottom left
-1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f // top left
};
unsigned int indices[] = {
0, 1, 3, // first triangle
1, 2, 3 // second triangle
};
unsigned int VBO, VAO, EBO;
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
glGenBuffers(1, &EBO);
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
// position attribute
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
// color attribute
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(3 * sizeof(float)));
glEnableVertexAttribArray(1);
// texture coord attribute
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(6 * sizeof(float)));
glEnableVertexAttribArray(2);
return VAO;
}