Esempio n. 1
0
    void fzDrawCircle( const fzVec2& center, fzFloat r, fzFloat a, fzUInt segs, bool drawLineToCenter)
    {
        int additionalSegment = 1;
        if (drawLineToCenter)
            additionalSegment++;
        
        const float coef = 2.0f * (float)M_PI/segs;
        
        fzVec2 *vertices = new fzVec2[segs+2];
        
        for(fzUInt i = 0; i <= segs; i++)
        {
            float rads  = i * coef;
            GLfloat j   = r * fzMath_cos(rads + a) + center.x;
            GLfloat k   = r * fzMath_sin(rads + a) + center.y;
            
            vertices[i] = fzPoint(j, k);
        }
        vertices[segs+1] = center;
        
        fzGLSetMode(kFZGLMode_Primitives);            
#if FZ_GL_SHADERS
        lazyInitialize();
        _fzShader->use();
        FZ_SAFE_APPLY_MATRIX(_fzShader);
        glVertexAttribPointer(kFZAttribPosition, 2, GL_FLOAT, GL_FALSE, 0, vertices);
#else
        glVertexPointer(2, GL_FLOAT, 0, vertices);
#endif
        
        glDrawArrays(GL_LINE_STRIP, 0, (GLsizei) segs+additionalSegment);
        
        delete [] vertices;
    }
Esempio n. 2
0
    void fzDrawCubicBezier(const fzVec2& origin, const fzVec2& c1, const fzVec2& c2, const fzVec2& destination, fzUInt segments)
    {
        fzVec2 *vertices = new fzVec2[segments+1];

        float t = 0;
        for(fzUInt i = 0; i < segments; i++)
        {
            vertices[i].x = powf(1 - t, 3) * origin.x + 3.0f * powf(1 - t, 2) * t * c1.x + 3.0f * (1 - t) * t * t * c2.x + t * t * t * destination.x;
            vertices[i].y = powf(1 - t, 3) * origin.y + 3.0f * powf(1 - t, 2) * t * c1.y + 3.0f * (1 - t) * t * t * c2.y + t * t * t * destination.y;
            t += 1.0f / segments;
        }
        vertices[segments] = destination;
        
        fzGLSetMode(kFZGLMode_Primitives);
        
#if FZ_GL_SHADERS
        lazyInitialize();
        _fzShader->use();
        FZ_SAFE_APPLY_MATRIX(_fzShader);
        glVertexAttribPointer(kFZAttribPosition, 2, GL_FLOAT, GL_FALSE, 0, vertices);
#else
        glVertexPointer(2, GL_FLOAT, 0, vertices);
#endif
        glDrawArrays(GL_LINE_STRIP, 0, (GLsizei) segments + 1);
        
        delete [] vertices;
    }
Esempio n. 3
0
    void Sprite::draw()
    {
        FZ_ASSERT(m_mode == kFZSprite_SelfRendering, "If Sprite is being rendered by SpriteBatch, Sprite::draw SHOULD NOT be called.");

        // Bind texture
        fzGLSetMode(kFZGLMode_TextureNoColor);
        if(mode.A.p_texture)
            mode.A.p_texture->bind();
        
        fzGLBlendFunc( m_blendFunc );
        
#if FZ_GL_SHADERS
        
        p_glprogram->use();
        p_glprogram->setUniform4f(kFZUniformColor_s, m_color.r/255.0f, m_color.g/255.0f, m_color.b/255.0f, (m_cachedOpacity * m_alpha)/255.0f);
        
        // atributes
        glVertexAttribPointer(kFZAttribTexCoords, 2, GL_FLOAT, GL_FALSE, 0, m_texCoords);
        glVertexAttribPointer(kFZAttribPosition, 2, GL_FLOAT, GL_FALSE, sizeof(fzVec4), mode.A.m_finalVertices);
        
#else
        glLoadIdentity();
        
        // atributes
        fzGLColor(m_color);
        glVertexPointer(3, GL_FLOAT, sizeof(fzVec4), mode.A.m_finalVertices);	
        glTexCoordPointer(2, GL_FLOAT, 0, m_texCoords);
#endif
        
        // Rendering
        glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);	
    }
Esempio n. 4
0
    void fzDrawPoint( const fzVec2& vertices )
    {	
        fzGLSetMode(kFZGLMode_Primitives);    

#if FZ_GL_SHADERS
        lazyInitialize();
        _fzShader->use();
        FZ_SAFE_APPLY_MATRIX(_fzShader);
        glVertexAttribPointer(kFZAttribPosition, 2, GL_FLOAT, GL_FALSE, 0, &vertices);
#else
        glVertexPointer(2, GL_FLOAT, 0, &vertices);
#endif
        glDrawArrays(GL_POINTS, 0, 1);	
    }
