Iphone 使用纹理渲染抗锯齿线=>;搜索非常简单的示例

Iphone 使用纹理渲染抗锯齿线=>;搜索非常简单的示例,iphone,opengl-es,cocos2d-iphone,antialiasing,Iphone,Opengl Es,Cocos2d Iphone,Antialiasing,有 。。。他们解释了如何绘制抗锯齿线 正是我想要的 但是 我不明白如何用一条简单的线就能做到这一点。我已经找到了这本书的在线版本(这篇文章是从这本书中衍生出来的),我已经下载了示例代码(显示一个木棍在做奇特的动作),但是有太多的mambojambo正在进行。。。一些奇怪的python脚本。。。圆圈作为png图像和头文件,几乎所有内容都是用cpp编写的,我复制到项目中的文件会产生很多错误,我无法正确解决,等等。我想我不需要所有这些花哨的东西,因为我只想在一个简单的基于cocos2d的应用程序中画线

。。。他们解释了如何绘制抗锯齿线

正是我想要的
但是

我不明白如何用一条简单的线就能做到这一点。我已经找到了这本书的在线版本(这篇文章是从这本书中衍生出来的),我已经下载了示例代码(显示一个木棍在做奇特的动作),但是有太多的mambojambo正在进行。。。一些奇怪的python脚本。。。圆圈作为png图像和头文件,几乎所有内容都是用cpp编写的,我复制到项目中的文件会产生很多错误,我无法正确解决,等等。我想我不需要所有这些花哨的东西,因为我只想在一个简单的基于cocos2d的应用程序中画线[Btw…。我不想使用AA,但我的线比5px厚,这使得它们在连接时有难看的洞(例如,在一个由几条线组成的圆圈中),所以我必须像看起来那样使用AA]

那么,是否有人使用链接文章中解释的原理已经或发现了一小段可运行的示例代码


