Guest User

Untitled

a guest
Jul 22nd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.44 KB | None | 0 0
  1. //
  2. // GLViewController.m
  3. // Isometric
  4. //
  5. // Created by Mac Admin on 05/01/2010.
  6. // Copyright __MyCompanyName__ 2010. All rights reserved.
  7. //
  8.  
  9. #import "GLViewController.h"
  10. #import "ConstantsAndMacros.h"
  11. #import "OpenGLCommon.h"
  12. @implementation GLViewController
  13.  
  14. static GLuint texture[1];
  15.  
  16. - (void)drawView:(UIView *)theView
  17. {
  18.  
  19. //Clear some stuff
  20. glColor4f(0.0, 0.0, 0.0, 0.0);
  21. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  22. glClearColor(1.0,1.0,1.0,1.0);
  23. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  24.  
  25. //Drawing Setup
  26. glEnableClientState(GL_VERTEX_ARRAY);
  27. glEnableClientState(GL_NORMAL_ARRAY);
  28. glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  29.  
  30. //Rendering
  31. glLoadIdentity();
  32. glRotatef(-90.0,0.0,0.0,1.0); //Because we are using the device in landscape mode.
  33. glTranslatef(0.0,0.0,-10.0); //Pull the camera back
  34. glRotatef(45,1.0,0.0,0.0); //tilt the camera so it's looking slightly downwards
  35. glBindTexture(GL_TEXTURE_2D, texture[0]); //Bind Level Texture
  36. glVertexPointer(3, GL_FLOAT, 0, vertices); //Give OpenGL the Level Vertices
  37. glNormalPointer(GL_FLOAT, 0, normals); //Give OpenGL the Level Vertex Normals
  38. glTexCoordPointer(2, GL_FLOAT, 0, texCoords); //Give OpenGL the Level Texture Coordinates
  39. glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, polygons); //Tell OpenGL to draw the Level
  40. /* PREVIOUS 4 LINES NEED THE DATA FROM THE PLIST */
  41.  
  42. //Drawing Unsetup
  43. glDisableClientState(GL_VERTEX_ARRAY);
  44. glDisableClientState(GL_NORMAL_ARRAY);
  45. glDisableClientState(GL_TEXTURE_COORD_ARRAY);
  46. }
  47. -(void)setupView:(GLView*)view
  48. {
  49. /* LOAD THE PLIST DATA HERE? */
  50.  
  51. const GLfloat zNear = 0.01, zFar = 1000.0, fieldOfView = 45.0;
  52. GLfloat size;
  53. glEnable(GL_DEPTH_TEST);
  54. glMatrixMode(GL_PROJECTION);
  55. size = zNear * tanf(DEGREES_TO_RADIANS(fieldOfView) / 2.0);
  56. CGRect rect = view.bounds;
  57. glFrustumf(-size, size, -size / (rect.size.width / rect.size.height), size / (rect.size.width / rect.size.height), zNear, zFar);
  58. glViewport(0, 0, rect.size.width, rect.size.height);
  59. glMatrixMode(GL_MODELVIEW);
  60.  
  61. glLoadIdentity();
  62.  
  63. // Turn necessary features on
  64. glEnable(GL_TEXTURE_2D);
  65. glEnable(GL_BLEND);
  66. glBlendFunc(GL_ONE, GL_SRC_COLOR);
  67. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  68.  
  69. glGenTextures(1, &texture[0]);
  70.  
  71. glBindTexture(GL_TEXTURE_2D, texture[0]);
  72. glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
  73. glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
  74. loadTexture(@"Tex");
  75.  
  76.  
  77. glEnable(GL_LIGHTING);
  78.  
  79. // Turn the first light on
  80. glEnable(GL_LIGHT0);
  81.  
  82. // Define the ambient component of the first light
  83. static const Color3D light0Ambient[] = {{1.0, 1.0, 1.0, 1.0}};
  84. glLightfv(GL_LIGHT0, GL_AMBIENT, (const GLfloat *)light0Ambient);
  85.  
  86. // Define the diffuse component of the first light
  87. static const Color3D light0Diffuse[] = {{1.0, 1.0, 1.0, 1.0}};
  88. glLightfv(GL_LIGHT0, GL_DIFFUSE, (const GLfloat *)light0Diffuse);
  89.  
  90. // Define the position of the first light
  91. const GLfloat light0Position[] = {10.0, 10.0, 10.0};
  92. //Vertex3D light0Position[] = {{0.0, 0.0, 0.0}};
  93. glLightfv(GL_LIGHT0, GL_POSITION, (const GLfloat *)light0Position);
  94.  
  95. glEnable(GL_CULL_FACE);
  96. glCullFace(GL_BACK);
  97. }
  98. - (void)dealloc
  99. {
  100. [super dealloc];
  101. }
  102. @end
Add Comment
Please, Sign In to add comment