Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3663604
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:32:57+00:00 2026-05-19T01:32:57+00:00

I’m creating a drawing app ( text ) for the iPad using OpenGL. I’ve

  • 0

I’m creating a drawing app ( text ) for the iPad using OpenGL. I’ve already had a look at Apple’s example GLPaint, and my app is now based on that code. My app should be just for drawing text, not for painting pictures.

Well, my App works, I can write some text. But the writing isn’t really good, it doesn’t make fun to write. The drawing path isn’t smooth, it’s angularly because I’m drawing a line from one point to another. And the path has everywhere the same width. My idea is: when you’re writing fast the line is thinner than when you’re writing slow. It should be the same experience like writing with a real pen.

How can I make the path look much smoother? How can I vary the width of the line depending on the speed of writing?

Here you can see what I mean:

example

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T01:32:58+00:00Added an answer on May 19, 2026 at 1:32 am

    The best way to smooth the drawing is use a bezeir curve. Here is my code. It is a modified version I found on apple’s dev site, but I don’t remember the original link:

    CGPoint drawBezier(CGPoint origin, CGPoint control, CGPoint destination, int segments)
    {
     CGPoint vertices[segments/2];
     CGPoint midPoint;
     glDisable(GL_TEXTURE_2D);
     float x, y;
    
     float t = 0.0;
     for(int i = 0; i < (segments/2); i++)
     {
      x = pow(1 - t, 2) * origin.x + 2.0 * (1 - t) * t * control.x + t * t * destination.x;
      y = pow(1 - t, 2) * origin.y + 2.0 * (1 - t) * t * control.y + t * t * destination.y;
      vertices[i] = CGPointMake(x, y);
      t += 1.0 / (segments);
    
     }
     //windowHeight is the height of you drawing canvas.
     midPoint = CGPointMake(x, windowHeight - y);
     glVertexPointer(2, GL_FLOAT, 0, vertices);
     glDrawArrays(GL_POINTS, 0, segments/2);
     return midPoint;
    }
    

    That will draw based on three points. The control is the midpoint, which you need to return. The new midpoint will be different than the previous. Also, if you go through the above code, it will only draw half the line. The next stroke will fill it in. This is required. my code for calling this function (the above is in C, this is in Obj-C):

       //Invert the Y axis to conform the iPhone top-down approach
       invertedYBegCoord = self.bounds.size.height - [[currentStroke objectAtIndex:i] CGPointValue].y;
       invertedYEndCoord = self.bounds.size.height - [[currentStroke objectAtIndex:i+1] CGPointValue].y;
       invertedYThirdCoord = self.bounds.size.height - [[currentStroke objectAtIndex:i+2] CGPointValue].y;
       //Figure our how many dots you need
       count = MAX(ceilf(sqrtf(([[currentStroke objectAtIndex:i+2] CGPointValue].x - [[currentStroke objectAtIndex:i] CGPointValue].x) 
             * ([[currentStroke objectAtIndex:i+2] CGPointValue].x - [[currentStroke objectAtIndex:i] CGPointValue].x) 
             + ((invertedYThirdCoord - invertedYBegCoord) * (invertedYThirdCoord - invertedYBegCoord))) / pointCount), 1);
    
       newMidPoint = drawBezier(CGPointMake([[currentStroke objectAtIndex:i] CGPointValue].x, invertedYBegCoord), CGPointMake([[currentStroke objectAtIndex:i+1] CGPointValue].x, invertedYEndCoord), CGPointMake([[currentStroke objectAtIndex:i+2] CGPointValue].x, invertedYThirdCoord), count);
    
       int loc = [currentStroke count]-1;
       [currentStroke insertObject:[NSValue valueWithCGPoint:newMidPoint] atIndex:loc];
       [currentStroke removeObjectAtIndex:loc-1];
    

    That code will get the mid point based on inverted iPad points, and set the ‘control’ as the current point.

    That will smooth out the edges. Now regarding the line width, you just need to find the speed of that drawing. It is easiest just to find the length of your line. This is easily done using component mathematics. I don’t have any code for it, but here is a primer for component mathmatics from a physics site. Or you can simply divide (above) count by some number to find out how thick you need the line to be (count uses component mathematics).

    I store point data in an array called currentStroke, in case it wasn’t obvious.

    That should be all you need.

    EDIT:

    To store points, you should use touchesBegin and touchesEnd:

    - (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
    {
        self.currentStroke = [NSMutableArray array];
        CGPoint point = [ [touches anyObject] locationInView:self];
        [currentStroke addObject:[NSValue valueWithCGPoint:point]];
        [self draw];
    
    }
    
    - (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
    {
        CGPoint point = [ [touches anyObject] locationInView:self];
        [currentStroke addObject:[NSValue valueWithCGPoint:point]];
        [self draw];
    }
    
    
    - (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
    {
        CGPoint point = [ [touches anyObject] locationInView:self];
        [currentStroke addObject:[NSValue valueWithCGPoint:point]];
        [self draw];
    }
    

    That is pretty much an entire drawing application there. If you are using GL_Paint, then you are already using point sprites, which this system is build on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
We're building an app, our first using Rails 3, and we're having to build
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
I'm making a simple page using Google Maps API 3. My first. One marker
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.