- (void)draw
{
glLoadIdentity();
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
CGColorRef color = currentColor.CGColor;
const CGFloat *components = CGColorGetComponents(color);
CGFloat red = components[0];
CGFloat green = components[1];
CGFloat blue = components[2];
glColor4f(red,green, blue, 1.0);
switch (shapeType) {
case kLineShape: {
if (sprite){
[sprite release];
self.sprite = nil;
}
GLfloat vertices[6];
// Convert coordinates
vertices[0] = 60.000000;//firstTouch.x;
vertices[1] = 150.000000;//self.frame.size.height - firstTouch.y;
vertices[2] = 60.000000;//lastTouch.x;
vertices[3] = 300.000000;//self.frame.size.height - lastTouch.y;
vertices[4] = 300.000000;
vertices[5] = 300.000000;
glLineWidth(2.0);
glVertexPointer (2, GL_FLOAT , 0, vertices);
glDrawArrays (GL_LINE_STRIP, 0, 3);
break;
}
case kRectShape:{
if (sprite){
[sprite release];
self.sprite = nil;
}
// Calculate bounding rect and store in vertices
GLfloat vertices[10];
vertices[0] = 50;
vertices[1] = 150;
vertices[2] = 50;
vertices[3] = 200;
vertices[4] = 100;
vertices[5] = 200;
vertices[6] = 100;
vertices[7] = 250;
vertices[8] = 150;
vertices[9] = 250;
glVertexPointer (2, GL_FLOAT , 0, vertices);
glDrawArrays (GL_LINE_STRIP, 0, 5);
break;
}
case kEllipseShape: {
if (sprite){
[sprite release];
self.sprite = nil;
}
// Calculate bounding rect and store in vertices
GLfloat vertices[14];
vertices[0] = 50;
vertices[1] = 150;
vertices[2] = 50;
vertices[3] = 200;
vertices[4] = 100;
vertices[5] = 200;
vertices[6] = 100;
vertices[7] = 250;
vertices[8] = 150;
vertices[9] = 250;
vertices[10] = 150;
vertices[11] = 300;
vertices[12] = 200;
vertices[13] = 300;
glVertexPointer (2, GL_FLOAT , 0, vertices);
glDrawArrays (GL_LINE_STRIP, 0, 7);
break;
}
case kImageShape:
if (sprite == nil) {
[sprite release];
self.sprite = nil;
}
// Calculate bounding rect and store in vertices
GLfloat vertices[18];
vertices[0] = 50;
vertices[1] = 150;
vertices[2] = 50;
vertices[3] = 200;
vertices[4] = 100;
vertices[5] = 200;
vertices[6] = 100;
vertices[7] = 250;
vertices[8] = 150;
vertices[9] = 250;
vertices[10] = 150;
vertices[11] = 300;
vertices[12] = 200;
vertices[13] = 300;
vertices[14] = 200;
vertices[15] = 350;
vertices[16] = 250;
vertices[17] = 350;
glVertexPointer (2, GL_FLOAT , 0, vertices);
glDrawArrays (GL_LINE_STRIP, 0, 9);
break;
}
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];
}
댓글 달기