void display (void) { glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Clear the background of our window to black glClear(GL_COLOR_BUFFER_BIT); //Clear the colour buffer glLoadIdentity(); // Load the Identity Matrix to reset our drawing locations glTranslatef(0.0f, 0.0f, -5.0f); renderStars(20); renderSun(7, 4,-20); renderAsteroid(-1.75, -1.25, 0); renderShip(0,0,0); glFlush(); // Flush the OpenGL buffers to the window }
void Sun::Render(const CameraSpectator &camera) { if (!program) initShaders(); glm::mat4 biasMVP = biasMatrix * camera.GetCameraMatrix(); glm::vec4 biassedPosition = biasMVP * glm::vec4(position,1.0); biassedPosition /= biassedPosition.w; //copy existing depth buffer to depth texture glBindTexture(GL_TEXTURE_2D, texIdDepth[0]); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, camera.GetScreenWidth(), camera.GetScreenHeight()); //draw sun glBindFramebuffer(GL_FRAMEBUFFER, fboId); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texIdColor[0], 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, texIdDepth[1], 0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); renderSun(camera); //apply depth test glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texIdColor[1], 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texIdColor[0]); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, texIdDepth[1]); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, texIdDepth[0]); depthTestProgram->Use(); renderRect(); depthTestProgram->UnUse(); //apply radial blur and render to screen glBindFramebuffer(GL_FRAMEBUFFER, 0); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR); glEnable(GL_BLEND); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texIdColor[1]); radialBlurProgram->Use(); glUniform2f(radialBlurProgram->GetUniformLocation("sourcePos"), biassedPosition.x, biassedPosition.y); glDisable(GL_DEPTH_TEST); renderRect(); glDisable(GL_DEPTH_TEST); radialBlurProgram->UnUse(); glDisable(GL_BLEND); }
void LensFlareSunDemo::renderSky() { skyShader.bindShader(); renderSkyPlane(&camera); skyShader.unbindShader(); setOrthographicProjection(); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); renderSun(-64.0f,-64.0f); GLfloat center_x = WIDTH * 0.5f; GLfloat center_y = HEIGHT * 0.5f; GLfloat screenPos_x = -64.0f; GLfloat screenPos_y = -64.0f; // screenPos is the onscreen position of the sun // mind that the pixel coordinates have been scaled // to fit our viewport GLfloat dx = center_x - screenPos_x; GLfloat dy = center_y - screenPos_y; GLfloat len = sqrt(dx * dx + dy * dy); // normalize the vector GLfloat vx = dx / len; GLfloat vy = dy / len; // choose a spacing between elements dx = vx * len * 0.4f; dy = vy * len * 0.4f; // note that we already are in 2D (orthogonal) // mode here glPushMatrix(); glTranslatef(screenPos_x, screenPos_y, 0); // travel down the line and draw the elements int numElements = 4; glBindTexture(GL_TEXTURE_2D,streaks4.texture); glTranslatef(dx, dy, 0); renderFlare(); glBindTexture(GL_TEXTURE_2D,halo3.texture); glTranslatef(dx, dy, 0); renderFlare(); glBindTexture(GL_TEXTURE_2D,bigGlow3.texture); glTranslatef(dx, dy, 0); renderFlare(); glBindTexture(GL_TEXTURE_2D,hardGlow2.texture); glTranslatef(dx, dy, 0); renderFlare(); glPopMatrix(); glDisable(GL_BLEND); restorePerspectiveProjection(); }