I'm creating an ios painting app for iOS and having the hardest time rotating a paint texture at a particular point to have it face the direction of the stroke.
I'm drawing the texture a few pixels apart between every touch of the user. The vertex points are being represented as a 2d point with x and y coordinates into a vertex buffer which is then rendered to screen. Here's the code that I'm using to draw:
count = MAX(ceilf(sqrtf((end.x - start.x) * (end.x - start.x) + (end.y - start.y) * (end.y - start.y)) / kBrushPixelStep), 1);
GLfloat *vBuffer = malloc(2 * sizeof(GLfloat));
for(i = 0; i < count; i++) {
vBuffer[0] = start.x + (end.x - start.x) * ((GLfloat)i / (GLfloat)count);
vBuffer[1] = start.y + (end.y - start.y) * ((GLfloat)i / (GLfloat)count);
CGFloat degrees = atan2(end.y - start.y, end.x - start.x) * 180 / M_PI;
glMatrixMode(GL_TEXTURE);
glPushMatrix();
glVertexPointer(2, GL_FLOAT, 0, vBuffer);
glDrawArrays(GL_POINTS, 0, count);
glRotatef(degrees, 0, 0, 1);
glPopMatrix();
}
// render to screen
glBindRenderbufferOES(GL_RENDERBUFFER_OES, renderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];
This does not give me the desired effect, which is the rotation of the texture at each vertex by the angle that represents the deviation between the two points.
Questions I have are:
- How do I rotate just the texture at every point?
- Is it sufficient to represent each vertex with just x,y coordinates or does it have to be as 3 points or more?
- Do I need to enable texture mapping? Is that what is preventing me from independently rotating the texture at each vertex? If so, how do I represent the texture co-ordinate array for a vertex array as is represented above? I haven't been able to figure that part out.
Thank you so much for your help in advance!
UPDATE:
I was able to figure this out and posted my answer here: https://stackoverflow.com/a/11298219/111856