我正在尝试为 mac os 实现 OpenGL 画笔。使用 GLPaint 作为示例。主要问题是 GLPaint 是 iOS 应用程序,我在 mac os 上需要它。不知何故,我几乎将它编辑为在 MAC OS 上工作(至少我是这么认为的),但它仍然没有运行。我想,主要问题在于“EAGLContext”和“NSOpenGLContext”或者“OpenGL”和“OpenGL ES”的差异。当我尝试使用'renderLineFromPoint:ToPoint: '
[self renderLineFromPoint:vieta toPoint:buvusVieta];
它向我显示错误
- `glBindFramebuffer(GL_FRAMEBUFFER, viewFramebufferis);
带有错误代码
线程 1:EXC_BAD_ACCSESS(代码=1,地址=0x1508)
整个 'renderLineFromPoint:toPoint:' 代码如下
- (void) renderLineFromPoint:(CGPoint)pradzia toPoint:(CGPoint)pabaiga
{
static GLfloat* vertexBuffer = NULL;
static NSUInteger vertexMax = 64;
NSUInteger vertexCount = 0, count, i;
[context makeCurrentContext];
glBindFramebuffer(GL_FRAMEBUFFER, viewFramebufferis);
//Convert from point to pixel
CGFloat scale = self.contentsScale;
pradzia.x *= scale;
pradzia.y *= scale;
pabaiga.x *= scale;
pabaiga.y *= scale;
//Vertex array buffer
if(vertexBuffer == NULL)
vertexBuffer = malloc(vertexMax * 2 * sizeof(GLfloat));
//Add points to buffer at X pixels
count = MAX(ceilf(sqrtf((pabaiga.x - pradzia.x) * (pabaiga.x - pradzia.x) + (pabaiga.y - pradzia.y) * (pabaiga.y - pradzia.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] = pradzia.x + (pabaiga.x - pradzia.x) * ((GLfloat)i / (GLfloat)count);
vertexBuffer[2 * vertexCount + 1] = pradzia.y + (pabaiga.y - pradzia.y) * ((GLfloat)i / (GLfloat)count);
vertexCount += 1;
}
//Render vertex array
glVertexPointer(2, GL_FLOAT, 0, vertexBuffer);
glDrawArrays(GL_POINTS, 0, vertexCount);
//Show buffer
glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbufferis);
[context presentRenderbuffer:GL_RENDERBUFFER];
}
任何人都可以帮助我吗?
或者也许有人可以指出我类似的示例代码?
即使有人将我链接到解释诸如实时绘图等内容的教程,这也会非常有用。我对鼠标事件跟踪和注册它的点没有任何问题。我只需要以某种方式使 OpenGL 在两点之间画线或在每个注册点绘制例如圆形。有任何想法吗?