diff --git a/graphics.cc b/graphics.cc index 5e25d97..47e3d58 100644 --- a/graphics.cc +++ b/graphics.cc @@ -77,6 +77,25 @@ void Graphics::init(Level* level) { flameShader = ShaderProgramCreator("flame") .attributeLocations(flame_positions->getAttributeLocations()).create(); + fullscreen_quad_ab = SharedArrayBuffer(new ArrayBuffer()); + fullscreen_quad_ab->defineAttribute("aPosition", GL_FLOAT, 2); + fullscreen_quad_ab->defineAttribute("aTexCoord", GL_FLOAT, 2); + + float quadData[] = { + -1.0f, 1.0f, 0.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, -1.0f, 1.0f, 0.0f, + + 1.0f, -1.0f, 1.0f, 0.0f, + -1.0f, -1.0f, 0.0f, 0.0f, + -1.0f, 1.0f, 0.0f, 1.0f + }; + + fullscreen_quad_ab->setDataElements(6, quadData); + + fullscreen_quad = SharedVertexArrayObject(new VertexArrayObject); + fullscreen_quad->attachAllAttributes(fullscreen_quad_ab); + flamePostShader = ShaderProgramCreator("flame_post") .attributeLocations(fullscreen_quad->getAttributeLocations()).create(); @@ -173,35 +192,58 @@ void Graphics::renderLoadingScreen() { printf("You need at least 18 texture units to run this application. Exiting\n"); exit(-1); } - fullscreen_quad_ab = SharedArrayBuffer(new ArrayBuffer()); - fullscreen_quad_ab->defineAttribute("aPosition", GL_FLOAT, 2); - fullscreen_quad_ab->defineAttribute("aTexCoord", GL_FLOAT, 2); - - float quadData[] = { - -1.0f, 1.0f, 0.0f, 1.0f, - 1.0f, 1.0f, 1.0f, 1.0f, - 1.0f, -1.0f, 1.0f, 0.0f, - - 1.0f, -1.0f, 1.0f, 0.0f, - -1.0f, -1.0f, 0.0f, 0.0f, - -1.0f, 1.0f, 0.0f, 1.0f - }; - - fullscreen_quad_ab->setDataElements(6, quadData); - - fullscreen_quad = SharedVertexArrayObject(new VertexArrayObject); - fullscreen_quad->attachAllAttributes(fullscreen_quad_ab); loadingScreen = Texture2DFileManager::the()->get(Texture2DCreator(loadingScreenPath)); loadingScreen->generateMipmaps(); loadingContinueScreen = Texture2DFileManager::the()->get(Texture2DCreator(loadingScreenContinuePath)); loadingContinueScreen->generateMipmaps(); + int loadingScreenWidth = loadingScreen->getWidth(); + int loadingScreenHeight = loadingScreen->getHeight(); + + fullscreen_quad_ab_loading = SharedArrayBuffer(new ArrayBuffer()); + fullscreen_quad_ab_loading->defineAttribute("aPosition", GL_FLOAT, 2); + fullscreen_quad_ab_loading->defineAttribute("aTexCoord", GL_FLOAT, 2); + + float quadData[24]; + if (loadingScreenWidth/loadingScreenHeight < (int)windowSize.x/(int)windowSize.y) { + float quadTemp[24] ={ + -1.0f + ((windowSize.y*loadingScreenWidth)/(windowSize.x*loadingScreenHeight)), 1.0f, 0.0f, 1.0f, + 1.0f - ((windowSize.y*loadingScreenWidth)/(windowSize.x*loadingScreenHeight)), 1.0f, 1.0f, 1.0f, + 1.0f - ((windowSize.y*loadingScreenWidth)/(windowSize.x*loadingScreenHeight)), -1.0f, 1.0f, 0.0f, + + 1.0f - ((windowSize.y*loadingScreenWidth)/(windowSize.x*loadingScreenHeight)), -1.0f, 1.0f, 0.0f, + -1.0f + ((windowSize.y*loadingScreenWidth)/(windowSize.x*loadingScreenHeight)), -1.0f, 0.0f, 0.0f, + -1.0f + ((windowSize.y*loadingScreenWidth)/(windowSize.x*loadingScreenHeight)), 1.0f, 0.0f, 1.0f + }; + for(int i = 0; i<24; i++) { + quadData[i] = quadTemp[i]; + } + } + else { + float quadTemp[24] = { + -1.0f, 1.0f - (windowSize.x*loadingScreenHeight)/(windowSize.y*loadingScreenWidth), 0.0f, 1.0f, + 1.0f, 1.0f - (windowSize.x*loadingScreenHeight)/(windowSize.y*loadingScreenWidth), 1.0f, 1.0f, + 1.0f, -1.0f + (windowSize.x*loadingScreenHeight)/(windowSize.y*loadingScreenWidth), 1.0f, 0.0f, + + 1.0f, -1.0f + (windowSize.x*loadingScreenHeight)/(windowSize.y*loadingScreenWidth), 1.0f, 0.0f, + -1.0f, -1.0f + (windowSize.x*loadingScreenHeight)/(windowSize.y*loadingScreenWidth), 0.0f, 0.0f, + -1.0f, 1.0f - (windowSize.x*loadingScreenHeight)/(windowSize.y*loadingScreenWidth), 0.0f, 1.0f + }; + for(int i = 0; i<24; i++) { + quadData[i] = quadTemp[i]; + } + } + + fullscreen_quad_ab_loading->setDataElements(6, quadData); + + fullscreen_quad_loading = SharedVertexArrayObject(new VertexArrayObject); + fullscreen_quad_loading->attachAllAttributes(fullscreen_quad_ab_loading); loadingShader = ShaderProgramCreator("loading") - .attributeLocations(fullscreen_quad->getAttributeLocations()).create(); + .attributeLocations(fullscreen_quad_loading->getAttributeLocations()).create(); loadingShader->use(); loadingShader->setUniform("time", 0.0f); loadingShader->setTexture("screen", loadingScreen, 16); loadingShader->setTexture("screenContinue", loadingContinueScreen, 17); - fullscreen_quad->render(); + fullscreen_quad_loading->render(); } glm::uvec2 Graphics::getWindowSize() { @@ -215,7 +257,7 @@ void Graphics::render(double time) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); loadingShader->use(); loadingShader->setUniform("time", float(time)); - fullscreen_quad->render(); + fullscreen_quad_loading->render(); } else { double nextUpdate = lastUpdate + lightUpdateDelay; @@ -292,7 +334,7 @@ void Graphics::render(double time) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //wind - glm::vec2 wind = glm::vec2(-0.4f, 0.3f); + glm::vec2 wind = glm::vec2(-0.3f, 0.0f); //set view and projection matrix glm::mat4 lightingViewProjectionMatrix = glm::perspective(1.571f, (float)windowSize.x/(float)windowSize.y, 0.1f, farPlane) * buildViewMatrix(level); diff --git a/graphics.hh b/graphics.hh index 085b15c..554894c 100644 --- a/graphics.hh +++ b/graphics.hh @@ -56,6 +56,8 @@ class Graphics { SharedTexture2D light_fbo_depth_texture; SharedVertexArrayObject fullscreen_quad; SharedArrayBuffer fullscreen_quad_ab; + SharedVertexArrayObject fullscreen_quad_loading; + SharedArrayBuffer fullscreen_quad_ab_loading; int cube_size; unsigned int maxShadowRenderCount; Level* level;