Ejemplo n.º 1
0
void Entity::Render( float ticks ) throw(std::exception)
{
    DoUpdate(ticks);
    glPushMatrix();
    glMultMatrixf( GetRenderState()->GetMatrix() );

    uint32_t flags = GetRenderState()->GetFlags();

    int gl_blend_src(0), gl_blend_dst(0);
    int alpha_enabled;
    glGetIntegerv(GL_ALPHA_TEST, &alpha_enabled);
    if (!alpha_enabled && (flags & RenderState::ALPHA_F) )
    {
        glGetIntegerv(GL_BLEND_SRC, &gl_blend_src);
        glGetIntegerv(GL_BLEND_DST, &gl_blend_dst);
        glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glEnable(GL_ALPHA_TEST);
    }
    else if (alpha_enabled && (flags & RenderState::ALPHA_F) == 0 )
    {
        glDisable(GL_ALPHA_TEST);
    }
    int blend_enabled;
    glGetIntegerv(GL_BLEND, &blend_enabled);
    if (!blend_enabled && (flags & RenderState::BLEND_F) )
    {
        glEnable(GL_BLEND);
    }
    else if ( blend_enabled && (flags & RenderState::BLEND_F) == 0 )
    {
        glDisable(GL_BLEND);
    }

    for( auto it = m_RenderList.begin(); it != m_RenderList.end(); ) {
        EntityPtr entity = *it;
        if ( entity->AreFlagsSet( Entity::F_ENABLE ) ) {
            entity->Render( ticks );
        }
        if ( entity->AreFlagsSet( Entity::F_DELETE ) ) {
            it = m_RenderList.erase( it );
            continue;
        }
        ++it;
    }
    DoRender();

    if (!alpha_enabled && (flags & RenderState::ALPHA_F) )
    {
        glBlendFunc( gl_blend_src, gl_blend_dst);
    }
    glPopMatrix();
}
Ejemplo n.º 2
0
void Buffered::Render( float ticks )
{
    // backup viewport
    GLint vp[4];
    glGetIntegerv( GL_VIEWPORT, vp );
    GLfloat depth[2];
    glGetFloatv( GL_DEPTH_RANGE, depth );

    // backup projection matrix for internal storage
    Matrix modelview;
    glGetFloatv( GL_MODELVIEW_MATRIX, (float*)modelview );
    Matrix projection;
    glGetFloatv( GL_PROJECTION_MATRIX, (float*)projection );

    m_FrameBuffer.Enable();

    // background color
    glClearColor( 1,1,1,1 );
    // clear buffer
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    for( auto it = m_RenderList.begin(); it != m_RenderList.end(); ) {
        EntityPtr entity = *it;
        if ( entity->AreFlagsSet( Entity::F_ENABLE ) ) {
            entity->Render(ticks);
        }
        if ( entity->AreFlagsSet( Entity::F_DELETE ) ) {
            it = m_RenderList.erase( it );
            continue;
        }
        ++it;
    }
    m_FrameBuffer.Disable();

    // restore view port
    glViewport( vp[0], vp[1], vp[2], vp[3]);
    glMatrixMode(GL_PROJECTION);
    glLoadMatrixf( projection );
    glMatrixMode(GL_MODELVIEW);
    glLoadMatrixf( modelview );

    DoUpdate( ticks );

    // render local list into texture
    glPushMatrix();
    glMultMatrixf(GetRenderState()->GetMatrix());
    Cube::DoRender();
    glPopMatrix();
}