1

我正在尝试制作具有绘图功能的应用程序。在那我需要提供像 SPRAY PAINT 这样的功能。

我已经制作了类似的代码

static GLfloat*     vertexBuffer = NULL;

static NSUInteger   vertexMax = 64;

NSUInteger          vertexCount = 0,
                    count,
                    i;

[EAGLContext setCurrentContext:context];
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);

// Convert locations from Points to Pixels
CGFloat scale = self.contentScaleFactor;
start.x *= scale;
start.y *= scale;
end.x *= scale;
end.y *= scale;

// Allocate vertex array buffer
if(vertexBuffer == NULL)
    vertexBuffer = malloc(vertexMax * 2 * sizeof(GLfloat));

// Add points to the buffer so there are drawing points every X pixels
count = MAX(ceilf(sqrtf((end.x - start.x) * (end.x - start.x) + (end.y - start.y) * (end.y - start.y)) / kBrushPixelStep), 1);
for(i = 0; i < count; ++i) {
    if(vertexCount == vertexMax) {
        vertexMax = 2 * vertexMax;
        vertexBuffer = realloc(vertexBuffer, vertexMax * 2 * sizeof(GLfloat));
    }

    vertexBuffer[2 * vertexCount + 0] = start.x + (end.x - start.x) * ((GLfloat)i / (GLfloat)count);
    vertexBuffer[2 * vertexCount + 1] = start.y + (end.y - start.y) * ((GLfloat)i / (GLfloat)count);
    vertexCount += 1;
}

// Render the vertex array
glVertexPointer(2, GL_FLOAT, 0, vertexBuffer);
glDrawArrays(GL_POINTS, 01, vertexCount);
glStencilMask(GL_STENCIL_VALUE_MASK);
glDepthMask(GL_FALSE);
// Display the buffer
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];

现在我需要为 Paint 做哪些额外的代码,看起来像喷漆?

这段代码将使我附上的颜色像图像

4

1 回答 1

5

苹果示例代码展示了如何做到这一点。为什么不从那开始呢?

于 2012-06-15T13:13:28.013 回答