Ejemplo n.º 1
0
///---------------------------------------------------------------------------------
///
///---------------------------------------------------------------------------------
void Profiler::PrintDataToScreen( OpenGLRenderer* renderer )
{
    if (!renderer)
        return;

    FontRenderer* fontRenderer = renderer->GetFontRenderer();
    Font* font = Font::CreateOrGetFont( "Data/Fonts/Calibri" );

    Vector3 offset( 10.0f, 870.0f, 1.0f );
    float offsetModifier = -35.0f;
    int fontSize = 32;


    for (std::map< std::string, ProfileData >::const_iterator categoryIter = s_profileDataMap.begin(); categoryIter != s_profileDataMap.end(); ++categoryIter)
    {
        const std::string& categoryName = categoryIter->first;
        const ProfileData& data = categoryIter->second;

        std::string totalText = categoryName + " total: " + std::to_string( data.m_totalTime_us / 1000LL ) + " ms, " + std::to_string( data.m_totalTime_us ) + " us - average: " + std::to_string( data.m_averageTime_us / 1000LL ) + " ms, " + std::to_string( data.m_averageTime_us ) + " us";

        Vector3 pos = offset;
        fontRenderer->DrawFontTextOrtho( fontSize, *font, totalText, pos, Rgba::WHITE );
        offset.y += offsetModifier;
    }
}
Ejemplo n.º 2
0
void invRTSGame::draw2D()
{
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_TEXTURE_2D);

	quadinstances.rewind();
	while(!quadinstances.isEnd())
	{
		invQuadInstance* q = quadinstances.current();
		if(q->visible && q->q->in2D)
		{
			q->draw();
		}
		quadinstances.next();
	}

	glDisable(GL_BLEND);
	glDisable(GL_TEXTURE_2D);

	glColor3f(1.f, 1.f, 1.f);
	fdraw.begin();
	textbuffers.rewind();
	while(!textbuffers.isEnd())
	{
		invTextBuffer* tb = textbuffers.current();
		fdraw.setPenPos(tb->pos.x, tb->pos.y);
		fdraw.setFont(tb->font);
		fdraw.printf("%s", tb->str);
		textbuffers.next();
	}

	fdraw.end();
}
FontRenderer* Lookup3GammaFontRenderer::getRenderer(Gamma gamma) {
    FontRenderer* renderer = mRenderers[gamma];
    if (!renderer) {
        renderer = new FontRenderer();
        mRenderers[gamma] = renderer;
        renderer->setGammaTable(&mGammaTable[gamma * 256]);
    }
    mRenderersUsageCount[gamma]++;
    return renderer;
}
Ejemplo n.º 4
0
int main(int argc, char** argv) {
    
    SDL_Init(SDL_INIT_EVERYTHING);
    
    SDL_Window* win = SDL_CreateWindow("Text Adventure",100,100,WINDOW_WIDTH,WINDOW_HEIGHT,
            SDL_WINDOW_SHOWN);
    
    SDL_Renderer* ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | 
            SDL_RENDERER_PRESENTVSYNC);
    
    
    FontCharacterSet *fcs = new FontCharacterSet("fonts/test.fnt");
    
    FontRenderer *fr      = new FontRenderer(win,ren,fcs);
    fr->setWindowWidth(WINDOW_WIDTH);
    fr->setWindowHeight(WINDOW_HEIGHT);
    
    bool quit = false;
    SDL_Event e;
    
    while (!quit) {
        
        while(SDL_PollEvent( &e ) != 0 ) { //User requests quit if( e.type == SDL_QUIT ) { quit = true; } }
            if (e.type == SDL_QUIT) {
                quit = true;
            } else if (e.type == SDL_KEYDOWN) {
                
                switch (e.key.keysym.sym) {
                    case SDLK_f:
                        
                        fr->render(LOREM,0,0);
                     
                        break;
                    
                }
            }
        }  
    }
    
    delete fcs;
    delete fr;
    
    SDL_DestroyRenderer(ren);
    SDL_DestroyWindow(win);
    
    SDL_Quit();
    
    return 0;
}
Ejemplo n.º 5
0
    void SizeReferenceTileProvider::renderText(const FontRenderer& fontRenderer, const ChunkIndex& chunkIndex) const {
        GeodeticPatch patch(chunkIndex);
        bool aboveEquator = patch.isNorthern();
        
        double tileLongitudalLength = roundedLongitudalLength(chunkIndex);

        std::string unit = "m";
        if (tileLongitudalLength > 9999) {
            tileLongitudalLength *= 0.001;
            unit = "km";
        }

        glm::vec2 textPosition;
        textPosition.x = 0;
        textPosition.y = aboveEquator ? _fontSize / 2 : _textureSize.y - 3 * _fontSize / 2;
        glm::vec4 color(1.0, 1.0, 1.0, 1.0);

        fontRenderer.render(
            *_font,
            textPosition,
            color,
            " %.0f %s",
            tileLongitudalLength, unit.c_str()
            );
    }
