summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2015-02-14 17:57:23 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2015-02-14 17:57:23 -0500
commit297c093d398e7d6e5fcc5dc6ba1056ede25abf6f (patch)
tree1e55ab169d6de9a6f11b4d3b6efbe9f1b4d6ab6f
parentde5a458cb037bb8e1e80c849c5e6525f9413b43a (diff)
downloadtherapy-297c093d398e7d6e5fcc5dc6ba1056ede25abf6f.tar.gz
therapy-297c093d398e7d6e5fcc5dc6ba1056ede25abf6f.tar.bz2
therapy-297c093d398e7d6e5fcc5dc6ba1056ede25abf6f.zip
Did some lighting and added room name
-rw-r--r--res/arcadepix_regular_8.PNGbin0 -> 3906 bytes
-rw-r--r--res/arcadepix_regular_8.bmpbin0 -> 24632 bytes
-rw-r--r--res/arcadepix_regular_8.sfl94
-rw-r--r--res/font.bmpbin0 -> 49208 bytes
-rw-r--r--src/main.cpp3
-rw-r--r--src/map.cpp17
-rw-r--r--src/renderer.cpp57
-rw-r--r--src/renderer.h2
-rw-r--r--src/translate_font.cpp32
9 files changed, 197 insertions, 8 deletions
diff --git a/res/arcadepix_regular_8.PNG b/res/arcadepix_regular_8.PNG new file mode 100644 index 0000000..5b152aa --- /dev/null +++ b/res/arcadepix_regular_8.PNG
Binary files differ
diff --git a/res/arcadepix_regular_8.bmp b/res/arcadepix_regular_8.bmp new file mode 100644 index 0000000..fc2fd82 --- /dev/null +++ b/res/arcadepix_regular_8.bmp
Binary files differ
diff --git a/res/arcadepix_regular_8.sfl b/res/arcadepix_regular_8.sfl new file mode 100644 index 0000000..b906c01 --- /dev/null +++ b/res/arcadepix_regular_8.sfl
@@ -0,0 +1,94 @@
139 1 3 2 2 0 4 3
296 4 3 4 2 0 4 6
334 9 3 6 2 0 4 8
494 16 3 6 3 0 4 8
545 23 6 5 1 0 7 7
6126 29 5 7 2 1 6 9
760 37 4 4 5 0 5 6
862 42 4 4 5 0 5 6
935 47 4 5 5 0 5 7
1047 53 4 5 5 1 5 8
1161 59 4 5 5 0 5 7
1292 65 4 5 5 1 5 8
1343 71 4 7 5 -1 5 7
1432 79 10 0 0 0 11 8
1591 80 10 0 0 0 11 0
1693 81 10 0 0 0 11 0
17123 82 10 0 0 0 11 0
18124 83 10 0 0 0 11 0
19125 84 10 0 0 0 11 0
2058 85 5 2 5 0 6 3
2146 88 8 2 2 0 9 3
22105 91 1 3 9 0 2 4
2333 95 3 3 7 0 4 4
2440 99 3 3 7 0 4 4
2541 103 3 3 7 0 4 4
26108 107 3 3 7 0 4 4
2736 111 3 5 7 0 4 7
2842 117 3 5 7 0 4 7
29102 1 11 5 7 0 4 7
30116 7 11 5 7 0 4 7
3138 13 11 6 7 0 4 8
3249 20 11 6 7 0 4 8
3373 27 11 6 7 0 4 8
3484 34 11 6 7 0 4 8
3589 41 11 6 7 0 4 8
3698 48 11 6 7 0 4 8
37100 55 11 6 7 0 4 8
38104 62 11 6 7 0 4 8
39107 69 11 6 7 0 4 8
4097 76 12 6 6 0 5 8
4199 83 12 6 6 0 5 8
42101 90 12 6 6 0 5 8
43110 97 12 6 6 0 5 8
44111 104 12 6 6 0 5 8
45114 111 12 6 6 0 5 8
46115 118 12 6 6 0 5 8
47117 1 20 6 6 0 5 8
48118 8 20 6 6 0 5 8
49120 15 20 6 6 0 5 8
50122 22 20 6 6 0 5 8
5137 29 19 7 7 1 4 9
5248 37 19 7 7 1 4 9
5350 45 19 7 7 1 4 9
5451 53 19 7 7 1 4 9
5552 61 19 7 7 1 4 9
5653 69 19 7 7 1 4 9
5754 77 19 7 7 1 4 9
5855 85 19 7 7 1 4 9
5956 93 19 7 7 1 4 9
6057 101 19 7 7 1 4 9
6165 109 19 7 7 1 4 9
6266 117 19 7 7 1 4 9
6367 1 27 7 7 1 4 9
6468 9 27 7 7 1 4 9
6569 17 27 7 7 1 4 9
6670 25 27 7 7 1 4 9
6771 33 27 7 7 1 4 9
6872 41 27 7 7 1 4 9
6974 49 27 7 7 1 4 9
7075 57 27 7 7 1 4 9
7176 65 27 7 7 1 4 9
7277 73 27 7 7 1 4 9
7378 81 27 7 7 1 4 9
7479 89 27 7 7 1 4 9
7580 97 27 7 7 1 4 9
7681 105 27 7 7 1 4 9
7782 113 27 7 7 1 4 9
7883 1 37 7 7 1 4 9
7985 9 37 7 7 1 4 9
8086 17 37 7 7 1 4 9
8187 25 37 7 7 1 4 9
8288 33 37 7 7 1 4 9
8390 41 37 7 7 1 4 9
84109 49 38 7 6 1 5 9
85119 57 38 7 6 1 5 9
8659 65 39 3 6 0 6 4
8744 69 42 3 3 0 9 4
8895 73 44 7 1 0 11 8
8964 81 37 8 8 1 4 10
90106 90 35 4 11 0 2 6
91103 95 38 6 8 0 5 8
92112 102 38 6 8 0 5 8
93113 109 38 6 8 0 5 8
94121 116 38 6 8 0 5 8
diff --git a/res/font.bmp b/res/font.bmp new file mode 100644 index 0000000..498f915 --- /dev/null +++ b/res/font.bmp
Binary files differ
diff --git a/src/main.cpp b/src/main.cpp index a2743d1..7c1a21f 100644 --- a/src/main.cpp +++ b/src/main.cpp
@@ -86,6 +86,7 @@ int main()
86 86
87 while (!quit) 87 while (!quit)
88 { 88 {
89 /*
89 double currentTime = glfwGetTime(); 90 double currentTime = glfwGetTime();
90 nbFrames++; 91 nbFrames++;
91 if ( currentTime - lastTime >= 1.0 ){ // If last prinf() was more than 1 sec ago 92 if ( currentTime - lastTime >= 1.0 ){ // If last prinf() was more than 1 sec ago
@@ -93,7 +94,7 @@ int main()
93 printf("%f ms/frame\n", 1000.0/double(nbFrames)); 94 printf("%f ms/frame\n", 1000.0/double(nbFrames));
94 nbFrames = 0; 95 nbFrames = 0;
95 lastTime += 1.0; 96 lastTime += 1.0;
96 } 97 }*/
97 98
98 if (holding_left && player->x_vel >= 0) 99 if (holding_left && player->x_vel >= 0)
99 { 100 {
diff --git a/src/map.cpp b/src/map.cpp index 10cd313..0dd3e04 100644 --- a/src/map.cpp +++ b/src/map.cpp
@@ -21,9 +21,9 @@ Map::Map()
21 add_collision(GAME_WIDTH+6, 0, GAME_WIDTH, right, 1); 21 add_collision(GAME_WIDTH+6, 0, GAME_WIDTH, right, 1);
22 22
23 FILE* f = fopen("../maps/bigmap.txt", "r"); 23 FILE* f = fopen("../maps/bigmap.txt", "r");
24 char* mapbuf = (char*) malloc(MAP_WIDTH*MAP_HEIGHT*sizeof(char)); 24 char* mapbuf = (char*) malloc(MAP_WIDTH*(MAP_HEIGHT-1)*sizeof(char));
25 25
26 for (int i=0; i<MAP_HEIGHT; i++) 26 for (int i=0; i<MAP_HEIGHT-1; i++)
27 { 27 {
28 fread(mapbuf + i*MAP_WIDTH, sizeof(char), MAP_WIDTH, f); 28 fread(mapbuf + i*MAP_WIDTH, sizeof(char), MAP_WIDTH, f);
29 fgetc(f); 29 fgetc(f);
@@ -35,7 +35,7 @@ Map::Map()
35 bg = createTexture(GAME_WIDTH, GAME_HEIGHT); 35 bg = createTexture(GAME_WIDTH, GAME_HEIGHT);
36 fillTexture(bg, NULL, 0, 0, 0); 36 fillTexture(bg, NULL, 0, 0, 0);
37 37
38 for (int i=0; i<MAP_WIDTH*MAP_HEIGHT; i++) 38 for (int i=0; i<MAP_WIDTH*(MAP_HEIGHT-1); i++)
39 { 39 {
40 int x = i % MAP_WIDTH; 40 int x = i % MAP_WIDTH;
41 int y = i / MAP_WIDTH; 41 int y = i / MAP_WIDTH;
@@ -78,6 +78,17 @@ Map::Map()
78 } 78 }
79 } 79 }
80 80
81 Texture* font = loadTextureFromBMP("../res/font.bmp");
82 const char* map_name = "Everything Is Embarassing";
83 int start_x = (40/2) - (strlen(map_name)/2);
84 for (int i=0; i<strlen(map_name); i++)
85 {
86 Rectangle srcRect(map_name[i] % 16 * 8, map_name[i] / 16 * 8, 8, 8);
87 Rectangle dstRect((start_x + i)*8, 24*8, 8, 8);
88 blitTexture(font, bg, &srcRect, &dstRect);
89 }
90
91 destroyTexture(font);
81 //destroyTexture(tiles); 92 //destroyTexture(tiles);
82} 93}
83 94
diff --git a/src/renderer.cpp b/src/renderer.cpp index e74c6a4..ca356f3 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp
@@ -345,6 +345,36 @@ Texture* loadTextureFromBMP(char* filename)
345 return tex; 345 return tex;
346} 346}
347 347
348void saveTextureToBMP(Texture* tex, char* filename)
349{
350 if (!rendererInitialized)
351 {
352 fprintf(stderr, "Renderer not initialized\n");
353 exit(-1);
354 }
355
356 int size = 54 + 3*tex->width*tex->height;
357
358 char* buf = (char*) calloc(size, sizeof(char));
359 buf[0x00] = 'B';
360 buf[0x01] = 'M';
361 *(int*)&(buf[0x0A]) = 54;
362 *(int*)&(buf[0x12]) = tex->width;
363 *(int*)&(buf[0x16]) = tex->height;
364 *(int*)&(buf[0x1C]) = 24;
365 *(int*)&(buf[0x1E]) = 0;
366 *(int*)&(buf[0x22]) = size;
367
368 glBindTexture(GL_TEXTURE_2D, tex->texID);
369 glGetTexImage(GL_TEXTURE_2D, 0, GL_BGR, GL_UNSIGNED_BYTE, buf + 54);
370
371 FILE* f = fopen(filename, "wb");
372 fwrite(buf, sizeof(char), size, f);
373 fclose(f);
374
375 free(buf);
376}
377
348void fillTexture(Texture* tex, Rectangle* dstrect, int r, int g, int b) 378void fillTexture(Texture* tex, Rectangle* dstrect, int r, int g, int b)
349{ 379{
350 if (!rendererInitialized) 380 if (!rendererInitialized)
@@ -478,15 +508,17 @@ void renderScreen(Texture* tex)
478 exit(-1); 508 exit(-1);
479 } 509 }
480 510
481 // Set up framebuffer 511 // First we're going to composite our frame with the previous frame
512 // We start by setting up the framebuffer
482 glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName); 513 glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
483 glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, renderedTexBufs[curBuf], 0); 514 glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, renderedTexBufs[curBuf], 0);
484 515
485 // Set up renderer 516 // Set up the shaer
486 glViewport(0,0,GAME_WIDTH,GAME_HEIGHT); 517 glViewport(0,0,GAME_WIDTH,GAME_HEIGHT);
487 glClear(GL_COLOR_BUFFER_BIT); 518 glClear(GL_COLOR_BUFFER_BIT);
488 glUseProgram(ntscShader); 519 glUseProgram(ntscShader);
489 520
521 // Use the current frame texture, nearest neighbor and clamped to edge
490 glActiveTexture(GL_TEXTURE0); 522 glActiveTexture(GL_TEXTURE0);
491 glBindTexture(GL_TEXTURE_2D, tex->texID); 523 glBindTexture(GL_TEXTURE_2D, tex->texID);
492 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 524 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@@ -495,6 +527,7 @@ void renderScreen(Texture* tex)
495 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 527 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
496 glUniform1i(glGetUniformLocation(ntscShader, "curFrameSampler"), 0); 528 glUniform1i(glGetUniformLocation(ntscShader, "curFrameSampler"), 0);
497 529
530 // Use the previous frame composite texture, nearest neighbor and clamped to edge
498 glActiveTexture(GL_TEXTURE1); 531 glActiveTexture(GL_TEXTURE1);
499 glBindTexture(GL_TEXTURE_2D, renderedTexBufs[(curBuf + 1) % 2]); 532 glBindTexture(GL_TEXTURE_2D, renderedTexBufs[(curBuf + 1) % 2]);
500 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 533 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@@ -503,12 +536,13 @@ void renderScreen(Texture* tex)
503 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 536 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
504 glUniform1i(glGetUniformLocation(ntscShader, "prevFrameSampler"), 1); 537 glUniform1i(glGetUniformLocation(ntscShader, "prevFrameSampler"), 1);
505 538
539 // Load the NTSC artifact texture
506 glActiveTexture(GL_TEXTURE2); 540 glActiveTexture(GL_TEXTURE2);
507 glBindTexture(GL_TEXTURE_2D, artifactsTex); 541 glBindTexture(GL_TEXTURE_2D, artifactsTex);
508 glUniform1i(glGetUniformLocation(ntscShader, "NTSCArtifactSampler"), 2); 542 glUniform1i(glGetUniformLocation(ntscShader, "NTSCArtifactSampler"), 2);
509
510 glUniform1f(glGetUniformLocation(ntscShader, "NTSCLerp"), curBuf * 1.0); 543 glUniform1f(glGetUniformLocation(ntscShader, "NTSCLerp"), curBuf * 1.0);
511 544
545 // Load the vertices of a flat surface
512 GLfloat g_quad_vertex_buffer_data[] = { 546 GLfloat g_quad_vertex_buffer_data[] = {
513 -1.0f, -1.0f, 0.0f, 547 -1.0f, -1.0f, 0.0f,
514 1.0f, -1.0f, 0.0f, 548 1.0f, -1.0f, 0.0f,
@@ -523,11 +557,13 @@ void renderScreen(Texture* tex)
523 glBindBuffer(GL_ARRAY_BUFFER, quad_vertexbuffer); 557 glBindBuffer(GL_ARRAY_BUFFER, quad_vertexbuffer);
524 glBufferData(GL_ARRAY_BUFFER, sizeof(g_quad_vertex_buffer_data), g_quad_vertex_buffer_data, GL_STATIC_DRAW); 558 glBufferData(GL_ARRAY_BUFFER, sizeof(g_quad_vertex_buffer_data), g_quad_vertex_buffer_data, GL_STATIC_DRAW);
525 559
560 // Render our composition
526 glEnableVertexAttribArray(0); 561 glEnableVertexAttribArray(0);
527 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0); 562 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
528 glDrawArrays(GL_TRIANGLES, 0, 6); 563 glDrawArrays(GL_TRIANGLES, 0, 6);
529 glDisableVertexAttribArray(0); 564 glDisableVertexAttribArray(0);
530 565
566 // Load the normal vertices of a flat surface
531 GLfloat g_norms_data[] = { 567 GLfloat g_norms_data[] = {
532 0.0f, 0.0f, 1.0f, 568 0.0f, 0.0f, 1.0f,
533 0.0f, 0.0f, 1.0f, 569 0.0f, 0.0f, 1.0f,
@@ -542,10 +578,13 @@ void renderScreen(Texture* tex)
542 glBindBuffer(GL_ARRAY_BUFFER, g_norms); 578 glBindBuffer(GL_ARRAY_BUFFER, g_norms);
543 glBufferData(GL_ARRAY_BUFFER, sizeof(g_norms_data), g_norms_data, GL_STATIC_DRAW); 579 glBufferData(GL_ARRAY_BUFFER, sizeof(g_norms_data), g_norms_data, GL_STATIC_DRAW);
544 580
581 // We're going to output to the window now
545 glBindFramebuffer(GL_FRAMEBUFFER, 0); 582 glBindFramebuffer(GL_FRAMEBUFFER, 0);
546 glViewport(0,0,1024,768); 583 glViewport(0,0,1024,768);
547 glClear(GL_COLOR_BUFFER_BIT); 584 glClear(GL_COLOR_BUFFER_BIT);
548 glUseProgram(finalShader); 585 glUseProgram(finalShader);
586
587 // Use the composited frame texture, linearly filtered and filling in black for the border
549 glActiveTexture(GL_TEXTURE0); 588 glActiveTexture(GL_TEXTURE0);
550 glBindTexture(GL_TEXTURE_2D, renderedTexBufs[curBuf]); 589 glBindTexture(GL_TEXTURE_2D, renderedTexBufs[curBuf]);
551 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 590 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
@@ -557,10 +596,20 @@ void renderScreen(Texture* tex)
557 glGenerateMipmap(GL_TEXTURE_2D); 596 glGenerateMipmap(GL_TEXTURE_2D);
558 glUniform1i(glGetUniformLocation(finalShader, "rendertex"), 0); 597 glUniform1i(glGetUniformLocation(finalShader, "rendertex"), 0);
559 598
599 // Use the scanlines texture
560 glActiveTexture(GL_TEXTURE1); 600 glActiveTexture(GL_TEXTURE1);
561 glBindTexture(GL_TEXTURE_2D, scanlinesTex); 601 glBindTexture(GL_TEXTURE_2D, scanlinesTex);
562 glUniform1i(glGetUniformLocation(finalShader, "scanlinestex"), 1); 602 glUniform1i(glGetUniformLocation(finalShader, "scanlinestex"), 1);
563 603
604 // Initialize the MVP matrices
605 mat4 p_matrix = perspective(90.0f, 4.0f / 4.0f, 0.1f, 100.0f);
606 mat4 v_matrix = lookAt(vec3(0,0,1), vec3(0,0,0), vec3(0,1,0));
607 mat4 m_matrix = mat4(1.0f);
608 mat4 mvp_matrix = p_matrix * v_matrix * m_matrix;
609
610 glUniformMatrix4fv(glGetUniformLocation(finalShader, "MVP"), 1, GL_FALSE, &mvp_matrix[0][0]);
611 glUniformMatrix4fv(glGetUniformLocation(finalShader, "worldMat"), 1, GL_FALSE, &m_matrix[0][0]);
612
564 glEnableVertexAttribArray(0); 613 glEnableVertexAttribArray(0);
565 glBindBuffer(GL_ARRAY_BUFFER, quad_vertexbuffer); 614 glBindBuffer(GL_ARRAY_BUFFER, quad_vertexbuffer);
566 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0); 615 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
diff --git a/src/renderer.h b/src/renderer.h index de5fc31..057337c 100644 --- a/src/renderer.h +++ b/src/renderer.h
@@ -1,6 +1,7 @@
1#include <GL/glew.h> 1#include <GL/glew.h>
2#include <GLFW/glfw3.h> 2#include <GLFW/glfw3.h>
3#include <glm/glm.hpp> 3#include <glm/glm.hpp>
4#include <glm/gtc/matrix_transform.hpp>
4 5
5using namespace glm; 6using namespace glm;
6 7
@@ -35,6 +36,7 @@ void destroyRenderer();
35Texture* createTexture(int width, int height); 36Texture* createTexture(int width, int height);
36void destroyTexture(Texture* tex); 37void destroyTexture(Texture* tex);
37Texture* loadTextureFromBMP(char* filename); 38Texture* loadTextureFromBMP(char* filename);
39void saveTextureToBMP(Texture* tex, char* filename);
38void fillTexture(Texture* tex, Rectangle* loc, int r, int g, int b); 40void fillTexture(Texture* tex, Rectangle* loc, int r, int g, int b);
39void blitTexture(Texture* srctex, Texture* dsttex, Rectangle* srcrect, Rectangle* dstrect); 41void blitTexture(Texture* srctex, Texture* dsttex, Rectangle* srcrect, Rectangle* dstrect);
40void renderScreen(Texture* tex); 42void renderScreen(Texture* tex);
diff --git a/src/translate_font.cpp b/src/translate_font.cpp new file mode 100644 index 0000000..7eb4c59 --- /dev/null +++ b/src/translate_font.cpp
@@ -0,0 +1,32 @@
1#include "renderer.h"
2#include <cstdio>
3
4#define min(x,y) ((x) > (y) ? (y) : (x))
5
6int main()
7{
8 initRenderer();
9
10 Texture* palette = createTexture(128, 128);
11 fillTexture(palette, NULL, 0, 0, 0);
12
13 Texture* wrong = loadTextureFromBMP("../res/arcadepix_regular_8.bmp");
14
15 FILE* desc = fopen("../res/arcadepix_regular_8.sfl", "r");
16 while (!feof(desc))
17 {
18 int ch;
19 Rectangle srcRect;
20
21 fscanf(desc, "%d %d %d %d %d %*d %*d %*d \n", &ch, &(srcRect.x), &(srcRect.y), &(srcRect.w), &(srcRect.h));
22
23 Rectangle dstRect(ch % 16 * 8, ch / 16 * 8 + (8 - min(srcRect.h,8)), min(srcRect.w, 8), min(srcRect.h, 8));
24 blitTexture(wrong, palette, &srcRect, &dstRect);
25 }
26
27 fclose(desc);
28
29 saveTextureToBMP(palette, "tex.bmp");
30
31 destroyRenderer();
32}