Guest User

Untitled

a guest
Jun 13th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. //THIS IS THE DRAW METHOD, THIS IS CALLED ABOUT 60 TIMES A SECOND
  2. - (void)drawView:(OpenGLCoreView*)view
  3. {
  4. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  5. glLoadIdentity();
  6.  
  7. float tempX = [glView xCoord];
  8. float tempY = [glView yCoord];
  9.  
  10. if ([glView touchDown])
  11. {
  12. [self moveBallToTouchCoordinates:tempX :tempY];
  13. }
  14. else
  15. {
  16. allowDrag = NO;
  17. }
  18.  
  19. [self drawBall:ballXCoord :ballYCoord];
  20. [self drawGLLine:200 :100 :200 :200: 1.0: 0.0: 0.0: 1.0];
  21. }
  22.  
  23. //This method draws a ball to the screen
  24. -(void)drawBall: (float)xCoordinate: (float)yCoordinate
  25. {
  26. glTranslatef(xCoordinate, yCoordinate, 0.0);
  27.  
  28. glVertexPointer(2, GL_FLOAT, 0, ballVerticies);
  29. glTexCoordPointer(2, GL_FLOAT, 0, ballTextureCoordinates);
  30. glBindTexture(GL_TEXTURE_2D, ballImageTexture);
  31. glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
  32. }
  33.  
  34. //This method draws a line to the screen with X,Y,X2, and Y2 coordinates, and R G B A for color
  35. -(void)drawGLLine:(float)x:(float)y:(float)x2:(float)y2:(float)red:(float)green:(float)blue:(float)alpha
  36. {
  37. glLoadIdentity();
  38. glDisable(GL_TEXTURE_2D);
  39.  
  40. GLfloat line[] = {
  41. x, y,
  42. x2, y2,
  43. };
  44.  
  45. glColor4f(red,green,blue,alpha); //line color
  46.  
  47. glVertexPointer(2, GL_FLOAT, 0, line);
  48. glEnableClientState(GL_VERTEX_ARRAY);
  49. glDrawArrays(GL_LINES, 0, 2);
  50. glEnable(GL_TEXTURE_2D);
  51.  
  52. glColor4f(1.0f,1.0f,1.0f,1.0f); //line color
  53. }
Add Comment
Please, Sign In to add comment