Hallo erstmal
Ich kämpfe schon seit geraumer Zeit mit OpenGL, und wollte nun ein Objekt (exportiert aus Blender / ohne Textur) in den
GLKview vom GLKViewController bringen. Jedoch wird anscheinend nichts projiziert? Ich weiß einfach nicht an was das liegen kann.. Ist das Objekt aus dem Sichtfeld? Kann ich mir aber iwie nicht vorstellen
wäre toll wenn sich jemand mit OpenGL auskennt und mir weiter helfen könnte.
mfg Seibold
Alles anzeigen
Ich kämpfe schon seit geraumer Zeit mit OpenGL, und wollte nun ein Objekt (exportiert aus Blender / ohne Textur) in den
GLKview vom GLKViewController bringen. Jedoch wird anscheinend nichts projiziert? Ich weiß einfach nicht an was das liegen kann.. Ist das Objekt aus dem Sichtfeld? Kann ich mir aber iwie nicht vorstellen
wäre toll wenn sich jemand mit OpenGL auskennt und mir weiter helfen könnte.
mfg Seibold
Quellcode
- #import "FlascheGLKViewController.h"
- int H = 1024;
- int W = 768;
- @interface FlascheGLKViewController ()
- {
- float _curRed;
- BOOL _increasing;
- }
- @end
- @implementation FlascheGLKViewController
- @synthesize context;
- @synthesize effect;
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
- // Custom initialization
- }
- return self;
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- self.context = [[EAGLContext alloc]initWithAPI:kEAGLRenderingAPIOpenGLES1];
- if (!self.context) {
- NSLog(@"Failed to create ES context");
- }
- GLKView *view = (GLKView*)self.view;
- view.context = self.context;
- view.drawableDepthFormat = GLKViewDrawableDepthFormat16;
- [self setUpGL];
- // Do any additional setup after loading the view.
- }
- - (void)didReceiveMemoryWarning
- {
- NSLog(@"ich bin der Fehler");
- [super didReceiveMemoryWarning];
- if ([self isViewLoaded] && ([[self view] window] == nil))
- {
- self.view = nil;
- [self tearDownGL];
- if ([EAGLContext currentContext] == self.context)
- {
- [EAGLContext setCurrentContext:nil];
- }
- self.context = nil;
- }
- }
- - (void) tearDownGL
- {
- // [EAGLContext setCurrentContext:self.context];
- // glDeleteBuffers(1, &vertexBuffer);
- // self.effect = nil;
- }
- -(void) glkView:(GLKView *)view drawInRect:(CGRect)rect {
- glClearColor(0.6, 0.1, 0.0, 1.0); // RGB und Alpha
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glLoadIdentity();
- GLKMatrix4 gml = GLKMatrix4MakeLookAt(0, 0, 1, //Kamera Position
- 0, 0.3, 0.5, //Look At
- 0, 1, 0); //"Stehend"
- glMultMatrixf(gml.m);
- [self drawOGLCube];
- }
- -(void) update{
- // float aspect = fabsf(self.view.bounds.size.width / self.view.bounds.size.height);
- glLoadIdentity();
- H = self.view.bounds.size.width;
- W = self.view.bounds.size.width;
- int w = W;
- int h = H;
- glMatrixMode(GL_PROJECTION);
- float zNear = 0.1;
- float zFar = 2500;
- float fieldOfViewAngle = 10;
- float top = zNear * tan(M_PI * fieldOfViewAngle / w);
- float bottom = -top;
- float left = bottom * w / h;
- float right = top * w / h;
- glFrustumf(left, right, bottom, top, zNear, zFar); //3D-Perspektive
- //Enable Modelview: Auf das Rendern von Vertex-Arrays umschalten
- glMatrixMode(GL_MODELVIEW);
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnable(GL_DEPTH_TEST);
- glDepthFunc(GL_LESS);
- //Light
- glEnable(GL_LIGHTING);
- glEnable(GL_COLOR_MATERIAL);
- glEnable(GL_LIGHT0);
- GLfloat color0[ ] = {1, 1, 1, 1};
- glLightfv(GL_LIGHT0, GL_DIFFUSE, color0);
- GLfloat light_position0[ ] = {0, 1, 0, 0};
- glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
- /* GLKMatrix4 projectionMatrix = GLKMatrix4MakePerspective(GLKMathDegreesToRadians(50), aspect, 0.1, 100);
- // static __inline__ GLKMatrix4 GLKMatrix4MakePerspective(float fovyRadians, float aspect, float nearZ, float farZ)
- self.effect.transform.projectionMatrix = projectionMatrix;
- GLKMatrix4 modelMatrix = GLKMatrix4MakeTranslation(0, 0, -7);
- modelMatrix = GLKMatrix4RotateY(modelMatrix, rotation);
- self.effect.transform.modelviewMatrix = modelMatrix;
- */
- // rotation += self.timeSinceLastUpdate;
- }
- - (void) setUpGL {
- [EAGLContext setCurrentContext:self.context];
- /*
- self.effect = [[GLKBaseEffect alloc]init];
- self.effect.light0.enabled = GL_TRUE;
- self.effect.light0.diffuseColor = GLKVector4Make(1, 0.8, 1.5, 1.0);
- */
- //Modelview: Auf das Rendern von Vertex Arrays umschalten
- /*
- glEnable(GL_DEPTH_TEST);
- glMatrixMode(GL_MODELVIEW);
- glEnableClientState(GL_VERTEX_ARRAY);
- glDepthFunc(GL_LESS);
- */
- }
- - (void) drawOGLCube {
- NSLog(@"drawOGLCube");
- GLfloat vertices[ ] = {
- -0.157871, 0.952064, -0.988728, 0.037220, 0.952064, -0.969513, 0.224813, 0.952064, -0.912607, 0.397700, 0.952064, -0.820197, 0.549236, 0.952064, -0.695835, 0.673599, 0.952064, -0.544298, 0.766009, 0.952064, -0.371411, 0.822915, 0.952064, -0.183818, 0.842129, 0.952064, 0.011272, -0.157871, 2.952064, 0.011272, 0.822915, 0.952064, 0.206362, 0.766009, 0.952064, 0.393956, 0.673599, 0.952064, 0.566842, 0.549236, 0.952064, 0.718379, 0.397700, 0.952064, 0.842742, 0.224813, 0.952064, 0.935152, 0.037219, 0.952064, 0.992058, -0.157871, 0.952064, 1.011272, -0.352961, 0.952064, 0.992057, -0.540555, 0.952064, 0.935152, -0.713441, 0.952064, 0.842742, -0.864978, 0.952064, 0.718379, -0.989341, 0.952064, 0.566842, -1.081751, 0.952064, 0.393955, -1.138656, 0.952064, 0.206362, -1.157871, 0.952064, 0.011271, -1.138656, 0.952064, -0.183819, -1.081750, 0.952064, -0.371412, -0.989340, 0.952064, -0.544299, -0.864977, 0.952064, -0.695835, -0.713440, 0.952064, -0.820198, -0.540553, 0.952064, -0.912608, -0.352959, 0.952064, -0.969513
- };
- GLfloat normals[ ] = {
- -0.259887, 0.445488, -0.856737, 0.087754, 0.445488, -0.890977, -0.087753, 0.445488, -0.890977, 0.259888, 0.445488, -0.856737, -0.422035, 0.445488, -0.789574, -0.567964, 0.445488, -0.692067, -0.692066, 0.445488, -0.567966, -0.789573, 0.445488, -0.422036, -0.856737, 0.445488, -0.259889, -0.890977, 0.445488, -0.087755, -0.890977, 0.445488, 0.087753, -0.856737, 0.445488, 0.259888, -0.789574, 0.445488, 0.422035, -0.692067, 0.445488, 0.567964, -0.567965, 0.445488, 0.692066, -0.422036, 0.445488, 0.789573, -0.259889, 0.445488, 0.856737, -0.087754, 0.445488, 0.890977, 0.087753, 0.445488, 0.890977, 0.259888, 0.445488, 0.856737, 0.422036, 0.445488, 0.789573, 0.567965, 0.445488, 0.692067, 0.692067, 0.445488, 0.567965, 0.789573, 0.445488, 0.422035, 0.856737, 0.445488, 0.259888, 0.890977, 0.445488, 0.087753, 0.890977, 0.445488, -0.087754, 0.856737, 0.445488, -0.259888, 0.789573, 0.445488, -0.422036, 0.692067, 0.445488, -0.567965, 0.567965, 0.445488, -0.692067, 0.422036, 0.445488, -0.789573, 0.000000, -1.000000, -0.000000
- };
- GLushort faces[ ] = { //12 Faces = 6 Wuerfelseiten mit je zwei Dreiecken
- 31, 9, 32, 0, 9, 1, 9, 0, 32, 1, 9, 2, 30, 9, 31, 29, 9, 30, 28, 9, 29, 27, 9, 28, 26, 9, 27, 25, 9, 26, 24, 9, 25, 23, 9, 24, 22, 9, 23, 21, 9, 22, 20, 9, 21, 19, 9, 20, 18, 9, 19, 17, 9, 18, 16, 9, 17, 15, 9, 16, 14, 9, 15, 13, 9, 14, 12, 9, 13, 11, 9, 12, 10, 9, 11, 8, 9, 10, 7, 9, 8, 6, 9, 7, 5, 9, 6, 4, 9, 5, 3, 9, 4, 2, 9, 3, 0, 1, 32, 1, 31, 32, 1, 2, 31, 2, 30, 31, 2, 3, 30, 3, 29, 30, 3, 4, 29, 4, 28, 29, 4, 5, 28, 5, 27, 28, 5, 6, 27, 6, 26, 27, 6, 7, 26, 7, 25, 26, 7, 8, 25, 8, 24, 25, 8, 10, 24, 10, 23, 24, 10, 11, 23, 11, 22, 23, 11, 12, 22, 12, 21, 22, 12, 13, 21, 13, 20, 21, 13, 14, 20, 14, 19, 20, 14, 15, 19, 15, 18, 19, 15, 16, 18, 16, 17, 18
- };
- //Anzahl der Array-Elemente
- //int verticesLength = sizeof(vertices) / sizeof(GLfloat);
- int facesLength = sizeof(faces) / sizeof(GLushort);
- //Render obj-Modell
- glEnableClientState(GL_NORMAL_ARRAY); //normal arrays aktivieren
- glEnable(GL_NORMALIZE);
- glEnable(GL_CULL_FACE); //Nicht sichtbare Flaechen ignorieren
- glCullFace(GL_BACK);
- glVertexPointer(3, GL_FLOAT, 0, vertices);
- glNormalPointer(GL_FLOAT, 0, normals);
- glColor4f(1, 1, 0, 1); //Einfaerben
- //Matrix-Operations
- glPushMatrix();
- glTranslatef(0, 0, -7);
- static int angle = 0; angle += 2;
- glRotatef(angle, 0, 1, 0);
- //glDrawArrays(GL_TRIANGLE_STRIP, 0, verticesLength/3);
- glDrawElements(GL_TRIANGLES, facesLength, GL_UNSIGNED_SHORT, faces);
- glPopMatrix();
- //Cleanup
- // glDisableClientState(GL_NORMAL_ARRAY);
- glDisable(GL_NORMALIZE);
- glDisable(GL_CULL_FACE);
- //glDrawArrays(GL_TRIANGLE_STRIP, 0, verticesLength/3); //-> obj liefert faces
- }
- -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
- self.paused = !self.paused ;
- }
- @end