void PlayerViewport::Render(float frameSeconds, const RenderInfo& screenRenderInfo) { const RenderTarget* current = RenderTarget::GetCurrentTarget(); //Render the world. worldRendTarg.EnableDrawingInto(); //TODO: Fix culling. RenderingState(RenderingState::C_NONE).EnableState(); ScreenClearer(true, true, false, Vector4f(1.0f, 0.0f, 1.0f, 0.0f)).ClearScreen(); Vector3f camPos = LevelConstants::Instance.GetPlayerEyePos(Target->Pos, Target->LookDir); Camera cam(camPos, Target->LookDir, Vector3f(0.0f, 0.0f, 1.0f), false); cam.PerspectiveInfo.SetFOVDegrees(Settings::Instance.FOVDegrees); cam.PerspectiveInfo.Width = (float)worldRendTarg.GetWidth(); cam.PerspectiveInfo.Height = (float)worldRendTarg.GetHeight(); cam.PerspectiveInfo.zNear = LevelConstants::Instance.CameraZNear; cam.PerspectiveInfo.zFar = LevelConstants::Instance.CameraZFar; Matrix4f viewM, projM; cam.GetViewTransform(viewM); cam.GetPerspectiveProjection(projM); RenderInfo worldRenderInfo(Lvl.GetTimeSinceGameStart(), &cam, &viewM, &projM); Lvl.Render(frameSeconds, worldRenderInfo); worldRendTarg.DisableDrawingInto(); //Render post-processing. RenderTarget* finalRnd = PostProcessing::Instance.Apply(worldRendColor, worldRendDepth); if (current != 0) { current->EnableDrawingInto(); } else { Viewport(0, 0, World->GetWindow()->getSize().x, World->GetWindow()->getSize().y).Use(); } //Do the final render to the screen. RenderingState(RenderingState::C_NONE).EnableState(); SetTex(finalRnd->GetColorTextures()[0].MTex); GUITexture::Render(frameSeconds, screenRenderInfo); }
int WindowLister( int x, int y, int xx, int yy, int CharToExitOn, int *NumItems, int NumToStartWith, int (*CharHandler)(int ch, int Index), void (*ScreenClearer)( void ), void (*DisplayLineFunction)(int Index) ) { register int i; register int CurrLine = 0; int PrevLine; int NumLines = yy - y; int Top = NumToStartWith; int OldTop; int RefreshScreen = 1; int ch; union REGS regs, regs2; int Index; regs.x.cx = ( (y-1) << 8 ) + x-1; regs.x.dx = ( (yy-1) << 8 ) + xx-1; regs.x.ax = 0; regs.h.bh = A_NORMAL; regs.h.ah = 0x06; regs.x.ax = 1; for (;;) { if ( RefreshScreen ) { ScreenClearer(); ChangeBlock( x, y, xx, yy, A_NORMAL ); RefreshScreen = 0; PrevLine = 500; OldTop = -500; for (i=0; i<=NumLines; ++i) { gotoxy( x, i+y ); if ( i+Top <= *NumItems ) DisplayLineFunction( i+Top ); } } Index = CurrLine + Top; if ( PrevLine != CurrLine || OldTop != Top ) { SetAttrib( A_REVERSE ); gotoxy( x, y + CurrLine ); DisplayLineFunction( Index ); SetAttrib( A_NORMAL ); } HideCursor(); PrevLine = CurrLine; OldTop = Top; ch = GComm(); if ( ch == CharToExitOn ) return( Index ); switch( ch ) { case ESC: return( -1 ); case DOWN: CurrLine++; if (CurrLine > NumLines) { CurrLine = NumLines; if ( Top < *NumItems - NumLines ) { Top++; ChangeBlock( x, y, xx, yy, A_NORMAL ); regs.h.ah = 0x06; int86( 0x10, ®s, ®s2 ); gotoxy( x, yy ); } } break; case UP: CurrLine--; if (CurrLine < 0) { CurrLine=0; if ( Top > 0 ) { Top--; ChangeBlock( x, yy, xx, yy, A_NORMAL ); regs.h.ah = 7; int86( 0x10, ®s, ®s2 ); gotoxy( x, y ); } } break; case END: Top = *NumItems - NumLines; if ( Top < 0 ) { Top = 0; } CurrLine = NumLines; if ( CurrLine > *NumItems ) { CurrLine = *NumItems; } RefreshScreen++; break; case PGDN: Top += NumLines; if (Top > *NumItems - NumLines) { Top = *NumItems - NumLines; if ( Top < 0 ) Top = 0; CurrLine = NumLines; if ( CurrLine > *NumItems ) { CurrLine = *NumItems; } } RefreshScreen++; break; case PGUP: Top -= NumLines; if (Top < 0) { Top = 0; CurrLine = 0; } RefreshScreen++; break; case HOME: Top = CurrLine = 0; RefreshScreen++; break; default: gotoxy( x, CurrLine + y ); ReverseText(); DisplayLineFunction( Index ); NormalText(); /*HideCursor();*/ RefreshScreen++; CurrLine = CharHandler( ch, Index ); RefreshScreen = 1; if ( CurrLine - Top <= NumLines && CurrLine - Top >= 0 ) CurrLine -= Top; else { Top = CurrLine - 1; CurrLine = 1; if ( Top < 0 ) { Top = CurrLine = 0; } } break; } if ( Top < 0 ) { Top = 0; CurrLine = 0; } if ( Top + CurrLine > *NumItems ) { CurrLine = *NumItems - Top; } if ( PrevLine != CurrLine || Top != OldTop ) { ChangeBlock( x, y, xx, yy, A_NORMAL ); } if ( RefreshScreen > 1 ) { Top = CurrLine = 0; } } }
bool TR::RenderString(std::string textToRender, unsigned int fontID, RenderTarget* targ, unsigned int& outTextWidth, unsigned int& outTextHeight) { //Get texture/render target. if (targ == 0) { return false; } textRendererParams[textSamplerName].Tex() = tempTex.GetTextureHandle(); //Set up rendering. targ->EnableDrawingInto(); RenderingState(RenderingState::C_BACK, false, false).EnableState(); ScreenClearer(true, true, false, Vector4f(0.0f, 0.0f, 0.0f, 0.0f)).ClearScreen(); //Render each character into the texture, then into the final render target. outTextWidth = 0; outTextHeight = 0; Vector2f pos = Vector2f(-1.0f, 1.0f); Vector2i size = Vector2i(), offset = Vector2i(), movement = Vector2i(); Vector2f scaledSize = Vector2f(), scaledOffset = Vector2f(), scaledMovement = Vector2f(); Vector2f invRendTargSize(2.0f / (float)targ->GetWidth(), -2.0f / (float)targ->GetHeight()); for (unsigned int i = 0; i < textToRender.size(); ++i) { char ch = textToRender.c_str()[i]; //Render the character into an array. if (FreeTypeHandler::Instance.RenderChar(fontID, ch) == FreeTypeHandler::CharRenderType::CRT_ERROR) { targ->DisableDrawingInto(true); return false; } //Compute character layout data. size = FreeTypeHandler::Instance.GetGlyphSize(fontID); scaledSize = ToV2f(size).ComponentProduct(invRendTargSize); offset = FreeTypeHandler::Instance.GetGlyphOffset(fontID); scaledOffset = ToV2f(offset).ComponentProduct(invRendTargSize); movement = FreeTypeHandler::Instance.GetMoveToNextGlyph(fontID); scaledMovement = ToV2f(movement).ComponentProduct(invRendTargSize); outTextWidth += movement.x; outTextHeight = Mathf::Max(size.y, (int)outTextHeight); //If the character is empty (i.e. a space), don't bother rendering it. Vector2i glyphSize = FreeTypeHandler::Instance.GetGlyphSize(fontID); if (glyphSize.x > 0 && glyphSize.y > 0) { //Render the array into the temp texture. FreeTypeHandler::Instance.GetChar(tempTex); //Set up the render quad size/location. Vector2f halfSize = scaledSize * 0.5f; Transform tr; tr.SetPosition(Vector3f(pos + halfSize, 0.0f)); tr.SetScale(Vector3f(halfSize, 1.0f)); tr.IncrementPosition(Vector3f(scaledOffset.x, -(1.0f + scaledOffset.y), 0.0f)); tr.SetScale(tr.GetScale().Abs()); //Render the character into the render target. DrawingQuad::GetInstance()->Render(tr, textRendererInfo, *textRenderer, textRendererParams); } //Move the quad to the next position for the letter. pos += scaledMovement; } outTextWidth -= movement.x; outTextWidth += size.x; targ->DisableDrawingInto(true); return true; }
bool PostProcessChain::RenderChain(SFMLOpenGLWorld * world, const ProjectionInfo & pInfo, RenderObjHandle colorIn, RenderObjHandle depthIn) { if (totalPasses == 0) return true; //Set up the RenderInfo struct. Camera cam; cam.PerspectiveInfo = pInfo; TransformObject trans; Matrix4f identity; identity.SetAsIdentity(); RenderInfo info(world, &cam, &trans, &identity, &identity, &identity); const RenderTarget * first = rtManager[rt1], * second = rtManager[rt2]; //The input and output color render targets for a single material render. RenderObjHandle source = colorIn; const RenderTarget * dest; UniformDictionary oldUniforms = params; //Render each material in turn. for (unsigned int i = 0; i < materials.size(); ++i) { if (source == colorIn || source == ct2.GetTextureHandle()) dest = first; else dest = second; assert(source != 0 && dest != 0); //Set up the uniforms for this pass. const UniformList & matUniforms = materials[i]->GetUniforms(); params.ClearUniforms(); params.AddUniforms(oldUniforms, true); params.Texture2DUniforms[PostProcessEffect::ColorSampler] = UniformValueSampler2D(source, PostProcessEffect::ColorSampler, matUniforms.FindUniform(PostProcessEffect::ColorSampler, matUniforms.Texture2DUniforms).Loc); params.Texture2DUniforms[PostProcessEffect::DepthSampler] = UniformValueSampler2D(depthIn, PostProcessEffect::DepthSampler, matUniforms.FindUniform(PostProcessEffect::DepthSampler, matUniforms.Texture2DUniforms).Loc); params.AddUniforms(uniforms[i], true); //Set up the render target. dest->EnableDrawingInto(); ScreenClearer().ClearScreen(); //Render. if (!quad.Render(info, params, *materials[i])) { errorMsg = "Error rendering material " + std::to_string(i) + ": " + materials[i]->GetErrorMsg(); return false; } //Disable the render target. dest->DisableDrawingInto(world->GetWindow()->getSize().x, world->GetWindow()->getSize().y, true); //Prepare for the next iteration. if (dest == first) source = ct1.GetTextureHandle(); else source = ct2.GetTextureHandle(); } params = oldUniforms; return true; }