Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // GLViewController.m
- // Isometric
- //
- // Created by Mac Admin on 05/01/2010.
- // Copyright __MyCompanyName__ 2010. All rights reserved.
- //
- #import "GLViewController.h"
- #import "ConstantsAndMacros.h"
- #import "OpenGLCommon.h"
- @implementation GLViewController
- static GLuint texture[1];
- - (void)drawView:(UIView *)theView
- {
- //Clear some stuff
- glColor4f(0.0, 0.0, 0.0, 0.0);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glClearColor(1.0,1.0,1.0,1.0);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- //Drawing Setup
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_NORMAL_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- //Rendering
- glLoadIdentity();
- glRotatef(-90.0,0.0,0.0,1.0); //Because we are using the device in landscape mode.
- glTranslatef(0.0,0.0,-10.0); //Pull the camera back
- glRotatef(45,1.0,0.0,0.0); //tilt the camera so it's looking slightly downwards
- glBindTexture(GL_TEXTURE_2D, texture[0]); //Bind Level Texture
- glVertexPointer(3, GL_FLOAT, 0, vertices); //Give OpenGL the Level Vertices
- glNormalPointer(GL_FLOAT, 0, normals); //Give OpenGL the Level Vertex Normals
- glTexCoordPointer(2, GL_FLOAT, 0, texCoords); //Give OpenGL the Level Texture Coordinates
- glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, polygons); //Tell OpenGL to draw the Level
- /* PREVIOUS 4 LINES NEED THE DATA FROM THE PLIST */
- //Drawing Unsetup
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_NORMAL_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- }
- -(void)setupView:(GLView*)view
- {
- /* LOAD THE PLIST DATA HERE? */
- const GLfloat zNear = 0.01, zFar = 1000.0, fieldOfView = 45.0;
- GLfloat size;
- glEnable(GL_DEPTH_TEST);
- glMatrixMode(GL_PROJECTION);
- size = zNear * tanf(DEGREES_TO_RADIANS(fieldOfView) / 2.0);
- CGRect rect = view.bounds;
- glFrustumf(-size, size, -size / (rect.size.width / rect.size.height), size / (rect.size.width / rect.size.height), zNear, zFar);
- glViewport(0, 0, rect.size.width, rect.size.height);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- // Turn necessary features on
- glEnable(GL_TEXTURE_2D);
- glEnable(GL_BLEND);
- glBlendFunc(GL_ONE, GL_SRC_COLOR);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glGenTextures(1, &texture[0]);
- glBindTexture(GL_TEXTURE_2D, texture[0]);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
- loadTexture(@"Tex");
- glEnable(GL_LIGHTING);
- // Turn the first light on
- glEnable(GL_LIGHT0);
- // Define the ambient component of the first light
- static const Color3D light0Ambient[] = {{1.0, 1.0, 1.0, 1.0}};
- glLightfv(GL_LIGHT0, GL_AMBIENT, (const GLfloat *)light0Ambient);
- // Define the diffuse component of the first light
- static const Color3D light0Diffuse[] = {{1.0, 1.0, 1.0, 1.0}};
- glLightfv(GL_LIGHT0, GL_DIFFUSE, (const GLfloat *)light0Diffuse);
- // Define the position of the first light
- const GLfloat light0Position[] = {10.0, 10.0, 10.0};
- //Vertex3D light0Position[] = {{0.0, 0.0, 0.0}};
- glLightfv(GL_LIGHT0, GL_POSITION, (const GLfloat *)light0Position);
- glEnable(GL_CULL_FACE);
- glCullFace(GL_BACK);
- }
- - (void)dealloc
- {
- [super dealloc];
- }
- @end
Add Comment
Please, Sign In to add comment