在iphone模拟器上使用OpenGL的简单渐变问题

时间:2012-07-01 03:01:37

标签: iphone opengl-es gradient

我正在关注raywenderlich website的教程,渐变似乎不能很好地工作,是因为它只是因为iphone模拟器,还是别的?我不能尝试使用iPhone。这是图像:

enter image description here

代码:

-(CCSprite *)spriteWithColor:(ccColor4F)bgColor textureSize:(float)textureSize {

    // 1: Create new CCRenderTexture
    CCRenderTexture *rt = [CCRenderTexture renderTextureWithWidth:textureSize height:screenSize.height];

    // 2: Call CCRenderTexture:begin
    [rt beginWithClear:bgColor.r g:bgColor.g b:bgColor.b a:bgColor.a];

    // 3: Draw into the texture
    glDisable(GL_TEXTURE_2D);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);

    float gradientAlpha = 0.5;    
    CGPoint vertices[4];
    ccColor4F colors[4];
    int nVertices = 0;

    vertices[nVertices] = CGPointMake(0, 0);
    colors[nVertices++] = (ccColor4F){0, 0, 0, 0};
    vertices[nVertices] = CGPointMake(textureSize, 0);
    colors[nVertices++] = (ccColor4F){0, 0, 0, gradientAlpha};
    vertices[nVertices] = CGPointMake(0, screenSize.height);
    colors[nVertices++] = (ccColor4F){0, 0, 0, 0};
    vertices[nVertices] = CGPointMake(textureSize, screenSize.height);
    colors[nVertices++] = (ccColor4F){0, 0, 0, gradientAlpha};

    glVertexPointer(2, GL_FLOAT, 0, vertices);
    glColorPointer(4, GL_FLOAT, 0, colors);
    glDrawArrays(GL_TRIANGLE_STRIP, 0, (GLsizei)nVertices);

    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glEnable(GL_TEXTURE_2D);

    // 4: Call CCRenderTexture:end
    [rt end];

    // 5: Create a new Sprite from the texture
    return [CCSprite spriteWithTexture:rt.sprite.texture];

}

由于

0 个答案:

没有答案