Ejemplo n.º 1
0
void CCRenderer::setupOpenGL()
{
    if( usingOpenGL2 )
    {
        // Use shader program
        currentShader = shaders.list[0];
        currentShader->use();

        currentShader->enableAttributeArray( ATTRIB_VERTEX );
        currentShader->enableAttributeArray( ATTRIB_TEXCOORD );
        DEBUG_OPENGL();
    }
    else
    {
#ifdef IOS
        // GL_TEXTURE_2D is not a valid argument to glEnable in OpenGL ES 2.0
        glEnable( GL_TEXTURE_2D );
        glEnableClientState( GL_VERTEX_ARRAY );
        glEnableClientState( GL_TEXTURE_COORD_ARRAY );
        glDisableClientState( GL_COLOR_ARRAY );
        DEBUG_OPENGL();

        CCSetColour( CCColour() );
#endif
    }

#ifndef DXRENDERER
    glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
    DEBUG_OPENGL();
#endif

    CCSetDepthRead( true );
    CCSetDepthWrite( true );
#ifndef DXRENDERER
    glDepthFunc( GL_LEQUAL );
    DEBUG_OPENGL();

    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

    glEnable( GL_SCISSOR_TEST );
    DEBUG_OPENGL();
#endif
    GLEnable( GL_BLEND );
    DEBUG_OPENGL();

#ifndef DXRENDERER
#ifndef Q_OS_SYMBIAN
    glClearDepthf( 1.0f );
    DEBUG_OPENGL();
#endif

    glLineWidth( LINE_WIDTH );
    DEBUG_OPENGL();
#endif

    // Enable back face culling
    CCSetCulling( true );
    CCSetBackCulling();
}
Ejemplo n.º 2
0
void CCSceneCollideable::renderCollisionBox()
{
	GLPushMatrix();
	{
		GLScalef( collisionBounds.x, collisionBounds.y, collisionBounds.z );
		//glColor4f( 1.0f, 1.0f, 0.0f, 0.5f );
        //RenderCube( true );
		
		gEngine->textureManager->setTextureIndex( 0 );
		GLRotatef( -rotation.y, 0.0f, 1.0f, 0.0f );
        static CCColour colour( 1.0f, 0.0f, 0.0f, 0.5f );
		CCSetColour( colour );
        CCRenderCube( true );
	}
	GLPopMatrix();
}
Ejemplo n.º 3
0
void CCModelBase::render(const bool alpha)
{
#if defined PROFILEON
    CCProfiler profile( "CCModelBase::render()" );
#endif

    if( shouldRender )
    {
        GLPushMatrix();
        {
            refreshModelMatrix();
            GLMultMatrixf( modelMatrix );
            
            gEngine->renderer->setShader( shader );

            if( colourOutline != NULL )
            {
#if defined PROFILEON
            	CCProfiler profile( "CCModelBase::render()::colourOutline" );
#endif
                CCSetColour( *colourOutline );
                if( alpha == false && ( CCGetColour().alpha > 0.0f ) )
                {
                    GLEnableBlend();
                }

                CCDefaultTexCoords();
                gEngine->textureManager->setTextureIndex( 0 );
                for( int i=0; i<primitives.length; ++i )
                {
                    primitives.list[i]->renderOutline();
                }

                if( alpha == false && ( CCGetColour().alpha > 0.0f ) )
                {
                    GLDisableBlend();
                }
            }

            if( colour != NULL )
            {
                CCSetColour( *colour );
            }

            if( alpha == false || colour == NULL || ( colour != NULL && colour->alpha > 0.0f ) )
            {
                for( int i=0; i<primitives.length; ++i )
                {
                    CCPrimitiveBase *primitive = primitives.list[i];
                    primitive->render();
                }
            }

            for( int i=0; i<models.length; ++i )
            {
                CCModelBase *model = models.list[i];
                model->render( alpha );
                if( colour != NULL )
                {
                    CCSetColour( *colour );
                }
            }
        }
        GLPopMatrix();
    }
}
Ejemplo n.º 4
0
void CCPathFinderNetwork::view()
{
    if( nodes.length > 0 && connectingNodes == false )
    {
		gEngine->textureManager->setTextureIndex( 1 );

        const CCColour nodeColour = CCColour( 1.0f, 0.0f, 0.0f, 1.0f );
        const CCColour pathColour = CCColour( 1.0f, 1.0f, 1.0f, 1.0f );

        CCSetColour( nodeColour );

        for( int i=0; i<nodes.length; ++i )
        {
            const PathNode *node = nodes.list[i];
            GLPushMatrix();
            GLTranslatef( node->point.x, node->point.y, node->point.z );
            CCRenderCube( true );
            GLPopMatrix();
        }

        static CCVector3 start, end;
		{
            GLVertexPointer( 3, GL_FLOAT, sizeof( PathNode ), &nodes.list[0]->point, nodes.length );
#ifndef DXRENDERER
            GLDrawArrays( GL_POINTS, 0, nodes.length );
#endif

            for( int i=0; i<nodes.length; ++i )
            {
                const PathNode *node = nodes.list[i];
                const CCList<PathNode::PathConnection> &connections = node->connections;
                for( int j=0; j<connections.length; ++j )
                {
                    const PathNode::PathConnection *connection = connections.list[j];
                    start.set( node->point.x, 2.0f, node->point.z );
                    end.set( connection->node->point.x, 2.0f, connection->node->point.z );
                    CCRenderLine( start, end );
                }
            }
        }

        if( pathingFrom != NULL )
        {
            CCRenderer::CCSetDepthRead( false );

            CCSetColour( pathColour );

            const PathNode *currentNode = pathingFrom;
            for( int i=0; i<path.endDirection; ++i )
            {
                const int connectionIndex = path.directions[i];
                const CCList<PathNode::PathConnection> &connections = currentNode->connections;
                if( connectionIndex < connections.length )
                {
                    const PathNode::PathConnection *connection = connections.list[connectionIndex];
                    const PathNode *toNode = connection->node;
                    ASSERT( toNode != NULL );
                    start.set( currentNode->point.x, 5.0f, currentNode->point.z );
                    end.set( toNode->point.x, 5.0f, toNode->point.z );
                    CCRenderLine( start, end );
                    currentNode = toNode;
                }
            }

            CCRenderer::CCSetDepthRead( true );
        }
    }
}
Ejemplo n.º 5
0
const bool CCWidgetBase::render(const bool foreground)
{	
	if( inView && enabled && foreground == renderForeground )
	{
		if( colour == NULL )
		{
            static CCColour colour( 1.0f, 1.0f, 1.0f, 0.75f );
			CCSetColour( colour );
		}
		else
		{
			CCSetColour( *colour );
		}
		
		if( renderButton )
		{
            if( textureIndex != 0 )
			{
				gEngine->textureManager->setTextureIndex( textureIndex );
				
				if( customUVs != NULL )
				{
					CCSetTexCoords( customUVs->uvs );
				}
				else
				{
					CCDefaultTexCoords();
				}
			}
			else
			{
				gEngine->textureManager->setTextureIndex( 0 );
			}
			
			CCRenderRectanglePoint( position, size.width, -size.height );
			
			if( renderOutline )
			{
				if( colour == NULL )
				{
                    static CCColour colour( 0.5f, 0.5f, 0.5f, 0.75f );
					CCSetColour( colour );
				}
				else
				{
                    CCColour colourObject( colour->red * 0.5f, colour->green * 0.5f, colour->blue * 0.5f, colour->alpha );
					CCSetColour( colourObject );
				}
				CCRenderRectanglePoint( position, size.width, -size.height, true );
			}
			
			if( distortEffect )
			{
                static CCColour colour( 1.0f, 1.0f, 1.0f, 0.5f );
				CCSetColour( colour );
				CCRenderRectanglePoint( position, size.width + distortTarget.x, size.height + distortTarget.y );
			}
		}
		
		return true;
	}
	
	return false;
}
Ejemplo n.º 6
0
void CCEngine::renderLoop()
{	
#if defined PROFILEON
    CCProfiler profile( "CCEngine::render()" );
#endif
    
    // Tell the texture manager we're rendering a new frame
    gEngine->textureManager->prepareRender();
    {
        CCList<CCSceneCollideable> &collideables = collisionManager.collideables;
        for( int i=0; i<collideables.length; ++i )
        {
            collideables.list[i]->visible = false;
        }
    }
    CCTile3DFrameBuffer::ResetRenderFlag();
    
	for( int cameraIndex=0; cameraIndex<cameras.length; ++cameraIndex )
    {
		CCCameraBase *currentCamera = CCCameraBase::currentCamera = cameras.list[cameraIndex];
		if( currentCamera->isEnabled() == false )
		{
			continue;
		}
        
        if( currentCamera->getFrameBufferId() != -1 )
        {
            continue;
        }


#if defined PROFILEON
		CCProfiler profile( "CCEngine::render()::camera" );
#endif

        currentCamera->setViewport();
		
		// 2D Background
        if( false )
		{	
			CCMatrix matrix;
			CCMatrixLoadIdentity( matrix );
			CCMatrixRotate( matrix, CCViewManager::GetOrientation().current, 0.0f, 0.0f, 1.0f );
			CCMatrixOrtho( matrix, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f );
			GLSetPushMatrix( matrix );
			
			for( int i=0; i<scenes.length; ++i )
			{
				scenes.list[i]->render2DBackground( cameraIndex );
			}
		}
		
		// 3D Rendering
		GLEnableDepth();
        extern bool gUseProjectionMatrix; 
		gUseProjectionMatrix = true;
		{	
			currentCamera->update();
			
			for( uint pass=render_background; pass<render_finished; ++pass )
			{
#if defined PROFILEON
				CCProfiler profile( "CCEngine::render()::pass" );
#endif

				// Render all the non-collideables
				GLDisableBlend();
				for( int i=0; i<scenes.length; ++i )
				{
					scenes.list[i]->render( currentCamera, pass, false );
				}
				
				// Render all the visible collideables
				{
#if defined PROFILEON
					CCProfiler profile( "CCOctreeRenderVisibleObjects( false )" );
#endif
					CCOctreeRenderVisibleObjects( currentCamera, pass, false );
				}
				
				GLEnableBlend();
				
				if( pass == render_main )
				{	
					if( CCHasFlag( gEngine->renderFlags, render_collisionTrees ) )
					{
						CCOctreeRender( collisionManager.tree );
					}
                    
                    if( CCHasFlag( gEngine->renderFlags, render_pathFinder ) )
					{
						collisionManager.pathFinderNetwork.view();
					}
				}
				
				if( pass == render_main )
				{
					// Keep it disabled for the rest of the renders
					GLDisableDepth();
				}
				
				for( int i=0; i<scenes.length; ++i )
				{
					scenes.list[i]->render( currentCamera, pass, true );
				}
				
				// Render all the visible collideables
				{

#if defined PROFILEON
					CCProfiler profile( "CCOctreeRenderVisibleObjects( true )" );
#endif
					CCOctreeRenderVisibleObjects( currentCamera, pass, true );
				}
			}
		}
		gUseProjectionMatrix = false;
		
		// 2D Rendering
        if( false )
		{
			CCMatrix matrix;
			CCMatrixLoadIdentity( matrix );
			CCMatrixRotate( matrix, CCViewManager::GetOrientation().current, 0.0f, 0.0f, 1.0f );
			CCMatrixOrtho( matrix, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f );
			GLSetPushMatrix( matrix );
			
            for( int i=0; i<scenes.length; ++i )
            {
                scenes.list[i]->render2DForeground( cameraIndex );
            }
			
#ifdef DEBUGON
			if( CCHasFlag( gEngine->renderFlags, render_fontPage ) )
			{
				CCSetColour( CCColour() );
				textureManager->fontPages.list[0]->view();
			}
#endif
		}
		
		currentCamera = NULL;
	}
}