2012-04-19 14:35:52 +08:00
|
|
|
#include "DrawPrimitivesTest.h"
|
2014-04-30 08:37:36 +08:00
|
|
|
#include "renderer/CCRenderer.h"
|
|
|
|
#include "renderer/CCCustomCommand.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2015-04-09 08:37:30 +08:00
|
|
|
USING_NS_CC;
|
|
|
|
|
2014-09-15 16:23:57 +08:00
|
|
|
#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
|
|
|
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
|
|
|
#elif _MSC_VER >= 1400 //vs 2005 or higher
|
|
|
|
#pragma warning (push)
|
|
|
|
#pragma warning (disable: 4996)
|
|
|
|
#endif
|
|
|
|
|
2012-11-21 11:43:08 +08:00
|
|
|
using namespace std;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
DrawPrimitivesTests::DrawPrimitivesTests()
|
2012-11-21 11:43:08 +08:00
|
|
|
{
|
2015-04-03 14:31:03 +08:00
|
|
|
ADD_TEST_CASE(DrawPrimitivesTest);
|
|
|
|
ADD_TEST_CASE(DrawNodeTest);
|
2015-08-26 06:07:03 +08:00
|
|
|
ADD_TEST_CASE(PrimitivesCommandTest);
|
2016-07-07 08:21:58 +08:00
|
|
|
ADD_TEST_CASE(Issue11942Test);
|
2012-11-21 11:43:08 +08:00
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
string DrawPrimitivesBaseTest::title() const
|
2012-11-21 11:43:08 +08:00
|
|
|
{
|
|
|
|
return "No title";
|
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-11-21 11:43:08 +08:00
|
|
|
// DrawPrimitivesTest
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-11-21 11:43:08 +08:00
|
|
|
DrawPrimitivesTest::DrawPrimitivesTest()
|
|
|
|
{
|
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2014-05-31 07:42:05 +08:00
|
|
|
void DrawPrimitivesTest::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
|
2012-11-21 11:43:08 +08:00
|
|
|
{
|
2014-01-19 03:35:27 +08:00
|
|
|
_customCommand.init(_globalZOrder);
|
2014-05-31 07:42:05 +08:00
|
|
|
_customCommand.func = CC_CALLBACK_0(DrawPrimitivesTest::onDraw, this, transform, flags);
|
2014-03-01 08:10:48 +08:00
|
|
|
renderer->addCommand(&_customCommand);
|
2013-12-25 11:44:05 +08:00
|
|
|
}
|
|
|
|
|
2014-05-31 07:42:05 +08:00
|
|
|
void DrawPrimitivesTest::onDraw(const Mat4 &transform, uint32_t flags)
|
2013-12-25 11:44:05 +08:00
|
|
|
{
|
2014-04-03 15:59:55 +08:00
|
|
|
Director* director = Director::getInstance();
|
|
|
|
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
|
|
|
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform);
|
2012-11-21 11:43:08 +08:00
|
|
|
|
2013-12-25 11:44:05 +08:00
|
|
|
//draw
|
|
|
|
CHECK_GL_ERROR_DEBUG();
|
2012-11-21 11:43:08 +08:00
|
|
|
|
2013-12-25 11:46:40 +08:00
|
|
|
// draw a simple line
|
|
|
|
// The default state is:
|
|
|
|
// Line Width: 1
|
|
|
|
// color: 255,255,255,255 (white, non-transparent)
|
|
|
|
// Anti-Aliased
|
|
|
|
// glEnable(GL_LINE_SMOOTH);
|
2013-07-26 05:49:43 +08:00
|
|
|
DrawPrimitives::drawLine( VisibleRect::leftBottom(), VisibleRect::rightTop() );
|
2012-11-21 11:43:08 +08:00
|
|
|
|
2013-12-25 11:46:40 +08:00
|
|
|
CHECK_GL_ERROR_DEBUG();
|
2012-11-21 11:43:08 +08:00
|
|
|
|
2013-12-25 11:44:05 +08:00
|
|
|
// line: color, width, aliased
|
2013-12-25 11:46:40 +08:00
|
|
|
// glLineWidth > 1 and GL_LINE_SMOOTH are not compatible
|
|
|
|
// GL_SMOOTH_LINE_WIDTH_RANGE = (1,1) on iPhone
|
|
|
|
// glDisable(GL_LINE_SMOOTH);
|
|
|
|
glLineWidth( 5.0f );
|
|
|
|
DrawPrimitives::setDrawColor4B(255,0,0,255);
|
2013-07-26 05:49:43 +08:00
|
|
|
DrawPrimitives::drawLine( VisibleRect::leftTop(), VisibleRect::rightBottom() );
|
2012-11-21 11:43:08 +08:00
|
|
|
|
2013-12-25 11:46:40 +08:00
|
|
|
CHECK_GL_ERROR_DEBUG();
|
2012-11-21 11:43:08 +08:00
|
|
|
|
2013-12-25 11:46:40 +08:00
|
|
|
// TIP:
|
|
|
|
// If you are going to use always thde same color or width, you don't
|
|
|
|
// need to call it before every draw
|
|
|
|
//
|
|
|
|
// Remember: OpenGL is a state-machine.
|
2012-11-21 11:43:08 +08:00
|
|
|
|
2013-12-25 11:46:40 +08:00
|
|
|
// draw big point in the center
|
|
|
|
DrawPrimitives::setPointSize(64);
|
|
|
|
DrawPrimitives::setDrawColor4B(0,0,255,128);
|
2013-07-26 05:49:43 +08:00
|
|
|
DrawPrimitives::drawPoint( VisibleRect::center() );
|
2012-11-21 11:43:08 +08:00
|
|
|
|
2013-12-25 11:46:40 +08:00
|
|
|
CHECK_GL_ERROR_DEBUG();
|
2012-11-21 11:43:08 +08:00
|
|
|
|
2013-12-25 11:46:40 +08:00
|
|
|
// draw 4 small points
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 points[] = { Vec2(60,60), Vec2(70,70), Vec2(60,70), Vec2(70,60) };
|
2013-12-25 11:46:40 +08:00
|
|
|
DrawPrimitives::setPointSize(4);
|
|
|
|
DrawPrimitives::setDrawColor4B(0,255,255,255);
|
|
|
|
DrawPrimitives::drawPoints( points, 4);
|
2012-11-21 11:43:08 +08:00
|
|
|
|
2013-12-25 11:46:40 +08:00
|
|
|
CHECK_GL_ERROR_DEBUG();
|
2012-11-21 11:43:08 +08:00
|
|
|
|
2013-12-25 11:46:40 +08:00
|
|
|
// draw a green circle with 10 segments
|
|
|
|
glLineWidth(16);
|
|
|
|
DrawPrimitives::setDrawColor4B(0, 255, 0, 255);
|
2013-07-26 05:49:43 +08:00
|
|
|
DrawPrimitives::drawCircle( VisibleRect::center(), 100, 0, 10, false);
|
2012-11-21 11:43:08 +08:00
|
|
|
|
2013-12-25 11:46:40 +08:00
|
|
|
CHECK_GL_ERROR_DEBUG();
|
2012-11-21 11:43:08 +08:00
|
|
|
|
2013-12-25 11:46:40 +08:00
|
|
|
// draw a green circle with 50 segments with line to center
|
|
|
|
glLineWidth(2);
|
|
|
|
DrawPrimitives::setDrawColor4B(0, 255, 255, 255);
|
2013-07-26 05:49:43 +08:00
|
|
|
DrawPrimitives::drawCircle( VisibleRect::center(), 50, CC_DEGREES_TO_RADIANS(90), 50, true);
|
2012-11-21 11:43:08 +08:00
|
|
|
|
2013-12-25 11:46:40 +08:00
|
|
|
CHECK_GL_ERROR_DEBUG();
|
2012-11-21 11:43:08 +08:00
|
|
|
|
2013-12-25 11:46:40 +08:00
|
|
|
// draw a pink solid circle with 50 segments
|
|
|
|
glLineWidth(2);
|
|
|
|
DrawPrimitives::setDrawColor4B(255, 0, 255, 255);
|
2014-05-15 01:07:09 +08:00
|
|
|
DrawPrimitives::drawSolidCircle( VisibleRect::center() + Vec2(140,0), 40, CC_DEGREES_TO_RADIANS(90), 50, 1.0f, 1.0f);
|
2013-07-03 04:39:16 +08:00
|
|
|
|
2013-12-25 11:46:40 +08:00
|
|
|
CHECK_GL_ERROR_DEBUG();
|
2013-07-03 04:39:16 +08:00
|
|
|
|
2013-12-25 11:46:40 +08:00
|
|
|
// open yellow poly
|
|
|
|
DrawPrimitives::setDrawColor4B(255, 255, 0, 255);
|
|
|
|
glLineWidth(10);
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 vertices[] = { Vec2(0,0), Vec2(50,50), Vec2(100,50), Vec2(100,100), Vec2(50,100) };
|
2013-12-25 11:46:40 +08:00
|
|
|
DrawPrimitives::drawPoly( vertices, 5, false);
|
2012-11-21 11:43:08 +08:00
|
|
|
|
2013-12-25 11:46:40 +08:00
|
|
|
CHECK_GL_ERROR_DEBUG();
|
|
|
|
|
|
|
|
// filled poly
|
|
|
|
glLineWidth(1);
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 filledVertices[] = { Vec2(0,120), Vec2(50,120), Vec2(50,170), Vec2(25,200), Vec2(0,170) };
|
2013-12-25 11:46:40 +08:00
|
|
|
DrawPrimitives::drawSolidPoly(filledVertices, 5, Color4F(0.5f, 0.5f, 1, 1 ) );
|
2012-11-21 11:43:08 +08:00
|
|
|
|
|
|
|
|
2013-12-25 11:46:40 +08:00
|
|
|
// closed purble poly
|
|
|
|
DrawPrimitives::setDrawColor4B(255, 0, 255, 255);
|
|
|
|
glLineWidth(2);
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 vertices2[] = { Vec2(30,130), Vec2(30,230), Vec2(50,200) };
|
2013-12-25 11:46:40 +08:00
|
|
|
DrawPrimitives::drawPoly( vertices2, 3, true);
|
2012-11-21 11:43:08 +08:00
|
|
|
|
2013-12-25 11:46:40 +08:00
|
|
|
CHECK_GL_ERROR_DEBUG();
|
2012-11-21 11:43:08 +08:00
|
|
|
|
2013-12-25 11:46:40 +08:00
|
|
|
// draw quad bezier path
|
2013-07-26 05:49:43 +08:00
|
|
|
DrawPrimitives::drawQuadBezier(VisibleRect::leftTop(), VisibleRect::center(), VisibleRect::rightTop(), 50);
|
2012-11-21 11:43:08 +08:00
|
|
|
|
2013-12-25 11:46:40 +08:00
|
|
|
CHECK_GL_ERROR_DEBUG();
|
2012-11-21 11:43:08 +08:00
|
|
|
|
2013-12-25 11:46:40 +08:00
|
|
|
// draw cubic bezier path
|
2014-05-15 01:07:09 +08:00
|
|
|
DrawPrimitives::drawCubicBezier(VisibleRect::center(), Vec2(VisibleRect::center().x+30,VisibleRect::center().y+50), Vec2(VisibleRect::center().x+60,VisibleRect::center().y-50),VisibleRect::right(),100);
|
2012-11-21 11:43:08 +08:00
|
|
|
|
2013-12-25 11:46:40 +08:00
|
|
|
CHECK_GL_ERROR_DEBUG();
|
2012-06-12 16:56:34 +08:00
|
|
|
|
|
|
|
//draw a solid polygon
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 vertices3[] = {Vec2(60,160), Vec2(70,190), Vec2(100,190), Vec2(90,160)};
|
2013-07-26 05:49:43 +08:00
|
|
|
DrawPrimitives::drawSolidPoly( vertices3, 4, Color4F(1,1,0,1) );
|
2012-11-21 11:43:08 +08:00
|
|
|
|
2013-12-25 11:46:40 +08:00
|
|
|
// restore original values
|
|
|
|
glLineWidth(1);
|
|
|
|
DrawPrimitives::setDrawColor4B(255,255,255,255);
|
|
|
|
DrawPrimitives::setPointSize(1);
|
2012-11-21 11:43:08 +08:00
|
|
|
|
2013-12-25 11:46:40 +08:00
|
|
|
CHECK_GL_ERROR_DEBUG();
|
2013-12-25 11:44:05 +08:00
|
|
|
|
|
|
|
//end draw
|
2014-04-03 15:59:55 +08:00
|
|
|
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
2012-11-21 11:43:08 +08:00
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
string DrawPrimitivesTest::title() const
|
2012-11-21 11:43:08 +08:00
|
|
|
{
|
|
|
|
return "draw primitives";
|
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
string DrawPrimitivesTest::subtitle() const
|
2012-11-21 11:43:08 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
return "Drawing Primitives. Use DrawNode instead";
|
2012-11-21 11:43:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// DrawNodeTest
|
|
|
|
DrawNodeTest::DrawNodeTest()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2012-11-21 11:43:08 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto draw = DrawNode::create();
|
2012-11-21 11:43:08 +08:00
|
|
|
addChild(draw, 10);
|
|
|
|
|
2014-09-11 15:39:56 +08:00
|
|
|
draw->drawPoint(Vec2(s.width/2-120, s.height/2-120), 10, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1));
|
|
|
|
|
|
|
|
draw->drawPoint(Vec2(s.width/2+120, s.height/2+120), 10, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1));
|
|
|
|
|
|
|
|
// draw 4 small points
|
|
|
|
Vec2 position[] = { Vec2(60,60), Vec2(70,70), Vec2(60,70), Vec2(70,60) };
|
2015-01-13 22:30:50 +08:00
|
|
|
draw->drawPoints( position, 4, 5, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1));
|
2014-09-11 15:39:56 +08:00
|
|
|
|
|
|
|
// draw a line
|
|
|
|
draw->drawLine(Vec2(0,0), Vec2(s.width, s.height), Color4F(1.0, 0.0, 0.0, 0.5));
|
|
|
|
|
|
|
|
// draw a rectangle
|
|
|
|
draw->drawRect(Vec2(23,23), Vec2(7,7), Color4F(1,1,0,1));
|
|
|
|
|
2015-01-07 11:44:16 +08:00
|
|
|
draw->drawRect(Vec2(15,30), Vec2(30,15), Vec2(15,0), Vec2(0,15), Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1));
|
|
|
|
|
2014-09-11 15:39:56 +08:00
|
|
|
// draw a circle
|
|
|
|
draw->drawCircle(VisibleRect::center() + Vec2(140,0), 100, CC_DEGREES_TO_RADIANS(90), 50, true, 1.0f, 2.0f, Color4F(1.0, 0.0, 0.0, 0.5));
|
|
|
|
|
|
|
|
draw->drawCircle(VisibleRect::center() - Vec2(140,0), 50, CC_DEGREES_TO_RADIANS(90), 30, false, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1));
|
|
|
|
|
|
|
|
// Draw some beziers
|
|
|
|
draw->drawQuadBezier(Vec2(s.width - 150, s.height - 150), Vec2(s.width - 70, s.height - 10), Vec2(s.width - 10, s.height - 10), 10, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 0.5));
|
|
|
|
|
|
|
|
draw->drawQuadBezier(Vec2(0, s.height), Vec2(s.width/2, s.height/2), Vec2(s.width, s.height), 50, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 0.5));
|
|
|
|
|
|
|
|
draw->drawCubicBezier(VisibleRect::center(), Vec2(VisibleRect::center().x+30,VisibleRect::center().y+50), Vec2(VisibleRect::center().x+60,VisibleRect::center().y-50),VisibleRect::right(),100, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 0.5));
|
|
|
|
|
|
|
|
draw->drawCubicBezier(Vec2(s.width - 250, 40), Vec2(s.width - 70, 100), Vec2(s.width - 30, 250), Vec2(s.width - 10, s.height - 50), 10, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 0.5));
|
|
|
|
|
|
|
|
auto array = PointArray::create(20);
|
|
|
|
array->addControlPoint(Vec2(0,0));
|
|
|
|
array->addControlPoint(Vec2(80,80));
|
|
|
|
array->addControlPoint(Vec2(s.width-80,80));
|
|
|
|
array->addControlPoint(Vec2(s.width-80,s.height-80));
|
|
|
|
array->addControlPoint(Vec2(80,s.height-80));
|
|
|
|
array->addControlPoint(Vec2(80,80));
|
|
|
|
array->addControlPoint(Vec2(s.width/2, s.height/2));
|
|
|
|
draw->drawCardinalSpline(array, 0.5, 50, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 0.5));
|
|
|
|
|
|
|
|
auto array2 = PointArray::create(20);
|
|
|
|
array2->addControlPoint(Vec2(s.width / 2, 30));
|
|
|
|
array2->addControlPoint(Vec2(s.width -80, 30));
|
|
|
|
array2->addControlPoint(Vec2(s.width - 80, s.height - 80));
|
|
|
|
array2->addControlPoint(Vec2(s.width / 2, s.height - 80));
|
|
|
|
array2->addControlPoint(Vec2(s.width / 2, 30));
|
|
|
|
draw->drawCatmullRom(array2, 50, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 0.5));
|
|
|
|
|
|
|
|
// open random color poly
|
|
|
|
Vec2 vertices[] = { Vec2(0,0), Vec2(50,50), Vec2(100,50), Vec2(100,100), Vec2(50,100) };
|
|
|
|
draw->drawPoly( vertices, 5, false, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1));
|
|
|
|
|
|
|
|
// closed random color poly
|
|
|
|
Vec2 vertices2[] = { Vec2(30,130), Vec2(30,230), Vec2(50,200) };
|
|
|
|
draw->drawPoly( vertices2, 3, true, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1));
|
|
|
|
|
2012-11-21 11:43:08 +08:00
|
|
|
// Draw 10 circles
|
|
|
|
for( int i=0; i < 10; i++)
|
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
draw->drawDot(Vec2(s.width/2, s.height/2), 10*(10-i), Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1));
|
2012-11-21 11:43:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Draw polygons
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 points[] = { Vec2(s.height/4,0), Vec2(s.width,s.height/5), Vec2(s.width/3*2,s.height) };
|
2014-09-11 15:39:56 +08:00
|
|
|
draw->drawPolygon(points, sizeof(points)/sizeof(points[0]), Color4F(1,0,0,0.5), 4, Color4F(0,0,1,0.5));
|
2012-11-21 11:43:08 +08:00
|
|
|
|
|
|
|
// star poly (triggers buggs)
|
|
|
|
{
|
|
|
|
const float o=80;
|
|
|
|
const float w=20;
|
|
|
|
const float h=50;
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 star[] = {
|
|
|
|
Vec2(o+w,o-h), Vec2(o+w*2, o), // lower spike
|
|
|
|
Vec2(o + w*2 + h, o+w ), Vec2(o + w*2, o+w*2), // right spike
|
2013-12-25 11:46:40 +08:00
|
|
|
// {o +w, o+w*2+h}, {o,o+w*2}, // top spike
|
|
|
|
// {o -h, o+w}, {o,o}, // left spike
|
2012-11-21 11:43:08 +08:00
|
|
|
};
|
|
|
|
|
2013-07-05 16:49:22 +08:00
|
|
|
draw->drawPolygon(star, sizeof(star)/sizeof(star[0]), Color4F(1,0,0,0.5), 1, Color4F(0,0,1,1));
|
2012-11-21 11:43:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// star poly (doesn't trigger bug... order is important un tesselation is supported.
|
|
|
|
{
|
|
|
|
const float o=180;
|
|
|
|
const float w=20;
|
|
|
|
const float h=50;
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 star[] = {
|
|
|
|
Vec2(o,o), Vec2(o+w,o-h), Vec2(o+w*2, o), // lower spike
|
|
|
|
Vec2(o + w*2 + h, o+w ), Vec2(o + w*2, o+w*2), // right spike
|
|
|
|
Vec2(o +w, o+w*2+h), Vec2(o,o+w*2), // top spike
|
|
|
|
Vec2(o -h, o+w), // left spike
|
2012-11-21 11:43:08 +08:00
|
|
|
};
|
|
|
|
|
2013-07-05 16:49:22 +08:00
|
|
|
draw->drawPolygon(star, sizeof(star)/sizeof(star[0]), Color4F(1,0,0,0.5), 1, Color4F(0,0,1,1));
|
2012-11-21 11:43:08 +08:00
|
|
|
}
|
|
|
|
|
2014-09-11 15:39:56 +08:00
|
|
|
//draw a solid polygon
|
|
|
|
Vec2 vertices3[] = {Vec2(60,160), Vec2(70,190), Vec2(100,190), Vec2(90,160)};
|
|
|
|
draw->drawSolidPoly( vertices3, 4, Color4F(1,1,0,1) );
|
|
|
|
|
|
|
|
//draw a solid rectangle
|
|
|
|
draw->drawSolidRect(Vec2(10,10), Vec2(20,20), Color4F(1,1,0,1));
|
|
|
|
|
|
|
|
//draw a solid circle
|
|
|
|
draw->drawSolidCircle( VisibleRect::center() + Vec2(140,0), 40, CC_DEGREES_TO_RADIANS(90), 50, 2.0f, 2.0f, Color4F(0.0, 1.0, 0.0, 1.0));
|
2012-11-21 11:43:08 +08:00
|
|
|
|
|
|
|
// Draw segment
|
2014-05-15 01:07:09 +08:00
|
|
|
draw->drawSegment(Vec2(20,s.height), Vec2(20,s.height/2), 10, Color4F(0, 1, 0, 1));
|
2014-09-11 15:39:56 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
draw->drawSegment(Vec2(10,s.height/2), Vec2(s.width/2, s.height/2), 40, Color4F(1, 0, 1, 0.5));
|
2013-10-14 12:52:58 +08:00
|
|
|
|
|
|
|
// Draw triangle
|
2014-05-15 01:07:09 +08:00
|
|
|
draw->drawTriangle(Vec2(10, 10), Vec2(70, 30), Vec2(100, 140), Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 0.5));
|
2014-10-24 12:03:11 +08:00
|
|
|
|
|
|
|
for (int i = 0; i < 100; i++) {
|
2015-01-13 22:30:50 +08:00
|
|
|
draw->drawPoint(Vec2(i*7, 5), (float)i/5+1, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1));
|
2014-10-24 12:03:11 +08:00
|
|
|
}
|
2015-12-03 14:21:00 +08:00
|
|
|
|
|
|
|
auto draw1 = DrawNode::create();
|
|
|
|
this->addChild(draw1, 10);
|
2015-12-04 14:55:54 +08:00
|
|
|
draw1->setLineWidth(4);
|
2015-12-03 14:21:00 +08:00
|
|
|
draw1->drawLine(Vec2(0, s.height), Vec2(s.width, s.height - 20), Color4F::YELLOW);
|
|
|
|
draw1->drawLine(Vec2(0, 0), Vec2(s.width, s.height - 20), Color4F::YELLOW);
|
2012-11-21 11:43:08 +08:00
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
string DrawNodeTest::title() const
|
2012-11-21 11:43:08 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
return "Test DrawNode";
|
2012-11-21 11:43:08 +08:00
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
string DrawNodeTest::subtitle() const
|
2012-11-21 11:43:08 +08:00
|
|
|
{
|
|
|
|
return "Testing DrawNode - batched draws. Concave polygons are BROKEN";
|
2010-08-26 10:53:49 +08:00
|
|
|
}
|
|
|
|
|
2015-08-26 06:07:03 +08:00
|
|
|
// PrimitivesCommandTest
|
|
|
|
PrimitivesCommandTest::PrimitivesCommandTest()
|
|
|
|
{
|
|
|
|
// draws a quad
|
|
|
|
V3F_C4B_T2F data[] = {
|
|
|
|
{{0, 0,0}, {255, 0, 0,255}, {0,1}},
|
|
|
|
{{200, 0,0}, {0, 255,255,255}, {1,1}},
|
|
|
|
{{200,200,0}, {255,255, 0,255}, {1,0}},
|
|
|
|
{{0, 200,0}, {255,255,255,255}, {0,0}},
|
|
|
|
};
|
|
|
|
|
|
|
|
uint16_t indices[] = {
|
|
|
|
0,1,2,
|
|
|
|
2,0,3
|
|
|
|
};
|
|
|
|
|
|
|
|
static const int TOTAL_VERTS = sizeof(data) / sizeof(data[0]);
|
|
|
|
static const int TOTAL_INDICES = TOTAL_VERTS*6/4;
|
|
|
|
|
|
|
|
auto vertexBuffer = VertexBuffer::create(sizeof(V3F_C4B_T2F), TOTAL_VERTS);
|
|
|
|
vertexBuffer->updateVertices(data, TOTAL_VERTS,0);
|
|
|
|
|
|
|
|
auto vertsData = VertexData::create();
|
|
|
|
vertsData->setStream(vertexBuffer, VertexStreamAttribute(0, GLProgram::VERTEX_ATTRIB_POSITION, GL_FLOAT, 3));
|
|
|
|
vertsData->setStream(vertexBuffer, VertexStreamAttribute(offsetof(V3F_C4B_T2F, colors), GLProgram::VERTEX_ATTRIB_COLOR, GL_UNSIGNED_BYTE, 4, true));
|
|
|
|
vertsData->setStream(vertexBuffer, VertexStreamAttribute(offsetof(V3F_C4B_T2F, texCoords), GLProgram::VERTEX_ATTRIB_TEX_COORD, GL_FLOAT, 2));
|
|
|
|
|
|
|
|
|
|
|
|
auto indexBuffer = IndexBuffer::create(IndexBuffer::IndexType::INDEX_TYPE_SHORT_16, TOTAL_INDICES);
|
|
|
|
indexBuffer->updateIndices(indices, TOTAL_INDICES, 0);
|
|
|
|
|
|
|
|
_primitive = Primitive::create(vertsData, indexBuffer, GL_TRIANGLES);
|
|
|
|
_primitive->setCount(TOTAL_INDICES);
|
|
|
|
_primitive->setStart(0);
|
|
|
|
|
|
|
|
auto cache = Director::getInstance()->getTextureCache();
|
|
|
|
_texture = cache->addImage("Images/grossini.png");
|
|
|
|
_programState = GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR);
|
|
|
|
|
|
|
|
_primitive->retain();
|
|
|
|
_texture->retain();
|
|
|
|
_programState->retain();
|
|
|
|
}
|
|
|
|
|
|
|
|
PrimitivesCommandTest::~PrimitivesCommandTest()
|
|
|
|
{
|
|
|
|
CC_SAFE_RELEASE(_primitive);
|
|
|
|
CC_SAFE_RELEASE(_texture);
|
|
|
|
CC_SAFE_RELEASE(_programState);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PrimitivesCommandTest::draw(Renderer* renderer, const Mat4& transform, uint32_t flags)
|
|
|
|
{
|
|
|
|
_primitiveCommand.init(_globalZOrder,
|
|
|
|
_texture->getName(),
|
|
|
|
_programState,
|
|
|
|
BlendFunc::ALPHA_NON_PREMULTIPLIED,
|
|
|
|
_primitive,
|
|
|
|
transform,
|
|
|
|
flags);
|
|
|
|
renderer->addCommand(&_primitiveCommand);
|
|
|
|
}
|
|
|
|
|
|
|
|
string PrimitivesCommandTest::title() const
|
|
|
|
{
|
|
|
|
return "PrimitiveCommand test";
|
|
|
|
}
|
|
|
|
|
|
|
|
string PrimitivesCommandTest::subtitle() const
|
|
|
|
{
|
|
|
|
return "Drawing Primitives using PrimitiveCommand";
|
|
|
|
}
|
|
|
|
|
2016-07-07 08:21:58 +08:00
|
|
|
//
|
|
|
|
// Issue11942Test
|
|
|
|
//
|
|
|
|
Issue11942Test::Issue11942Test()
|
|
|
|
{
|
|
|
|
auto draw = DrawNode::create();
|
|
|
|
addChild(draw, 10);
|
|
|
|
|
|
|
|
// draw a circle
|
|
|
|
draw->setLineWidth(1);
|
|
|
|
draw->drawCircle(VisibleRect::center() - Vec2(140,0), 50, CC_DEGREES_TO_RADIANS(90), 30, false, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1));
|
|
|
|
draw->setLineWidth(10);
|
|
|
|
draw->drawCircle(VisibleRect::center() + Vec2(140,0), 50, CC_DEGREES_TO_RADIANS(90), 30, false, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
string Issue11942Test::title() const
|
|
|
|
{
|
|
|
|
return "Gihub Issue #11942";
|
|
|
|
}
|
|
|
|
|
|
|
|
string Issue11942Test::subtitle() const
|
|
|
|
{
|
|
|
|
return "drawCircle() with width";
|
|
|
|
}
|
|
|
|
|
2015-08-26 06:07:03 +08:00
|
|
|
|
2014-09-15 16:23:57 +08:00
|
|
|
#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
|
|
|
|
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
|
|
|
|
#elif _MSC_VER >= 1400 //vs 2005 or higher
|
|
|
|
#pragma warning (pop)
|
|
|
|
#endif
|