cocos2dx 绘制矩形 cocos2dx画矩形的源代码,是一个带有边框的矩形~
void GameLayer1::draw(void)
{
CCLayer::draw();
glEnable(GL_LINE_SMOOTH);
glLineWidth(1);
CCPoint vertices【】 = { ccp(100, 100), ccp(200, 100), ccp(200, 200), ccp(100, 200) };
glDisable(GL_TEXTURE_2D);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glColor4ub(255, 0, 0, 255);
glVertexPointer(2, GL_FLOAT, 0, vertices);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4); //画填充矩形
glColor4ub(0, 0, 255, 255);
glVertexPointer(2, GL_FLOAT, 0, vertices);
glDrawArrays(GL_LINE_LOOP, 0, 4); //画矩形边框
// restore default state
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_TEXTURE_2D);
}
重写draw函数如上就ok了