0

I have a visit method for the dot indicator of my Sliding Menu Grid.

- (void) visit
{
    [super visit];//< Will draw after glPopScene.

    BOOL showPagesIndicator = YES;


    ccColor4B pagesIndicatorNormalColor_ = ccc4([sud integerForKey:key_int_r], [sud integerForKey:key_int_g], [sud integerForKey:key_int_b], 255);
    ccColor4B pagesIndicatorSelectedColor_ = ccc4(255, 255, 255, 255);
    if (showPagesIndicator)
    {
        int totalScreens = iPageCount;

        // Prepare Points Array
        CGFloat n = (CGFloat)totalScreens; //< Total points count in CGFloat.
        CGFloat pY = pageIndicatorPosition.y; //< Points y-coord in parent coord sys.
        CGFloat d = may_double(16.0f); //< Distance between points.
        CGPoint points[totalScreens];
        for (int i=0; i < totalScreens; ++i)
        {
            CGFloat pX = pageIndicatorPosition.x + d * ( (CGFloat)i - 0.5f*(n-1.0f) );
            points[i] = ccp (pX, pY);
        }

        // Set GL Values
#if COCOS2D_VERSION >= 0x00020000
//        ccGLEnable(CC_GL_BLEND);
        ccPointSize( may_double(6.0 * CC_CONTENT_SCALE_FACTOR()) );
#define DRAW_4B_FUNC ccDrawColor4B

#else
        glEnable(GL_POINT_SMOOTH);
        GLboolean blendWasEnabled = glIsEnabled( GL_BLEND );
        glEnable(GL_BLEND);

        // save the old blending functions
        int blend_src = 0;
        int blend_dst = 0;
        glGetIntegerv( GL_BLEND_SRC, &blend_src );
        glGetIntegerv( GL_BLEND_DST, &blend_dst );
        glPointSize( may_double(6.0 * CC_CONTENT_SCALE_FACTOR()) );

#define DRAW_4B_FUNC glColor4ub

#endif
        ccGLBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//        glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );


        // Draw Gray Points
        DRAW_4B_FUNC(pagesIndicatorNormalColor_.r,
                     pagesIndicatorNormalColor_.g,
                     pagesIndicatorNormalColor_.b,
                     pagesIndicatorNormalColor_.a);

        ccDrawPoints( points, totalScreens );

        // Draw White Point for Selected Page
        DRAW_4B_FUNC(pagesIndicatorSelectedColor_.r,
                     pagesIndicatorSelectedColor_.g,
                     pagesIndicatorSelectedColor_.b,
                     pagesIndicatorSelectedColor_.a);
        ccDrawPoint(points[iCurrentPage]);

        // Restore GL Values
#if COCOS2D_VERSION >= 0x00020000
        ccPointSize(1.0f);
#else
        glPointSize(1.0f);
        glDisable(GL_POINT_SMOOTH);
        if (! blendWasEnabled)
            glDisable(GL_BLEND);

        // always restore the blending functions too
        ccGLBlendFunc( blend_src, blend_dst);
//        glBlendFunc( blend_src, blend_dst );
#endif
    }
}

It worked fine for my earlier projects but not working for cocos2d v3. I get errors (not valid for C99 etc) for almost every openGL statements, such as glPointSize/ccPointSize and glColor4ub. I have tried to use CCDrawNode (the OOP way) but still it's not one to one translation. (glGetIntegerv etc)

The following link is the test project I created (with errors, notice that the screen is not scrollable, and the dot indicator is not shown (i.e. the visit function is not working)

https://drive.google.com/file/d/0BzH5x38rukpYaVlWdUJPWW9EYWc/edit?usp=sharing

EDIT: I have tried to use [renderer enqueueMethod:@selector(drawDotIndicators) target:self]; and put the visit code in drawDotIndicators method. It is not working either

(the end of this tutorial: https://www.makegameswith.us/docs/#!/cocos2d/1.1/customrendering)

OMGPOP
  • 1,995
  • 8
  • 52
  • 95
  • In cocos2d v3 you have to use the built-in OpenGL wrapper functions and the CCRenderBuffer - you can't override visit or draw, you have to add custom drawing code to -(void) draw:(CCRenderer*)renderer transform:(const GLKMatrix4*)transform using methods like CCRenderBufferSetVertex and similar. See CCSprite code for an example. – CodeSmile Jul 18 '14 at 10:02
  • @LearnCocos2D I have tried to put everything inside `draw:transform:` method but still the same result – OMGPOP Jul 19 '14 at 05:51
  • if i wasn't clear: you can't use any gl* functions in v3, you have to use the v3 gl wrapper functions that work in conjuction with ccrenderer – CodeSmile Jul 19 '14 at 08:01
  • @LearnCocos2D can you be more specific? I have tried to use lots of blogs and tutorials but I am unable to draw stripes inside CCRendererTexture. – Paresh Thakor Sep 27 '14 at 16:45
  • It's not well documented and even less so by tutorial writers. Here's an example draw method to show what I mean, there's no use of OpenGL functions at all: https://gist.github.com/LearnCocos2D/69891adcc110082b25a8 (though in the meantime I found out that it is possible to use regular OpenGL if you call specific start/end macros to put the renderer in the correct state to receive non-batched custom OpenGL commands) – CodeSmile Sep 27 '14 at 17:01

0 Answers0