注意事项:

  • 在图中,您可以看到这些孔:

  • 在这里您可以找到上述stickman的代码(AA行):

  • 这是我画圆圈的方式:

    int segments = 80;
    CGFloat width = 100;
    CGFloat height = 100;
    CGPoint center = ccp(800,200);  
    
    glDisable(GL_TEXTURE_2D);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisableClientState(GL_COLOR_ARRAY);
    //glEnable(GL_LINE_SMOOTH); // doesn't work on device
    glTranslatef(center.x, center.y, 0.0);
    glLineWidth(3.0f);
    GLfloat vertices[segments*2];
    int count=0;
    for (GLfloat i = 0; i < 360.0f; i+=(360.0f/segments))
    {
        vertices[count++] = (cos(degreesToRadian(i))*width);
        vertices[count++] = (sin(degreesToRadian(i))*height);
    }
    glVertexPointer (2, GL_FLOAT , 0, vertices); 
    glDrawArrays (GL_LINE_LOOP, 0, segments);
    
    glEnableClientState(GL_COLOR_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glEnable(GL_TEXTURE_2D);    
    
    int段=80;
    CGFloat宽度=100;
    CGFloat高度=100;
    CGPoint中心=ccp(800200);
    glDisable(GL_纹理_2D);
    glDisableClientState(GL_纹理_坐标_数组);
    glDisableClientState(GL_颜色_数组);
    //glEnable(GL_线_光滑);//在设备上不工作
    glTranslatef(中心x,中心y,0.0);
    glLineWidth(3.0f);
    GLfloat顶点[段*2];
    整数计数=0;
    对于(GLfloat i=0;i<360.0f;i+=(360.0f/段))
    {
    顶点[计数++]=(cos(度弧度(i))*宽度);
    顶点[计数++]=(sin(度弧度(i))*高度);
    }
    glVertexPointer(2,GLU浮点,0,顶点);
    gldrawArray(GL_线_环,0,段);
    glEnableClientState(GL_颜色_阵列);
    glEnableClientState(GL_纹理_坐标_阵列);
    glEnable(GL_纹理_2D);
    
  • 也许你能看到。
    我通过opengl es的链接解决了这个问题。

    我也遇到了这个问题。我花了一段时间才弄明白。。。我曾经使用过类似的解决方案(通过Apple.com上的walterBenjamin):

    这是可行的,它很简单,看起来也不错,但它仍然不是最好的(对于我所做的)。最后,我写了我自己的解决方案,将GL绘制粒子图与他的点对点绘制方案相结合

    我制作了一个数组,在touchesBegin,touchesMoved,我添加了一个点:

    [currentStroke添加对象:[NSValue valueWithCGPoint:point]]


    然后我遍历笔划,如您在使用GL_点的GL Paint中看到的

    多亏了Paul Haeberli,以下是他与我共享的一些代码,用于绘制抗锯齿框、点和线:

    /*
     *   Antialised 2D points, lines and rectangles for iOS devices
     *
     *   The feathered edge of these primitives is width/2.0.
     *
     *   If you are working in screen space, the width should be 1.0.
     *
     *       Paul Haeberli 2010
     *
     */
    void fillSmoothRectangle(CGRect *r, float width)
    {
        GLfloat rectVertices[10][2];
        GLfloat curc[4]; 
        GLint   ir, ig, ib, ia;
    
        // fill the inside of the rectangle
        rectVertices[0][0] = r->origin.x;
        rectVertices[0][1] = r->origin.y;
        rectVertices[1][0] = r->origin.x+r->size.width;
        rectVertices[1][1] = r->origin.y;
        rectVertices[2][0] = r->origin.x;
        rectVertices[2][1] = r->origin.y+r->size.height;
        rectVertices[3][0] = r->origin.x+r->size.width;
        rectVertices[3][1] = r->origin.y+r->size.height;
    
        glEnableClientState(GL_VERTEX_ARRAY);
        glVertexPointer(2, GL_FLOAT, 0, rectVertices);
        glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    
        rectVertices[0][0] = r->origin.x;
        rectVertices[0][1] = r->origin.y;
        rectVertices[1][0] = r->origin.x-width;
        rectVertices[1][1] = r->origin.y-width;
        rectVertices[2][0] = r->origin.x+r->size.width;
        rectVertices[2][1] = r->origin.y;
        rectVertices[3][0] = r->origin.x+r->size.width+width;
        rectVertices[3][1] = r->origin.y-width;
        rectVertices[4][0] = r->origin.x+r->size.width;
        rectVertices[4][1] = r->origin.y+r->size.height;
        rectVertices[5][0] = r->origin.x+r->size.width+width;
        rectVertices[5][1] = r->origin.y+r->size.height+width;
        rectVertices[6][0] = r->origin.x;
        rectVertices[6][1] = r->origin.y+r->size.height;
        rectVertices[7][0] = r->origin.x-width;
        rectVertices[7][1] = r->origin.y+r->size.height+width;
        rectVertices[8][0] = r->origin.x;
        rectVertices[8][1] = r->origin.y;
        rectVertices[9][0] = r->origin.x-width;
        rectVertices[9][1] = r->origin.y-width;
    
        glGetFloatv(GL_CURRENT_COLOR, curc);
        ir = 255.0*curc[0];
        ig = 255.0*curc[1];
        ib = 255.0*curc[2];
        ia = 255.0*curc[3];
    
        const GLubyte rectColors[] = {
            ir, ig, ib, ia,
            ir, ig, ib, 0,
            ir, ig, ib, ia,
            ir, ig, ib, 0,
            ir, ig, ib, ia,
            ir, ig, ib, 0,
            ir, ig, ib, ia,
            ir, ig, ib, 0,
            ir, ig, ib, ia,
            ir, ig, ib, 0,
            ir, ig, ib, ia,
            ir, ig, ib, 0,
        };
    
        glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_COLOR_ARRAY);
        glVertexPointer(2, GL_FLOAT, 0, rectVertices);
        glColorPointer(4, GL_UNSIGNED_BYTE, 0, rectColors);
        glDrawArrays(GL_TRIANGLE_STRIP, 0, 10);
        glDisableClientState(GL_COLOR_ARRAY);
    }
    
    void drawSmoothLine(CGPoint *pos1, CGPoint *pos2, float width)
    {
        GLfloat lineVertices[12], curc[4]; 
        GLint   ir, ig, ib, ia;
        CGPoint dir, tan;
    
        width = width*8;
        dir.x = pos2->x - pos1->x;
        dir.y = pos2->y - pos1->y;
        float len = sqrtf(dir.x*dir.x+dir.y*dir.y);
        if(len<0.00001)
            return;
        dir.x = dir.x/len;
        dir.y = dir.y/len;
        tan.x = -width*dir.y;
        tan.y = width*dir.x;
    
        lineVertices[0] = pos1->x + tan.x;
        lineVertices[1] = pos1->y + tan.y;
        lineVertices[2] = pos2->x + tan.x;
        lineVertices[3] = pos2->y + tan.y;
        lineVertices[4] = pos1->x;
        lineVertices[5] = pos1->y;
        lineVertices[6] = pos2->x;
        lineVertices[7] = pos2->y;
        lineVertices[8] = pos1->x - tan.x;
        lineVertices[9] = pos1->y - tan.y;
        lineVertices[10] = pos2->x - tan.x;
        lineVertices[11] = pos2->y - tan.y;
    
        glGetFloatv(GL_CURRENT_COLOR,curc);
        ir = 255.0*curc[0];
        ig = 255.0*curc[1];
        ib = 255.0*curc[2];
        ia = 255.0*curc[3];
    
        const GLubyte lineColors[] = {
            ir, ig, ib, 0,
            ir, ig, ib, 0,
            ir, ig, ib, ia,
            ir, ig, ib, ia,
            ir, ig, ib, 0,
            ir, ig, ib, 0,
        };
    
        glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_COLOR_ARRAY);
        glVertexPointer(2, GL_FLOAT, 0, lineVertices);
        glColorPointer(4, GL_UNSIGNED_BYTE, 0, lineColors);
        glDrawArrays(GL_TRIANGLE_STRIP, 0, 6);
        glDisableClientState(GL_COLOR_ARRAY);
    }
    
    
    void drawSmoothPoint(CGPoint *pos, float width)
    {
        GLfloat pntVertices[12], curc[4]; 
        GLint   ir, ig, ib, ia;
    
        pntVertices[0] = pos->x;
        pntVertices[1] = pos->y;
        pntVertices[2] = pos->x - width;
        pntVertices[3] = pos->y - width;
        pntVertices[4] = pos->x - width;
        pntVertices[5] = pos->y + width;
        pntVertices[6] = pos->x + width;
        pntVertices[7] = pos->y + width;
        pntVertices[8] = pos->x + width;
        pntVertices[9] = pos->y - width;
        pntVertices[10] = pos->x - width;
        pntVertices[11] = pos->y - width;
    
        glGetFloatv(GL_CURRENT_COLOR,curc);
        ir = 255.0*curc[0];
        ig = 255.0*curc[1];
        ib = 255.0*curc[2];
        ia = 255.0*curc[3];
    
        const GLubyte pntColors[] = {
            ir, ig, ib, ia,
            ir, ig, ib, 0,
            ir, ig, ib, 0,
            ir, ig, ib, 0,
            ir, ig, ib, 0,
            ir, ig, ib, 0,
        };
    
        glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_COLOR_ARRAY);
        glVertexPointer(2, GL_FLOAT, 0, pntVertices);
        glColorPointer(4, GL_UNSIGNED_BYTE, 0, pntColors);
        glDrawArrays(GL_TRIANGLE_FAN, 0, 6);
        glDisableClientState(GL_COLOR_ARRAY);
    }
    
    /*
    *iOS设备的反序列化2D点、线和矩形
    *
    *这些基本体的羽化边为宽度/2.0。
    *
    *如果在屏幕空间中工作,则宽度应为1.0。
    *
    *保罗·海伯里2010
    *
    */
    空心填充平滑矩形(CGRect*r,浮动宽度)
    {
    gl[10][2];
    glc[4];
    闪烁红外、免疫球蛋白、免疫球蛋白、免疫球蛋白;
    //填充矩形的内部
    矩形顶点[0][0]=r->origin.x;
    矩形顶点[0][1]=r->origin.y;
    矩形顶点[1][0]=r->origin.x+r->size.width;
    矩形顶点[1][1]=r->origin.y;
    矩形顶点[2][0]=r->origin.x;
    矩形顶点[2][1]=r->origin.y+r->size.height;
    矩形顶点[3][0]=r->origin.x+r->size.width;
    矩形顶点[3][1]=r->origin.y+r->size.height;
    glEnableClientState(GL_顶点_数组);
    glVertexPointer(2,GLU浮点,0,矩形顶点);
    gldrawArray(GL_三角带,0,4);
    矩形顶点[0][0]=r->origin.x;
    矩形顶点[0][1]=r->origin.y;
    矩形顶点[1][0]=r->origin.x-width;
    矩形顶点[1][1]=r->origin.y-宽度;
    矩形顶点[2][0]=r->origin.x+r->size.width;
    矩形顶点[2][1]=r->origin.y;
    矩形顶点[3][0]=r->origin.x+r->size.width+width;
    矩形顶点[3][1]=r->origin.y-宽度;
    矩形顶点[4][0]=r->origin.x+r->size.width;
    矩形顶点[4][1]=r->origin.y+r->size.height;
    矩形顶点[5][0]=r->origin.x+r->size.width+width;
    矩形顶点[5][1]=r->origin.y+r->size.height+width;
    矩形顶点[6][0]=r->origin.x;
    矩形顶点[6][1]=r->origin.y+r->size.height;
    矩形顶点[7][0]=r->origin.x-width;
    矩形顶点[7][1]=r->origin.y+r->size.height+width;
    矩形顶点[8][0]=r->origin.x;
    矩形顶点[8][1]=r->origin.y;
    矩形顶点[9][0]=r->origin.x-width;
    矩形顶点[9][1]=r->origin.y-宽度;
    glGetFloatv(当前颜色,curc);
    ir=255.0*curc[0];
    ig=255.0*curc[1];
    ib=255.0*curc[2];
    ia=255.0*curc[3];
    常量GLubyte rectColors[]={
    ir、ig、ib、ia、,
    ir,ig,ib,0,
    ir、ig、ib、ia、,
    ir,ig,ib,0,
    ir、ig、ib、ia、,
    ir,ig,ib,0,
    ir、ig、ib、ia、,
    ir,ig,ib,0,
    ir、ig、ib、ia、,
    ir,ig,ib,0,
    ir、ig、ib、ia、,
    ir,ig,ib,0,
    };
    glEnableClientState(GL_顶点_数组);
    glEnableClientState(GL_颜色_阵列);
    glVertexPointer(2,GLU浮点,0,矩形顶点);
    glColorPointer(4,GL_无符号字节,0,rectColors);
    gldrawArray(GL_三角形_条,0,10);
    glDisableClientState(GL_颜色_数组);
    }
    虚线绘制平滑线(CGPoint*pos1,CGPoint*pos2,浮动宽度)
    {
    GLfloat linevertexts[12],curc[4];
    闪烁红外、免疫球蛋白、免疫球蛋白、免疫球蛋白;
    陈志强,;
    宽度=宽度*8;
    dir.x=pos2->x-pos1->x;
    方向y=pos2->y-pos1->y;
    float len=sqrtf(dir.x*dir.x+dir.y*dir.y);
    if(lenx+tan.x;
    线顶点[1]=pos1->y+tan.y;
    线条顶点[2]=pos2->x+tan.x;
    线顶点[3]=pos2->y+tan.y;
    线