渲染的一些代码

/**

 * draw will be called fps

 */

-(void) draw {

glDisable(GL_TEXTURE_2D);

glDisableClientState(GL_TEXTURE_COORD_ARRAY);

    [_renderdrawOpenGLBackground];

   glDisableClientState(GL_COLOR_ARRAY);

    

    /**画的时候也要体现出一个层次感来~ */

    [_renderdrawOneColorBackground];  //背景~

    

   _world->DrawDebugData();   // debugDraw(因为包含更多,所以放在画冰块儿后面)~

    

    

    [_renderdrawTouchPath:_mouseDowntouchSegment:_touchSegment]; //切割路径~

    [_renderdrawNails:_single.nailsnailsCount:_single.nailsCount];

    

    if(![_gCfg bfk:@"debugDraw"]) {

        [_renderdrawIce:_world];  //形状外框线条~

        [_renderdrawLittleMap:_world];

    }

    

// restore default GL states

glEnableClientState(GL_COLOR_ARRAY);

glEnableClientState(GL_TEXTURE_COORD_ARRAY);

   glEnable(GL_TEXTURE_2D);

}




// 绘制混色的背景~

-(void) drawOpenGLBackground {

    b2Vec2 vertices[4];

    if(_gCfg.isHd ==YES) {

        vertices[0] =b2Vec2(0.0f,640.0f);

        vertices[1] =b2Vec2(960.0f,640.0f);

        vertices[2] =b2Vec2(0.0f,0.0f);

        vertices[3] =b2Vec2(960.0f,0.0f);

    } else {

        vertices[0] =b2Vec2(0.0f,320.0f);

        vertices[1] =b2Vec2(480.0f,320.0f);

        vertices[2] =b2Vec2(0.0f,0.0f);

        vertices[3] =b2Vec2(480.0f,0.0f);

    }

    ccColor4F colors[4];

    colors[0] = (ccColor4F){1.0f,1.0f,0.0f,1.0f};

    colors[1] = (ccColor4F){0.0f,1.0f,0.0f,1.0f};

    colors[2] = (ccColor4F){0.0f,0.0f,1.0f,1.0f};

    colors[3] = (ccColor4F){1.0f,0.0f,0.0f,1.0f};

    

   //将顶点(x, y)数组和颜色(r, g, b, a)数组传给opengl

    glVertexPointer(2, GL_FLOAT, 0, vertices);

    glColorPointer(4, GL_FLOAT, 0, colors);

   glDrawArrays(GL_TRIANGLE_STRIP,0,4);

}



// 绘制单色的背景~

-(void) drawOneColorBackground {

    b2Vec2 vertices[4];

    if(_gCfg.isHd ==YES) {

        vertices[0]=b2Vec2(0.0f,640.0f);

        vertices[1]=b2Vec2(960.0f,640.0f);

        vertices[2]=b2Vec2(0.0f,0.0f);

        vertices[3]=b2Vec2(960.0f,0.0f);

    } else {

        vertices[0]=b2Vec2(0.0f,320.0f);

        vertices[1]=b2Vec2(480.0f,320.0f);

        vertices[2]=b2Vec2(0.0f,0.0f);

        vertices[3]=b2Vec2(480.0f,0.0f);

    }

   //将顶点(x, y)数组和颜色(r, g, b, a)数组传给opengl

    glColor4f(0.3f, 0.3f, 0.3f, 1.0f);    // 灰色

    glVertexPointer(2, GL_FLOAT, 0, vertices);

   glDrawArrays(GL_TRIANGLE_STRIP,0,4);

}



-(void) drawNails:(b2Vec2*)nails nailsCount:(int)nailsCount {

   /**绘制之前将所有的 b2Vec2 单元放大 PTM_RATIO ~ */

    b2Vec2 *handled = new b2Vec2[nailsCount];

    for(int i = 0; i < nailsCount; ++ i) {

        b2Vec2 item = nails[i];

        handled[i].Set(item.x *_gCfg.multiplyFactor, item.y *_gCfg.multiplyFactor);

    }

   glPointSize(8.0f);

   glColor4f(1.0f,0.0f,0.0f,1.0f);

    glVertexPointer(2, GL_FLOAT, 0, handled);

    glDrawArrays(GL_POINTS, 0, nailsCount);

   glPointSize(1.0f);   

}



-(void) drawIce:(b2World*)world {

    b2Body *bodyList = world->GetBodyList();

    for (b2Body* b = bodyList; b; b = b->GetNext()) {

        const b2Transform& xf = b->GetTransform();

        for (b2Fixture* f = b->GetFixtureList(); f; f = f->GetNext()) {

            if (b->IsActive() == false) {

                [selfdrawSolidPolygon:fxf:xf color:b2Color(0.5f,0.5f,0.3f)];

            } else if (b->GetType() ==b2_staticBody) {

                [selfdrawSolidPolygon:fxf:xf color:b2Color(0.5f,0.9f,0.5f)];

            } else if (b->GetType() ==b2_kinematicBody) {

                [selfdrawSolidPolygon:fxf:xf color:b2Color(0.5f,0.5f,0.9f)];

            } else if (b->IsAwake() ==false) {

                [selfdrawSolidPolygon:fxf:xf color:b2Color(0.6f,0.6f,0.6f)];

            } else {

                [selfdrawSolidPolygon:fxf:xf color:b2Color(0.9f,0.7f,0.7f)];

            }

        }

    }

}


posted on 2012-02-22 10:08  yang3wei  阅读(316)  评论(0编辑  收藏  举报