コード例 #1
0
ファイル: IPointsDrw.cpp プロジェクト: AWhetter/alembic
//-*****************************************************************************
void IPointsDrw::draw( const DrawContext &iCtx )
{
    if ( !valid() )
    {
        return;
    }

    if ( !m_positions || m_positions->size() == 0 )
    {
        IObjectDrw::draw( iCtx );
        return;
    }

    size_t numPoints = m_positions->size();

    const V3f *points = m_positions->get();
    const C3f *colors = NULL;
    if ( m_colors  && ( m_colors->size() == numPoints ) )
    {
        colors = m_colors->get();
    }
    const N3f *normals = NULL;
    if ( m_normals && ( m_normals->size() == numPoints ) )
    {
        normals = m_normals->get();
    }

    if ( !normals )
    {
        glDisable( GL_LIGHTING );
    }

    if ( !colors )
    {
        glColor3f( 1.0f, 1.0f, 1.0f );
    }

    glEnable( GL_POINT_SMOOTH );
    glPointSize( iCtx.getPointSize() );

#ifndef SIMPLE_ABC_VIEWER_NO_GL_CLIENT_STATE
//#if 0
    {
        GL_NOISY( glEnableClientState( GL_VERTEX_ARRAY ) );
        if ( colors )
        {
            GL_NOISY( glEnableClientState( GL_COLOR_ARRAY ) );
            GL_NOISY( glColorPointer( 3, GL_FLOAT, 0,
                                      ( const GLvoid * )colors ) );
        }
        if ( normals )
        {
            GL_NOISY( glEnableClientState( GL_NORMAL_ARRAY ) );
            GL_NOISY( glNormalPointer( GL_FLOAT, 0,
                                       ( const GLvoid * )normals ) );
        }

        GL_NOISY( glVertexPointer( 3, GL_FLOAT, 0,
                                   ( const GLvoid * )points ) );

        GL_NOISY( glDrawArrays( GL_POINTS,
                                0, ( GLsizei )( numPoints ) ) );

        if ( colors )
        {
            GL_NOISY( glDisableClientState( GL_COLOR_ARRAY ) );
        }
        if ( normals )
        {
            GL_NOISY( glDisableClientState( GL_NORMAL_ARRAY ) );
        }
        GL_NOISY( glDisableClientState( GL_VERTEX_ARRAY ) );
    }
#else
    glBegin( GL_POINTS );

    for ( size_t i = 0; i < numPoints; ++i )
    {
        const V3f &vert = (*m_positions)[i];

        if ( colors )
        {
            const C3f &col = colors[i];
            glColor3fv( ( const GLfloat * )&col );
        }

        if ( normals )
        {
            const N3f &norm = normals[i];
            glNormal3fv( ( const GLfloat * )&norm );
        }

        glVertex3fv( ( const GLfloat * )&vert );
    }

    glEnd();

#endif

    glEnable( GL_LIGHTING );

    IObjectDrw::draw( iCtx );
}
コード例 #2
0
ファイル: MeshDrwHelper.cpp プロジェクト: hallLong/bb_alembic
//-*****************************************************************************
void MeshDrwHelper::draw( const DrawContext & iCtx ) const
{
    // Bail if invalid.
    if ( !m_valid || m_triangles.size() < 1 || !m_meshP )
    {
        return;
    }

    const V3f *points = m_meshP->get();
    const V3f *normals = NULL;
    if ( m_meshN  && ( m_meshN->size() == m_meshP->size() ) )
    {
        normals = m_meshN->get();
    }
    else if ( m_customN.size() == m_meshP->size() )
    {
        normals = &(m_customN.front());
    }

#ifndef SIMPLE_ABC_VIEWER_NO_GL_CLIENT_STATE
//#if 0
    {
        GL_NOISY( glEnableClientState( GL_VERTEX_ARRAY ) );
        if ( normals )
        {
            GL_NOISY( glEnableClientState( GL_NORMAL_ARRAY ) );
            GL_NOISY( glNormalPointer( GL_FLOAT, 0,
                                       ( const GLvoid * )normals ) );
        }

        GL_NOISY( glVertexPointer( 3, GL_FLOAT, 0,
                                   ( const GLvoid * )points ) );

        GL_NOISY( glDrawElements( GL_TRIANGLES,
                                  ( GLsizei )m_triangles.size() * 3,
                                  GL_UNSIGNED_INT,
                                  ( const GLvoid * )&(m_triangles[0]) ) );

        if ( normals )
        {
            GL_NOISY( glDisableClientState( GL_NORMAL_ARRAY ) );
        }
        GL_NOISY( glDisableClientState( GL_VERTEX_ARRAY ) );
    }
#else
    glBegin( GL_TRIANGLES );

    for ( size_t i = 0; i < m_triangles.size(); ++i )
    {
        const Tri &tri = m_triangles[i];
        const V3f &vertA = points[tri[0]];
        const V3f &vertB = points[tri[1]];
        const V3f &vertC = points[tri[2]];

        if ( normals )
        {
            const V3f &normA = normals[tri[0]];
            glNormal3fv( ( const GLfloat * )&normA );
            glVertex3fv( ( const GLfloat * )&vertA );

            const V3f &normB = normals[tri[1]];
            glNormal3fv( ( const GLfloat * )&normB );
            glVertex3fv( ( const GLfloat * )&vertB );

            const V3f &normC = normals[tri[2]];
            glNormal3fv( ( const GLfloat * )&normC );
            glVertex3fv( ( const GLfloat * )&vertC );
        }
        else
        {
            V3f AB = vertB - vertA;
            V3f AC = vertC - vertA;
            V3f N = AB.cross( AC );
            if ( N.length() > 1.0e-4f )
            {
                N.normalize();
                glNormal3fv( ( const GLfloat * )&N );
            }

            glVertex3fv( ( const GLfloat * )&vertA );

            glVertex3fv( ( const GLfloat * )&vertB );

            glVertex3fv( ( const GLfloat * )&vertC );
        }

    }

    glEnd();

#endif
}