summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt11
-rw-r--r--res/Starla.pngbin336 -> 3011 bytes
-rw-r--r--shaders/bloom1.fragment11
-rw-r--r--shaders/bloom2.fragment26
-rw-r--r--shaders/fill.fragment4
-rw-r--r--shaders/final.fragment4
-rw-r--r--shaders/ntsc.fragment4
-rw-r--r--src/game.cpp2
-rw-r--r--src/renderer.cpp34
9 files changed, 54 insertions, 42 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b6ba2f..22bbc1a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt
@@ -17,13 +17,22 @@ find_package(portaudio REQUIRED)
17find_package(libsndfile REQUIRED) 17find_package(libsndfile REQUIRED)
18find_package(libxml2 REQUIRED) 18find_package(libxml2 REQUIRED)
19 19
20IF(APPLE)
21 FIND_LIBRARY(COCOA_LIBRARY Cocoa)
22 FIND_LIBRARY(CV_LIBRARY CoreVideo)
23 FIND_LIBRARY(IO_LIBRARY IOKit)
24 MARK_AS_ADVANCED (COCOA_LIBRARY CV_LIBRARY IO_LIBRARY)
25 SET(EXTRA_LIBS ${COCOA_LIBRARY} ${CV_LIBRARY} ${IO_LIBRARY})
26ENDIF (APPLE)
27
20set(ALL_LIBS 28set(ALL_LIBS
21 ${OPENGL_LIBRARIES} 29 ${OPENGL_gl_LIBRARY}
22 ${GLEW_LIBRARIES} 30 ${GLEW_LIBRARIES}
23 ${GLFW_LIBRARIES} 31 ${GLFW_LIBRARIES}
24 ${PORTAUDIO_LIBRARIES} 32 ${PORTAUDIO_LIBRARIES}
25 ${LIBSNDFILE_LIBRARY} 33 ${LIBSNDFILE_LIBRARY}
26 ${LIBXML2_LIBRARIES} 34 ${LIBXML2_LIBRARIES}
35 ${EXTRA_LIBS}
27) 36)
28 37
29include_directories( 38include_directories(
diff --git a/res/Starla.png b/res/Starla.png index 7c98514..f5b41d7 100644 --- a/res/Starla.png +++ b/res/Starla.png
Binary files differ
diff --git a/shaders/bloom1.fragment b/shaders/bloom1.fragment index 0a89ea1..ed9e10d 100644 --- a/shaders/bloom1.fragment +++ b/shaders/bloom1.fragment
@@ -2,15 +2,16 @@
2 2
3in vec2 UV; 3in vec2 UV;
4 4
5out vec3 color; 5out vec4 color;
6 6
7uniform vec2 offset; 7uniform vec2 offset;
8uniform sampler2D inTex; 8uniform sampler2D inTex;
9 9
10void main() 10void main()
11{ 11{
12 color = vec3(0.0); 12 vec3 mval = vec3(0.0);
13 color += (5.0/16.0) * texture(inTex, UV - offset).rgb; 13 mval += (5.0/16.0) * texture(inTex, UV - offset).rgb;
14 color += (6.0/16.0) * texture(inTex, UV).rgb; 14 mval += (6.0/16.0) * texture(inTex, UV).rgb;
15 color += (5.0/16.0) * texture(inTex, UV + offset).rgb; 15 mval += (5.0/16.0) * texture(inTex, UV + offset).rgb;
16 color = vec4(mval, 1.0);
16} 17}
diff --git a/shaders/bloom2.fragment b/shaders/bloom2.fragment index 4c50e86..6723c2c 100644 --- a/shaders/bloom2.fragment +++ b/shaders/bloom2.fragment
@@ -2,7 +2,7 @@
2 2
3in vec2 UV; 3in vec2 UV;
4 4
5out vec3 color; 5out vec4 color;
6 6
7uniform sampler2D clearTex; 7uniform sampler2D clearTex;
8uniform sampler2D blurTex; 8uniform sampler2D blurTex;
@@ -15,19 +15,21 @@ float nrand(vec2 n)
15 15
16void main() 16void main()
17{ 17{
18 color = vec3(0.0); 18 vec3 mval = vec3(0.0);
19 color += texture(clearTex, UV).rgb / 2.0; 19 mval += texture(clearTex, UV).rgb / 2.0;
20 color += texture(blurTex, UV).rgb; 20 mval += texture(blurTex, UV).rgb;
21 color = max(vec3(0.0), color - 0.5); 21 mval = max(vec3(0.0), mval - 0.5);
22 color *= color; 22 mval *= mval;
23 23
24 float flicker = 0.5 + nrand(vec2(iGlobalTime)); 24 float flicker = 0.5 + nrand(vec2(iGlobalTime));
25 flicker *= (flicker); 25 flicker *= (flicker);
26 //flicker = sqrt(flicker); 26 //flicker = sqrt(flicker);
27 //flicker = pow(flicker, 1.0/8.0); 27 //flicker = pow(flicker, 1.0/8.0);
28 //color *= flicker; 28 //mval *= flicker;
29 color *= mix(vec3(0.0), color, flicker); 29 mval *= mix(vec3(0.0), mval, flicker);
30 30
31 color += texture(clearTex, UV).rgb; 31 mval += texture(clearTex, UV).rgb;
32 color = clamp(color, vec3(0.0), vec3(1.0)); 32 mval = clamp(mval, vec3(0.0), vec3(1.0));
33
34 color = vec4(mval, 1.0);
33} 35}
diff --git a/shaders/fill.fragment b/shaders/fill.fragment index ab7d9c9..81443c4 100644 --- a/shaders/fill.fragment +++ b/shaders/fill.fragment
@@ -1,10 +1,10 @@
1#version 330 core 1#version 330 core
2 2
3out vec3 color; 3out vec4 color;
4 4
5uniform vec3 vecColor; 5uniform vec3 vecColor;
6 6
7void main() 7void main()
8{ 8{
9 color = vecColor; 9 color = vec4(vecColor, 1.0);
10} 10}
diff --git a/shaders/final.fragment b/shaders/final.fragment index a3ee243..9a39597 100644 --- a/shaders/final.fragment +++ b/shaders/final.fragment
@@ -5,7 +5,7 @@ in vec3 normIn;
5in vec3 camDirIn; 5in vec3 camDirIn;
6in vec3 lightDirIn; 6in vec3 lightDirIn;
7 7
8out vec3 color; 8out vec4 color;
9 9
10uniform sampler2D rendertex; 10uniform sampler2D rendertex;
11uniform sampler2D scanlinestex; 11uniform sampler2D scanlinestex;
@@ -71,5 +71,5 @@ void main()
71 vec4 nearfinal = colorfres + colordiff + colorspec + emissive; 71 vec4 nearfinal = colorfres + colordiff + colorspec + emissive;
72 //vec4 final = nearfinal * mix(vec4(1,1,1,1), vec4(0,0,0, 0), Tuning_Dimming); 72 //vec4 final = nearfinal * mix(vec4(1,1,1,1), vec4(0,0,0, 0), Tuning_Dimming);
73 73
74 color = nearfinal.rgb; 74 color = nearfinal;
75} 75}
diff --git a/shaders/ntsc.fragment b/shaders/ntsc.fragment index 56fb1c4..d6ae904 100644 --- a/shaders/ntsc.fragment +++ b/shaders/ntsc.fragment
@@ -2,7 +2,7 @@
2 2
3in vec2 UV; 3in vec2 UV;
4 4
5out vec3 color; 5out vec4 color;
6 6
7uniform sampler2D curFrameSampler; 7uniform sampler2D curFrameSampler;
8uniform sampler2D NTSCArtifactSampler; 8uniform sampler2D NTSCArtifactSampler;
@@ -61,5 +61,5 @@ void main()
61 Cur_Local = clamp(Cur_Local + (offset * Tuning_Sharp * mix(vec4(1,1,1,1), NTSCArtifact, Tuning_NTSC)), vec4(0,0,0,0), vec4(1,1,1,1)); 61 Cur_Local = clamp(Cur_Local + (offset * Tuning_Sharp * mix(vec4(1,1,1,1), NTSCArtifact, Tuning_NTSC)), vec4(0,0,0,0), vec4(1,1,1,1));
62 Cur_Local = clamp(max(Cur_Local, Tuning_Persistence * (1.0 / (1.0 + (2.0 * Tuning_Bleed))) * (Prev_Local + ((Prev_Left + Prev_Right) * Tuning_Bleed))), vec4(0,0,0,0), vec4(1,1,1,1)); 62 Cur_Local = clamp(max(Cur_Local, Tuning_Persistence * (1.0 / (1.0 + (2.0 * Tuning_Bleed))) * (Prev_Local + ((Prev_Left + Prev_Right) * Tuning_Bleed))), vec4(0,0,0,0), vec4(1,1,1,1));
63 63
64 color = Cur_Local.xyz; 64 color = vec4(Cur_Local.rgb, 1.0);
65} 65}
diff --git a/src/game.cpp b/src/game.cpp index 39bb3f1..1182689 100644 --- a/src/game.cpp +++ b/src/game.cpp
@@ -40,7 +40,7 @@ Game::Game(
40 40
41 int player = entityManager_.emplaceEntity(); 41 int player = entityManager_.emplaceEntity();
42 42
43 AnimationSet playerGraphics {"res/Starla2.bmp", 10, 12, 6}; 43 AnimationSet playerGraphics {"res/Starla.png", 10, 12, 6};
44 playerGraphics.emplaceAnimation("stillLeft", 3, 1, 1); 44 playerGraphics.emplaceAnimation("stillLeft", 3, 1, 1);
45 playerGraphics.emplaceAnimation("stillRight", 0, 1, 1); 45 playerGraphics.emplaceAnimation("stillRight", 0, 1, 1);
46 playerGraphics.emplaceAnimation("walkingLeft", 4, 2, 10); 46 playerGraphics.emplaceAnimation("walkingLeft", 4, 2, 10);
diff --git a/src/renderer.cpp b/src/renderer.cpp index 3945e09..f840180 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp
@@ -33,8 +33,6 @@ static GLuint bloom1Shader;
33static GLuint bloom2Shader; 33static GLuint bloom2Shader;
34 34
35// The buffers for the NTSC rendering process 35// The buffers for the NTSC rendering process
36static GLuint renderedTex1;
37static GLuint renderedTex2;
38static GLuint renderedTexBufs[2]; 36static GLuint renderedTexBufs[2];
39static int curBuf; 37static int curBuf;
40static GLuint artifactsTex; 38static GLuint artifactsTex;
@@ -148,6 +146,10 @@ void flipImageData(unsigned char* data, int width, int height, int comps)
148 146
149void loadMesh(const char* filename, std::vector<glm::vec3>& out_vertices, std::vector<glm::vec2>& out_uvs, std::vector<glm::vec3>& out_normals) 147void loadMesh(const char* filename, std::vector<glm::vec3>& out_vertices, std::vector<glm::vec2>& out_uvs, std::vector<glm::vec3>& out_normals)
150{ 148{
149 out_vertices.clear();
150 out_uvs.clear();
151 out_normals.clear();
152
151 FILE* file = fopen(filename, "r"); 153 FILE* file = fopen(filename, "r");
152 if (file == nullptr) 154 if (file == nullptr)
153 { 155 {
@@ -308,34 +310,33 @@ GLFWwindow* initRenderer()
308 GLenum DrawBuffers2[1] = {GL_COLOR_ATTACHMENT1}; 310 GLenum DrawBuffers2[1] = {GL_COLOR_ATTACHMENT1};
309 glDrawBuffers(1, DrawBuffers2); 311 glDrawBuffers(1, DrawBuffers2);
310 312
313 glfwGetFramebufferSize(window, &buffer_width, &buffer_height);
314
311 glGenRenderbuffers(1, &bloom_depthbuffer); 315 glGenRenderbuffers(1, &bloom_depthbuffer);
312 glBindRenderbuffer(GL_RENDERBUFFER, bloom_depthbuffer); 316 glBindRenderbuffer(GL_RENDERBUFFER, bloom_depthbuffer);
313 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, 1024, 768); 317 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, buffer_width, buffer_height);
314 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, bloom_depthbuffer); 318 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, bloom_depthbuffer);
315 319
316 // Set up the NTSC rendering buffers 320 // Set up the NTSC rendering buffers
317 glGenTextures(1, &renderedTex1); 321 glGenTextures(2, renderedTexBufs);
318 glBindTexture(GL_TEXTURE_2D, renderedTex1); 322 glBindTexture(GL_TEXTURE_2D, renderedTexBufs[0]);
319 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, GAME_WIDTH, GAME_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); 323 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, GAME_WIDTH, GAME_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
320 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 324 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
321 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 325 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
322 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 326 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
323 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 327 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
324 renderedTexBufs[0] = renderedTex1;
325 328
326 glGenTextures(1, &renderedTex2); 329 glBindTexture(GL_TEXTURE_2D, renderedTexBufs[1]);
327 glBindTexture(GL_TEXTURE_2D, renderedTex2);
328 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, GAME_WIDTH, GAME_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); 330 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, GAME_WIDTH, GAME_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
329 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 331 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
330 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 332 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
331 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 333 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
332 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 334 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
333 renderedTexBufs[1] = renderedTex2;
334 335
335 // Set up bloom rendering buffers 336 // Set up bloom rendering buffers
336 glGenTextures(1, &preBloomTex); 337 glGenTextures(1, &preBloomTex);
337 glBindTexture(GL_TEXTURE_2D, preBloomTex); 338 glBindTexture(GL_TEXTURE_2D, preBloomTex);
338 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1024, 768, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); 339 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, buffer_width, buffer_height, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
339 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 340 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
340 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 341 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
341 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 342 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
@@ -343,7 +344,7 @@ GLFWwindow* initRenderer()
343 344
344 glGenTextures(1, &bloomPassTex1); 345 glGenTextures(1, &bloomPassTex1);
345 glBindTexture(GL_TEXTURE_2D, bloomPassTex1); 346 glBindTexture(GL_TEXTURE_2D, bloomPassTex1);
346 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1024/4, 768/4, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); 347 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, buffer_width/4, buffer_height/4, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
347 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 348 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
348 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 349 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
349 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 350 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
@@ -351,7 +352,7 @@ GLFWwindow* initRenderer()
351 352
352 glGenTextures(1, &bloomPassTex2); 353 glGenTextures(1, &bloomPassTex2);
353 glBindTexture(GL_TEXTURE_2D, bloomPassTex2); 354 glBindTexture(GL_TEXTURE_2D, bloomPassTex2);
354 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1024/4, 768/4, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); 355 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, buffer_width/4, buffer_height/4, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
355 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 356 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
356 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 357 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
357 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 358 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
@@ -370,15 +371,15 @@ GLFWwindow* initRenderer()
370 371
371 glGenBuffers(1, &mesh_vertexbuffer); 372 glGenBuffers(1, &mesh_vertexbuffer);
372 glBindBuffer(GL_ARRAY_BUFFER, mesh_vertexbuffer); 373 glBindBuffer(GL_ARRAY_BUFFER, mesh_vertexbuffer);
373 glBufferData(GL_ARRAY_BUFFER, mesh_vertices.size() * sizeof(glm::vec3), &mesh_vertices[0], GL_STATIC_DRAW); 374 glBufferData(GL_ARRAY_BUFFER, mesh_vertices.size() * sizeof(glm::vec3), mesh_vertices.data(), GL_STATIC_DRAW);
374 375
375 glGenBuffers(1, &mesh_uvbuffer); 376 glGenBuffers(1, &mesh_uvbuffer);
376 glBindBuffer(GL_ARRAY_BUFFER, mesh_uvbuffer); 377 glBindBuffer(GL_ARRAY_BUFFER, mesh_uvbuffer);
377 glBufferData(GL_ARRAY_BUFFER, mesh_uvs.size() * sizeof(glm::vec3), &mesh_uvs[0], GL_STATIC_DRAW); 378 glBufferData(GL_ARRAY_BUFFER, mesh_uvs.size() * sizeof(glm::vec2), mesh_uvs.data(), GL_STATIC_DRAW);
378 379
379 glGenBuffers(1, &mesh_normalbuffer); 380 glGenBuffers(1, &mesh_normalbuffer);
380 glBindBuffer(GL_ARRAY_BUFFER, mesh_normalbuffer); 381 glBindBuffer(GL_ARRAY_BUFFER, mesh_normalbuffer);
381 glBufferData(GL_ARRAY_BUFFER, mesh_normals.size() * sizeof(glm::vec3), &mesh_normals[0], GL_STATIC_DRAW); 382 glBufferData(GL_ARRAY_BUFFER, mesh_normals.size() * sizeof(glm::vec3), mesh_normals.data(), GL_STATIC_DRAW);
382 383
383 // Load the vertices of a flat surface 384 // Load the vertices of a flat surface
384 GLfloat g_quad_vertex_buffer_data[] = { 385 GLfloat g_quad_vertex_buffer_data[] = {
@@ -452,8 +453,7 @@ void destroyRenderer()
452 glDeleteProgram(bloom2Shader); 453 glDeleteProgram(bloom2Shader);
453 454
454 // Delete the NTSC rendering buffers 455 // Delete the NTSC rendering buffers
455 glDeleteTextures(1, &renderedTex1); 456 glDeleteTextures(2, renderedTexBufs);
456 glDeleteTextures(1, &renderedTex2);
457 glDeleteTextures(1, &artifactsTex); 457 glDeleteTextures(1, &artifactsTex);
458 glDeleteTextures(1, &scanlinesTex); 458 glDeleteTextures(1, &scanlinesTex);
459 glDeleteTextures(1, &preBloomTex); 459 glDeleteTextures(1, &preBloomTex);