Ejemplo n.º 6
0
 void ChunkIndexTileProvider::renderText(const FontRenderer& fontRenderer, const ChunkIndex& chunkIndex) const {
     fontRenderer.render(
         *_font,
         glm::vec2(
             _textureSize.x / 4 - (_textureSize.x / 32) * log10(1 << chunkIndex.level),
             _textureSize.y / 2 + _fontSize),
         glm::vec4(1.0, 0.0, 0.0, 1.0),
         "level: %i \nx: %i \ny: %i",
         chunkIndex.level, chunkIndex.x, chunkIndex.y
         );
 }
Ejemplo n.º 7
0
void TextTestApp::draw()
{
	// this pair of lines is the standard way to clear the screen in OpenGL
	glClearColor( 0,0,0,1 );
	glClear( GL_COLOR_BUFFER_BIT );
	
	if (flipScreen==true){
		gl::pushMatrices();
		
		gl::scale( Vec3f(-1, 1, 1) );
		gl::translate( Vec2f(-ci::app::getWindowWidth(), 0 ) );
		gl::translate( Vec3f(-1, 1, 1) );
	}

	gl::enableAlphaBlending();
	gl::enableAdditiveBlending();

	mbackground.draw();

	drawSkeleton();

	// FONT NOW GETS RENDERED AFTER SCENE SO WE CAN OVERRIDE DRAW OPERATION IF REQUIRED
	currentScene->draw();

	myFont.draw();	
	
	// kill this all and refresh
	gl::disableAlphaBlending();
	gl::enableAdditiveBlending();

	// store our viewport, so we can restore it later
	Area viewport = gl::getViewport();

	// render a simple scene into mFboScene
	gl::setViewport( mFboScene.getBounds() );
	mFboScene.bindFramebuffer();
		gl::pushMatrices();
		gl::setMatricesWindow( viewport.getWidth(), viewport.getHeight(), false );
			gl::clear( ColorA( 0,0,0,1 ));
			fgParticles.draw();
			//gl::drawSolidCircle( Vec2f(50,50), 20 );
			//gl::draw( mFboScene.getTexture() );//TODO - screenshot?
		gl::popMatrices();
	mFboScene.unbindFramebuffer();

	// bind the blur shader
	mShaderBlur.bind();
	mShaderBlur.uniform("tex0", 0); // use texture unit 0
 
	// tell the shader to blur horizontally and the size of 1 pixel
	mShaderBlur.uniform("sampleOffset", Vec2f(1.0f/mFboBlur1.getWidth(), 0.0f));

	// copy a horizontally blurred version of our scene into the first blur Fbo
	
	gl::setViewport( mFboBlur1.getBounds() );
	mFboBlur1.bindFramebuffer();
		mFboScene.bindTexture(0);
		gl::pushMatrices();
			gl::setMatricesWindow( viewport.getWidth(), viewport.getHeight(), false );
			gl::clear( Color::black() );
			gl::drawSolidRect( mFboBlur1.getBounds() );
		gl::popMatrices();
		mFboScene.unbindTexture();
	mFboBlur1.unbindFramebuffer();

 
	// tell the shader to blur vertically and the size of 1 pixel
	mShaderBlur.uniform("sampleOffset", Vec2f(0.0f, 1.0f/mFboBlur2.getHeight()));

	// copy a vertically blurred version of our blurred scene into the second blur Fbo
	gl::setViewport( mFboBlur2.getBounds() );
	mFboBlur2.bindFramebuffer();
		mFboBlur1.bindTexture(0);
		gl::pushMatrices();
			gl::setMatricesWindow( viewport.getWidth(), viewport.getHeight(), false );
			gl::clear( Color::black() );
			gl::drawSolidRect( mFboBlur2.getBounds() );
		gl::popMatrices();
		mFboBlur1.unbindTexture();
	mFboBlur2.unbindFramebuffer();

	// unbind the shader
	mShaderBlur.unbind();

	// restore the viewport
	gl::setViewport( viewport );
	// because the Fbo's have their origin in the LOWER-left corner,
	// flip the Y-axis before drawing
	gl::pushModelView();
	gl::translate( Vec2f(0, 0 ) );// viewport.getHeight() ) );
	gl::scale( Vec3f(1, 1, 1) );

	// draw the 3 Fbo's 
	//gl::color( Color::white() );
	//gl::draw( mFboScene.getTexture(), Rectf(0, 0, 256, 256) );
	//gl::draw( mFboBlur1.getTexture(), Rectf(260, 0, 260 + 256, 256) );
	//gl::draw( mFboBlur2.getTexture(), Rectf(520, 0, 520 + 256, 256) );

	// draw our scene with the blurred version added as a blend
	gl::color( Color::white() );
	
	gl::enableAdditiveBlending();
	gl::draw( mFboScene.getTexture(), Rectf(0, 0, viewport.getWidth(), viewport.getHeight() ));

	gl::draw( mFboBlur2.getTexture(), Rectf(0, 0, viewport.getWidth(), viewport.getHeight() ));
	gl::disableAlphaBlending();

	// restore the modelview matrix
	gl::popModelView();

	if (flipScreen == true){
		gl::popMatrices();
	}
	
	gl::color( Color(1.0,1.0,1.0) );
	
	
	//These are for debug only
	//drawTitleSafeArea();
	//OutlineParams::getInstance()->draw();
}
Ejemplo n.º 8
0
// todo: move this code to C# side.
// Renders world axis at the bottom-left corner.
static void RenderWorldAxis()
{
    RenderContext* rc = RenderContext::Inst();
    RenderSurface* surface = s_engineData->pRenderSurface;
    LineRenderer *lr = LineRenderer::Inst();
    Camera& cam = rc->Cam();    
    float margin = 36; // margin in pixels
    float xl = 28; // axis length in pixels.
    float vw = (float)surface->GetWidth();
    float vh = (float)surface->GetHeight();
    Matrix view = cam.View();    
    view.M41 = -vw/2 + margin;
    view.M42 = -vh/2 + margin;
    view.M43 = -xl;
    
    float3 look = cam.CamLook();    
    bool perspective = !cam.IsOrtho();

    // for orthographic hide one of the axis depending on view-type
    const float epsilon  = 0.001f; // use relatively large number for this test.
    bool renderX = perspective || abs(look.x) < epsilon;
    bool renderY = perspective || abs(look.y) < epsilon;
    bool renderZ = perspective || abs(look.z) < epsilon;
    
    Matrix proj = Matrix::CreateOrthographic(vw,vh,1,10000);
    cam.SetViewProj(view,proj);

    float3 centerV(0,0,0);
    // draw x,y,z
    if(renderX)
        lr->DrawLine(centerV,float3(xl,0,0),float4(1,0,0,1));    
    if(renderY)
        lr->DrawLine(centerV,float3(0,xl,0),float4(0,1,0,1));    
    if(renderZ)
        lr->DrawLine(centerV,float3(0,0,xl),float4(0,0,1,1));       

    lr->RenderAll(rc);

    Font* font = s_engineData->AxisFont;
    if(font)
    {   
        float fh = font->GetFontSize();
        float fhh = fh /2.0f;
        FontRenderer* fr = LvEdFonts::FontRenderer::Inst();
        Matrix vp = view * proj;
                
        // draw x,y,z
        if(renderX)
        {
            float3 xpos = surface->Project(float3(xl,fhh,0),vp);
            fr->DrawText(font,L"X",(int)xpos.x,(int)xpos.y,float4(1,0,0,1));
        }

        if(renderY)
        {
            float3 ypos = surface->Project(float3(0,xl+fhh,0),vp);
            fr->DrawText(font,L"Y",(int)ypos.x,(int)ypos.y,float4(0,1,0,1));
        }

        if(renderZ)
        {
            float3 zpos = surface->Project(float3(0,fhh,xl),vp);
            int ycoord =(int) ((zpos.y + fh) > vh ? vh - fh : zpos.y);
            fr->DrawText(font,L"Z",(int)zpos.x,ycoord,float4(0,0,1,1));
        }
        fr->FlushPrintRequests( rc );
    }    
    
}