From 297c093d398e7d6e5fcc5dc6ba1056ede25abf6f Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sat, 14 Feb 2015 17:57:23 -0500 Subject: Did some lighting and added room name --- res/arcadepix_regular_8.PNG | Bin 0 -> 3906 bytes res/arcadepix_regular_8.bmp | Bin 0 -> 24632 bytes res/arcadepix_regular_8.sfl | 94 ++++++++++++++++++++++++++++++++++++++++++++ res/font.bmp | Bin 0 -> 49208 bytes src/main.cpp | 3 +- src/map.cpp | 17 ++++++-- src/renderer.cpp | 57 +++++++++++++++++++++++++-- src/renderer.h | 2 + src/translate_font.cpp | 32 +++++++++++++++ 9 files changed, 197 insertions(+), 8 deletions(-) create mode 100644 res/arcadepix_regular_8.PNG create mode 100644 res/arcadepix_regular_8.bmp create mode 100644 res/arcadepix_regular_8.sfl create mode 100644 res/font.bmp create mode 100644 src/translate_font.cpp diff --git a/res/arcadepix_regular_8.PNG b/res/arcadepix_regular_8.PNG new file mode 100644 index 0000000..5b152aa Binary files /dev/null and b/res/arcadepix_regular_8.PNG differ diff --git a/res/arcadepix_regular_8.bmp b/res/arcadepix_regular_8.bmp new file mode 100644 index 0000000..fc2fd82 Binary files /dev/null and b/res/arcadepix_regular_8.bmp 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 @@ +39 1 3 2 2 0 4 3 +96 4 3 4 2 0 4 6 +34 9 3 6 2 0 4 8 +94 16 3 6 3 0 4 8 +45 23 6 5 1 0 7 7 +126 29 5 7 2 1 6 9 +60 37 4 4 5 0 5 6 +62 42 4 4 5 0 5 6 +35 47 4 5 5 0 5 7 +47 53 4 5 5 1 5 8 +61 59 4 5 5 0 5 7 +92 65 4 5 5 1 5 8 +43 71 4 7 5 -1 5 7 +32 79 10 0 0 0 11 8 +91 80 10 0 0 0 11 0 +93 81 10 0 0 0 11 0 +123 82 10 0 0 0 11 0 +124 83 10 0 0 0 11 0 +125 84 10 0 0 0 11 0 +58 85 5 2 5 0 6 3 +46 88 8 2 2 0 9 3 +105 91 1 3 9 0 2 4 +33 95 3 3 7 0 4 4 +40 99 3 3 7 0 4 4 +41 103 3 3 7 0 4 4 +108 107 3 3 7 0 4 4 +36 111 3 5 7 0 4 7 +42 117 3 5 7 0 4 7 +102 1 11 5 7 0 4 7 +116 7 11 5 7 0 4 7 +38 13 11 6 7 0 4 8 +49 20 11 6 7 0 4 8 +73 27 11 6 7 0 4 8 +84 34 11 6 7 0 4 8 +89 41 11 6 7 0 4 8 +98 48 11 6 7 0 4 8 +100 55 11 6 7 0 4 8 +104 62 11 6 7 0 4 8 +107 69 11 6 7 0 4 8 +97 76 12 6 6 0 5 8 +99 83 12 6 6 0 5 8 +101 90 12 6 6 0 5 8 +110 97 12 6 6 0 5 8 +111 104 12 6 6 0 5 8 +114 111 12 6 6 0 5 8 +115 118 12 6 6 0 5 8 +117 1 20 6 6 0 5 8 +118 8 20 6 6 0 5 8 +120 15 20 6 6 0 5 8 +122 22 20 6 6 0 5 8 +37 29 19 7 7 1 4 9 +48 37 19 7 7 1 4 9 +50 45 19 7 7 1 4 9 +51 53 19 7 7 1 4 9 +52 61 19 7 7 1 4 9 +53 69 19 7 7 1 4 9 +54 77 19 7 7 1 4 9 +55 85 19 7 7 1 4 9 +56 93 19 7 7 1 4 9 +57 101 19 7 7 1 4 9 +65 109 19 7 7 1 4 9 +66 117 19 7 7 1 4 9 +67 1 27 7 7 1 4 9 +68 9 27 7 7 1 4 9 +69 17 27 7 7 1 4 9 +70 25 27 7 7 1 4 9 +71 33 27 7 7 1 4 9 +72 41 27 7 7 1 4 9 +74 49 27 7 7 1 4 9 +75 57 27 7 7 1 4 9 +76 65 27 7 7 1 4 9 +77 73 27 7 7 1 4 9 +78 81 27 7 7 1 4 9 +79 89 27 7 7 1 4 9 +80 97 27 7 7 1 4 9 +81 105 27 7 7 1 4 9 +82 113 27 7 7 1 4 9 +83 1 37 7 7 1 4 9 +85 9 37 7 7 1 4 9 +86 17 37 7 7 1 4 9 +87 25 37 7 7 1 4 9 +88 33 37 7 7 1 4 9 +90 41 37 7 7 1 4 9 +109 49 38 7 6 1 5 9 +119 57 38 7 6 1 5 9 +59 65 39 3 6 0 6 4 +44 69 42 3 3 0 9 4 +95 73 44 7 1 0 11 8 +64 81 37 8 8 1 4 10 +106 90 35 4 11 0 2 6 +103 95 38 6 8 0 5 8 +112 102 38 6 8 0 5 8 +113 109 38 6 8 0 5 8 +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 Binary files /dev/null and b/res/font.bmp 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() while (!quit) { + /* double currentTime = glfwGetTime(); nbFrames++; if ( currentTime - lastTime >= 1.0 ){ // If last prinf() was more than 1 sec ago @@ -93,7 +94,7 @@ int main() printf("%f ms/frame\n", 1000.0/double(nbFrames)); nbFrames = 0; lastTime += 1.0; - } + }*/ if (holding_left && player->x_vel >= 0) { 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() add_collision(GAME_WIDTH+6, 0, GAME_WIDTH, right, 1); FILE* f = fopen("../maps/bigmap.txt", "r"); - char* mapbuf = (char*) malloc(MAP_WIDTH*MAP_HEIGHT*sizeof(char)); + char* mapbuf = (char*) malloc(MAP_WIDTH*(MAP_HEIGHT-1)*sizeof(char)); - for (int i=0; iwidth*tex->height; + + char* buf = (char*) calloc(size, sizeof(char)); + buf[0x00] = 'B'; + buf[0x01] = 'M'; + *(int*)&(buf[0x0A]) = 54; + *(int*)&(buf[0x12]) = tex->width; + *(int*)&(buf[0x16]) = tex->height; + *(int*)&(buf[0x1C]) = 24; + *(int*)&(buf[0x1E]) = 0; + *(int*)&(buf[0x22]) = size; + + glBindTexture(GL_TEXTURE_2D, tex->texID); + glGetTexImage(GL_TEXTURE_2D, 0, GL_BGR, GL_UNSIGNED_BYTE, buf + 54); + + FILE* f = fopen(filename, "wb"); + fwrite(buf, sizeof(char), size, f); + fclose(f); + + free(buf); +} + void fillTexture(Texture* tex, Rectangle* dstrect, int r, int g, int b) { if (!rendererInitialized) @@ -478,15 +508,17 @@ void renderScreen(Texture* tex) exit(-1); } - // Set up framebuffer + // First we're going to composite our frame with the previous frame + // We start by setting up the framebuffer glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, renderedTexBufs[curBuf], 0); - // Set up renderer + // Set up the shaer glViewport(0,0,GAME_WIDTH,GAME_HEIGHT); glClear(GL_COLOR_BUFFER_BIT); glUseProgram(ntscShader); + // Use the current frame texture, nearest neighbor and clamped to edge glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, tex->texID); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); @@ -495,6 +527,7 @@ void renderScreen(Texture* tex) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glUniform1i(glGetUniformLocation(ntscShader, "curFrameSampler"), 0); + // Use the previous frame composite texture, nearest neighbor and clamped to edge glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, renderedTexBufs[(curBuf + 1) % 2]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); @@ -503,12 +536,13 @@ void renderScreen(Texture* tex) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glUniform1i(glGetUniformLocation(ntscShader, "prevFrameSampler"), 1); + // Load the NTSC artifact texture glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, artifactsTex); glUniform1i(glGetUniformLocation(ntscShader, "NTSCArtifactSampler"), 2); - glUniform1f(glGetUniformLocation(ntscShader, "NTSCLerp"), curBuf * 1.0); + // Load the vertices of a flat surface GLfloat g_quad_vertex_buffer_data[] = { -1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 0.0f, @@ -523,11 +557,13 @@ void renderScreen(Texture* tex) glBindBuffer(GL_ARRAY_BUFFER, quad_vertexbuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(g_quad_vertex_buffer_data), g_quad_vertex_buffer_data, GL_STATIC_DRAW); + // Render our composition glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0); glDrawArrays(GL_TRIANGLES, 0, 6); glDisableVertexAttribArray(0); - + + // Load the normal vertices of a flat surface GLfloat g_norms_data[] = { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, @@ -542,10 +578,13 @@ void renderScreen(Texture* tex) glBindBuffer(GL_ARRAY_BUFFER, g_norms); glBufferData(GL_ARRAY_BUFFER, sizeof(g_norms_data), g_norms_data, GL_STATIC_DRAW); + // We're going to output to the window now glBindFramebuffer(GL_FRAMEBUFFER, 0); glViewport(0,0,1024,768); glClear(GL_COLOR_BUFFER_BIT); glUseProgram(finalShader); + + // Use the composited frame texture, linearly filtered and filling in black for the border glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, renderedTexBufs[curBuf]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); @@ -557,10 +596,20 @@ void renderScreen(Texture* tex) glGenerateMipmap(GL_TEXTURE_2D); glUniform1i(glGetUniformLocation(finalShader, "rendertex"), 0); + // Use the scanlines texture glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, scanlinesTex); glUniform1i(glGetUniformLocation(finalShader, "scanlinestex"), 1); + // Initialize the MVP matrices + mat4 p_matrix = perspective(90.0f, 4.0f / 4.0f, 0.1f, 100.0f); + mat4 v_matrix = lookAt(vec3(0,0,1), vec3(0,0,0), vec3(0,1,0)); + mat4 m_matrix = mat4(1.0f); + mat4 mvp_matrix = p_matrix * v_matrix * m_matrix; + + glUniformMatrix4fv(glGetUniformLocation(finalShader, "MVP"), 1, GL_FALSE, &mvp_matrix[0][0]); + glUniformMatrix4fv(glGetUniformLocation(finalShader, "worldMat"), 1, GL_FALSE, &m_matrix[0][0]); + glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, quad_vertexbuffer); 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 @@ #include #include #include +#include using namespace glm; @@ -35,6 +36,7 @@ void destroyRenderer(); Texture* createTexture(int width, int height); void destroyTexture(Texture* tex); Texture* loadTextureFromBMP(char* filename); +void saveTextureToBMP(Texture* tex, char* filename); void fillTexture(Texture* tex, Rectangle* loc, int r, int g, int b); void blitTexture(Texture* srctex, Texture* dsttex, Rectangle* srcrect, Rectangle* dstrect); 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 @@ +#include "renderer.h" +#include + +#define min(x,y) ((x) > (y) ? (y) : (x)) + +int main() +{ + initRenderer(); + + Texture* palette = createTexture(128, 128); + fillTexture(palette, NULL, 0, 0, 0); + + Texture* wrong = loadTextureFromBMP("../res/arcadepix_regular_8.bmp"); + + FILE* desc = fopen("../res/arcadepix_regular_8.sfl", "r"); + while (!feof(desc)) + { + int ch; + Rectangle srcRect; + + fscanf(desc, "%d %d %d %d %d %*d %*d %*d \n", &ch, &(srcRect.x), &(srcRect.y), &(srcRect.w), &(srcRect.h)); + + Rectangle dstRect(ch % 16 * 8, ch / 16 * 8 + (8 - min(srcRect.h,8)), min(srcRect.w, 8), min(srcRect.h, 8)); + blitTexture(wrong, palette, &srcRect, &dstRect); + } + + fclose(desc); + + saveTextureToBMP(palette, "tex.bmp"); + + destroyRenderer(); +} -- cgit 1.4.1