Esempio n. 5
0
    void fzDrawLine(const fzVec2& origin, const fzVec2& destination )
    {
        fzGLSetMode(kFZGLMode_Primitives);
        fzVec2 vertices[2] = { origin, destination };

#if FZ_GL_SHADERS
        lazyInitialize();
        fzGLUseProgram(_fzShader->getName());
        FZ_SAFE_APPLY_MATRIX(_fzShader);
        glVertexAttribPointer(kFZAttribPosition, 2, GL_FLOAT, GL_FALSE, 0, vertices);
#else
        glVertexPointer(2, GL_FLOAT, 0, vertices);
#endif
        glDrawArrays(GL_LINES, 0, 2);	
    }
Esempio n. 6
0
    void fzDrawPoints( const fzVec2 *vertices, fzUInt numberOfPoints )
    {
        FZ_ASSERT( numberOfPoints > 0, "Number of points can not be 0.");

        fzGLSetMode(kFZGLMode_Primitives);
        
#if FZ_GL_SHADERS
        lazyInitialize();
        _fzShader->use();
        FZ_SAFE_APPLY_MATRIX(_fzShader);
        glVertexAttribPointer(kFZAttribPosition, 2, GL_FLOAT, GL_FALSE, 0, vertices);
#else
        glVertexPointer(2, GL_FLOAT, 0, vertices);
#endif
        glDrawArrays(GL_POINTS, 0, (GLsizei)numberOfPoints);
    }
Esempio n. 7
0
    void fzDrawShape( const fzVec2 *vertices, fzUInt numOfVertices)
    {    
        FZ_ASSERT( numOfVertices > 0, "Number of vertices can not be 0.");
        
        fzGLSetMode(kFZGLMode_Primitives);            
#if FZ_GL_SHADERS
        lazyInitialize();
        fzGLUseProgram(_fzShader->getName());
        FZ_SAFE_APPLY_MATRIX(_fzShader);
        glVertexAttribPointer(kFZAttribPosition, 2, GL_FLOAT, GL_FALSE, 0, vertices);
#else
        glVertexPointer(2, GL_FLOAT, 0, vertices);
#endif
        GLsizei nu = static_cast<GLsizei>(numOfVertices);
        glDrawArrays(GL_TRIANGLE_STRIP, 0, nu);
    }
Esempio n. 8
0
    void fzDrawPoly( const fzVec2 *vertices, fzUInt numOfVertices, bool closePolygon )
    {    
        FZ_ASSERT( numOfVertices > 0, "Number of vertices can not be 0.");

        fzGLSetMode(kFZGLMode_Primitives);            
#if FZ_GL_SHADERS
        lazyInitialize();
        _fzShader->use();
        FZ_SAFE_APPLY_MATRIX(_fzShader);
        glVertexAttribPointer(kFZAttribPosition, 2, GL_FLOAT, GL_FALSE, 0, vertices);
#else
        glVertexPointer(2, GL_FLOAT, 0, vertices);
#endif

        if( closePolygon )
            glDrawArrays(GL_LINE_LOOP, 0, (GLsizei) numOfVertices);
        else
            glDrawArrays(GL_LINE_STRIP, 0, (GLsizei) numOfVertices);
    }
Esempio n. 9
0
    void ParticleSystemQuad::draw()
    {	
        if(m_particleIdx == 0)
            return;
        
        // Default Attribs & States: GL_TEXTURE0, k,CCAttribVertex, kCCAttribColor, kCCAttribTexCoords
        // Needed states: GL_TEXTURE0, k,CCAttribVertex, kCCAttribColor, kCCAttribTexCoords
        // Unneeded states: -
        
        fzGLSetMode(kFZGLMode_Texture);
        fzGLBlendFunc( m_blendFunc.src, m_blendFunc.dst );
        p_texture->bind();
        
#if FZ_GL_SHADERS
        
        p_glprogram->use();
        FZ_SAFE_APPLY_MATRIX(p_glprogram);
        
        // atributes
        glVertexAttribPointer(kFZAttribPosition, 2, GL_FLOAT, GL_FALSE, sizeof(_fzC4_T2_V2), &p_quads->bl.vertex);
        glVertexAttribPointer(kFZAttribTexCoords, 2, GL_FLOAT, GL_FALSE, sizeof(_fzC4_T2_V2), &p_quads->bl.texCoord);
        glVertexAttribPointer(kFZAttribColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(_fzC4_T2_V2), &p_quads->bl.color);
#else
        
        glLoadMatrixf(get);

        glVertexPointer(2, GL_FLOAT, sizeof(_fzC4_T2_V2), &p_quads->bl.vertex);
        glTexCoordPointer(2, GL_FLOAT, sizeof(_fzC4_T2_V2), &p_quads->bl.texCoord);
        glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(_fzC4_T2_V2), &p_quads->bl.color);
#endif
                
        FZ_ASSERT( m_particleIdx == m_particleCount, "Abnormal error in particle quad");
    
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indicesVBO);
        glDrawElements(GL_TRIANGLES, m_particleIdx * 6, GL_UNSIGNED_SHORT, 0);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
    }