I’m trying to implement OpenGL brush for mac os. Using GLPaint as sample. Main trouble is that GLPaint is iOS application, and I need it on mac os. Somehow i almost edited it to work on MAC OS (well at least i think so), but it’s still not running. I guess, the main issue is in ‘EAGLContext’ and ‘NSOpenGLContext’ or maybe ‘OpenGL’ and ‘OpenGL ES’ differences. When I try to use ‘renderLineFromPoint:ToPoint:‘
[self renderLineFromPoint:vieta toPoint:buvusVieta];
it shows me error at
- `glBindFramebuffer(GL_FRAMEBUFFER, viewFramebufferis);
with error code
Thread 1: EXC_BAD_ACCSESS (code=1, adress=0x1508)
Whole ‘renderLineFromPoint:toPoint:’ code bellow
- (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];
}
Anyone could help me?
Or maybe someone could point me to similar sample code?
That would be very useful even if someone links me to tutorial where is explained such a thing as drawing in real time or etc. I have no problems with mouse events tracking and registering its points. I just need somehow to make OpenGL to draw line between two points or to draw for example circle at each registered point. Any ideas?
I solved my problem. I just had to use
functions to register mouse events, and then call function [self drawSomething]; in witch was written what to draw and use coordinates witch was given me by ‘mouseDown’ ‘mouseDragged’ ‘mouseUp’.