1

I'm creating an ios drawing app and would like to understand how to rotate the texture I'm using for drawing to have the texture follow the direction of my stroke.

Sketchbook for iOS and brushes are two apps that Ive seen accomplish this.

Does anyone have any idea of how to achieve this?

Here's an example of the concept that I'm trying to capture: http://drawsketch.about.com/od/learntodraw/ss/pencilshading_5.htm

Attached is a screenshot from the sketchbook app of this in practice.enter image description here

UPDATE:

I was able to figure this out (thanks to SO community for helping out!) and posted my answer here: https://stackoverflow.com/a/11298219/111856

Community
  • 1
  • 1
kajham
  • 1,241
  • 15
  • 19

1 Answers1

1

You can just rotate the brush texture as you're drawing it. You can get the angle by taking the arctangent of the y delta divided by the x delta for each segment of the stroke:

atan2(newY - prevY, newX - prevX);

Then rotate your brush texture by that amount before blending it at each point along the line.

user1118321
  • 25,567
  • 4
  • 55
  • 86
  • Thanks! The strategy makes sense. And I use glRotatef to rotate the brush texture? And what vector should I rotate the brush over (x,y,z arguments of glRotatef). I've been experimenting with the rotation but haven't been able to figure out how the rotation works exactly. – kajham Jun 28 '12 at 15:41
  • Also, would I need to draw the texture as a quad to be able to rotate it? – kajham Jun 28 '12 at 17:58
  • Not really, you can use tris as well. iOS supports only tris I remember – codetiger Jun 29 '12 at 00:49
  • I think in general you would want to do `glRotatef(angle,0,0,1)` so you're rotating around the Z-axis. Drawing a rotated quad (or triangles) is probably the easiest way. – user1118321 Jun 29 '12 at 00:52
  • Thanks! Rotation around Z-axis makes complete sense. What I haven't figured out yet is how to rotate just one texture in the entire view. What I have is a vertex array with points (x and y) that is used as the vertex pointer. I currently do not have a texture coordinate array, and am drawing the points to the screen using a 2d texture with the glDrawArrays(GL_TRIANGLE_STRIP, 0, count) command. Is it necessary to specify each vertex on the screen with 3 points (as a triangle) or a quad to make it possible to rotate each texture? – kajham Jun 29 '12 at 18:17