Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to implement OpenGL brush
    text
    copied!<p>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 <em>'EAGLContext'</em> and <em>'NSOpenGLContext'</em> or maybe <em>'OpenGL'</em> and <em>'OpenGL ES'</em> differences. When I try to use <em>'renderLineFromPoint:ToPoint:</em>'</p> <ul> <li><code>[self renderLineFromPoint:vieta toPoint:buvusVieta];</code></li> </ul> <p>it shows me error at </p> <ul> <li>`glBindFramebuffer(GL_FRAMEBUFFER, viewFramebufferis);</li> </ul> <p>with error code </p> <blockquote> <p>Thread 1: EXC_BAD_ACCSESS (code=1, adress=0x1508)</p> </blockquote> <p>Whole 'renderLineFromPoint:toPoint:' code bellow</p> <pre><code>- (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 &lt; 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]; } </code></pre> <p>Anyone could help me? </p> <p>Or maybe someone could point me to similar sample code?</p> <p>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?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload