diff options
| author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-02-14 17:57:23 -0500 |
|---|---|---|
| committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-02-14 17:57:23 -0500 |
| commit | 297c093d398e7d6e5fcc5dc6ba1056ede25abf6f (patch) | |
| tree | 1e55ab169d6de9a6f11b4d3b6efbe9f1b4d6ab6f | |
| parent | de5a458cb037bb8e1e80c849c5e6525f9413b43a (diff) | |
| download | therapy-297c093d398e7d6e5fcc5dc6ba1056ede25abf6f.tar.gz therapy-297c093d398e7d6e5fcc5dc6ba1056ede25abf6f.tar.bz2 therapy-297c093d398e7d6e5fcc5dc6ba1056ede25abf6f.zip | |
Did some lighting and added room name
| -rw-r--r-- | res/arcadepix_regular_8.PNG | bin | 0 -> 3906 bytes | |||
| -rw-r--r-- | res/arcadepix_regular_8.bmp | bin | 0 -> 24632 bytes | |||
| -rw-r--r-- | res/arcadepix_regular_8.sfl | 94 | ||||
| -rw-r--r-- | res/font.bmp | bin | 0 -> 49208 bytes | |||
| -rw-r--r-- | src/main.cpp | 3 | ||||
| -rw-r--r-- | src/map.cpp | 17 | ||||
| -rw-r--r-- | src/renderer.cpp | 57 | ||||
| -rw-r--r-- | src/renderer.h | 2 | ||||
| -rw-r--r-- | src/translate_font.cpp | 32 |
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 @@ | |||
| 1 | 39 1 3 2 2 0 4 3 | ||
| 2 | 96 4 3 4 2 0 4 6 | ||
| 3 | 34 9 3 6 2 0 4 8 | ||
| 4 | 94 16 3 6 3 0 4 8 | ||
| 5 | 45 23 6 5 1 0 7 7 | ||
| 6 | 126 29 5 7 2 1 6 9 | ||
| 7 | 60 37 4 4 5 0 5 6 | ||
| 8 | 62 42 4 4 5 0 5 6 | ||
| 9 | 35 47 4 5 5 0 5 7 | ||
| 10 | 47 53 4 5 5 1 5 8 | ||
| 11 | 61 59 4 5 5 0 5 7 | ||
| 12 | 92 65 4 5 5 1 5 8 | ||
| 13 | 43 71 4 7 5 -1 5 7 | ||
| 14 | 32 79 10 0 0 0 11 8 | ||
| 15 | 91 80 10 0 0 0 11 0 | ||
| 16 | 93 81 10 0 0 0 11 0 | ||
| 17 | 123 82 10 0 0 0 11 0 | ||
| 18 | 124 83 10 0 0 0 11 0 | ||
| 19 | 125 84 10 0 0 0 11 0 | ||
| 20 | 58 85 5 2 5 0 6 3 | ||
| 21 | 46 88 8 2 2 0 9 3 | ||
| 22 | 105 91 1 3 9 0 2 4 | ||
| 23 | 33 95 3 3 7 0 4 4 | ||
| 24 | 40 99 3 3 7 0 4 4 | ||
| 25 | 41 103 3 3 7 0 4 4 | ||
| 26 | 108 107 3 3 7 0 4 4 | ||
| 27 | 36 111 3 5 7 0 4 7 | ||
| 28 | 42 117 3 5 7 0 4 7 | ||
| 29 | 102 1 11 5 7 0 4 7 | ||
| 30 | 116 7 11 5 7 0 4 7 | ||
| 31 | 38 13 11 6 7 0 4 8 | ||
| 32 | 49 20 11 6 7 0 4 8 | ||
| 33 | 73 27 11 6 7 0 4 8 | ||
| 34 | 84 34 11 6 7 0 4 8 | ||
| 35 | 89 41 11 6 7 0 4 8 | ||
| 36 | 98 48 11 6 7 0 4 8 | ||
| 37 | 100 55 11 6 7 0 4 8 | ||
| 38 | 104 62 11 6 7 0 4 8 | ||
| 39 | 107 69 11 6 7 0 4 8 | ||
| 40 | 97 76 12 6 6 0 5 8 | ||
| 41 | 99 83 12 6 6 0 5 8 | ||
| 42 | 101 90 12 6 6 0 5 8 | ||
| 43 | 110 97 12 6 6 0 5 8 | ||
| 44 | 111 104 12 6 6 0 5 8 | ||
| 45 | 114 111 12 6 6 0 5 8 | ||
| 46 | 115 118 12 6 6 0 5 8 | ||
| 47 | 117 1 20 6 6 0 5 8 | ||
| 48 | 118 8 20 6 6 0 5 8 | ||
| 49 | 120 15 20 6 6 0 5 8 | ||
| 50 | 122 22 20 6 6 0 5 8 | ||
| 51 | 37 29 19 7 7 1 4 9 | ||
| 52 | 48 37 19 7 7 1 4 9 | ||
| 53 | 50 45 19 7 7 1 4 9 | ||
| 54 | 51 53 19 7 7 1 4 9 | ||
| 55 | 52 61 19 7 7 1 4 9 | ||
| 56 | 53 69 19 7 7 1 4 9 | ||
| 57 | 54 77 19 7 7 1 4 9 | ||
| 58 | 55 85 19 7 7 1 4 9 | ||
| 59 | 56 93 19 7 7 1 4 9 | ||
| 60 | 57 101 19 7 7 1 4 9 | ||
| 61 | 65 109 19 7 7 1 4 9 | ||
| 62 | 66 117 19 7 7 1 4 9 | ||
| 63 | 67 1 27 7 7 1 4 9 | ||
| 64 | 68 9 27 7 7 1 4 9 | ||
| 65 | 69 17 27 7 7 1 4 9 | ||
| 66 | 70 25 27 7 7 1 4 9 | ||
| 67 | 71 33 27 7 7 1 4 9 | ||
| 68 | 72 41 27 7 7 1 4 9 | ||
| 69 | 74 49 27 7 7 1 4 9 | ||
| 70 | 75 57 27 7 7 1 4 9 | ||
| 71 | 76 65 27 7 7 1 4 9 | ||
| 72 | 77 73 27 7 7 1 4 9 | ||
| 73 | 78 81 27 7 7 1 4 9 | ||
| 74 | 79 89 27 7 7 1 4 9 | ||
| 75 | 80 97 27 7 7 1 4 9 | ||
| 76 | 81 105 27 7 7 1 4 9 | ||
| 77 | 82 113 27 7 7 1 4 9 | ||
| 78 | 83 1 37 7 7 1 4 9 | ||
| 79 | 85 9 37 7 7 1 4 9 | ||
| 80 | 86 17 37 7 7 1 4 9 | ||
| 81 | 87 25 37 7 7 1 4 9 | ||
| 82 | 88 33 37 7 7 1 4 9 | ||
| 83 | 90 41 37 7 7 1 4 9 | ||
| 84 | 109 49 38 7 6 1 5 9 | ||
| 85 | 119 57 38 7 6 1 5 9 | ||
| 86 | 59 65 39 3 6 0 6 4 | ||
| 87 | 44 69 42 3 3 0 9 4 | ||
| 88 | 95 73 44 7 1 0 11 8 | ||
| 89 | 64 81 37 8 8 1 4 10 | ||
| 90 | 106 90 35 4 11 0 2 6 | ||
| 91 | 103 95 38 6 8 0 5 8 | ||
| 92 | 112 102 38 6 8 0 5 8 | ||
| 93 | 113 109 38 6 8 0 5 8 | ||
| 94 | 121 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 | ||
| 348 | void 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 | |||
| 348 | void fillTexture(Texture* tex, Rectangle* dstrect, int r, int g, int b) | 378 | void 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 | ||
| 5 | using namespace glm; | 6 | using namespace glm; |
| 6 | 7 | ||
| @@ -35,6 +36,7 @@ void destroyRenderer(); | |||
| 35 | Texture* createTexture(int width, int height); | 36 | Texture* createTexture(int width, int height); |
| 36 | void destroyTexture(Texture* tex); | 37 | void destroyTexture(Texture* tex); |
| 37 | Texture* loadTextureFromBMP(char* filename); | 38 | Texture* loadTextureFromBMP(char* filename); |
| 39 | void saveTextureToBMP(Texture* tex, char* filename); | ||
| 38 | void fillTexture(Texture* tex, Rectangle* loc, int r, int g, int b); | 40 | void fillTexture(Texture* tex, Rectangle* loc, int r, int g, int b); |
| 39 | void blitTexture(Texture* srctex, Texture* dsttex, Rectangle* srcrect, Rectangle* dstrect); | 41 | void blitTexture(Texture* srctex, Texture* dsttex, Rectangle* srcrect, Rectangle* dstrect); |
| 40 | void renderScreen(Texture* tex); | 42 | void 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 | |||
| 6 | int 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 | } | ||
