Home Blog erstellt am: : 12/03/08 Zuletzt aktualisiert : 03/01/10 18:47 / 126 veröffentlichte Einträge
 

c) Open GL fürs iPhone und nochmal von Anfang an

c1) Warum nochmal von Vorne  (c) Open GL fürs iPhone und nochmal von Anfang an) Verfasst: Freitag, den 11. Dezember 2009 17:29

ja also ich war mit den Serien a) und b) nicht wirklich Inhaltlich zufrieden , da ich noch zuviele offene Fragen haben ... insbedondere im ES2 Part mit den Shadern was eigentlich als nächstes Thema kommen sollte ... dieses mal nehme ich jedoch einen anderen Blog als Aufbau...

hier die Links der ersten beiden Parts

Part 1

http://iphonedevelopment.blogspot.com/2009/04/opengl-es-from-ground-up-part-1-basic.html

Part2

http://iphonedevelopment.blogspot.com/2009/04/opengl-es-from-ground-up-part-2-look-at.html

hier kann man sich ein Template runterladen ... und es in Xcode einbinden...unter

/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Project Templates/Application/

ein binden

Link des Templates :  http://www.innerloop.biz/code/Empty%20OpenGL%20ES%20Application.zip

 

 

in Part 2 ... sehr gut erklärt (leider eng)->  ist man dann schon beim Dreieck Beispiel

 

Permalink

c2) mal kein Dreieck oder Viereck  (c) Open GL fürs iPhone und nochmal von Anfang an) Verfasst: Freitag, den 11. Dezember 2009 18:20

in Parts 2 wird auch dieses Beispiel erklärt ... einfach neuen Projekt mit dem empty OGL öffnen und die DraVIEW auswechseln...

- (void)drawViewGLView*)view;
{
 static GLfloat rot = 0.0;
 // This is the same result as using Vertex3D, just faster to type and
    // can be made const this way   
 static const Vertex3D vertices[]= {
        {0, -0.525731, 0.850651},             // vertices[0]
        {0.850651, 0, 0.525731},              // vertices[1]
        {0.850651, 0, -0.525731},             // vertices[2]
        {-0.850651, 0, -0.525731},            // vertices[3]
        {-0.850651, 0, 0.525731},             // vertices[4]
        {-0.525731, 0.850651, 0},             // vertices[5]
        {0.525731, 0.850651, 0},              // vertices[6]
        {0.525731, -0.850651, 0},             // vertices[7]
        {-0.525731, -0.850651, 0},            // vertices[8]
        {0, -0.525731, -0.850651},            // vertices[9]
        {0, 0.525731, -0.850651},             // vertices[10]
        {0, 0.525731, 0.850651}               // vertices[11]
    };
 static const Color3D colors[] = {
        {1.0, 0.0, 0.0, 1.0}, {1.0, 0.5, 0.0, 1.0}, {1.0, 1.0, 0.0, 1.0},
  {0.5, 1.0, 0.0, 1.0}, {0.0, 1.0, 0.0, 1.0}, {0.0, 1.0, 1.0, 1.0}, 
  {0.0, 0.5, 1.0, 1.0}, {0.0, 0.0, 1.0, 1.0}, {0.5, 0.0, 1.0, 1.0},   
  {1.0, 0.0, 1.0, 1.0}, {1.0, 0.0, 0.5, 1.0} 
 };    
 static const GLubyte icosahedronFaces[] = { 
  1, 2, 6,     1, 7, 2,      3, 4, 5,     4, 3, 8,  
  6, 5, 11,  5, 6, 10,    9, 10, 2,   10, 9, 3,     
  7, 8, 9,   8, 7, 0,     11, 0, 1,      0, 11, 4,  
  6, 2, 10,      1, 6, 11,     3, 5, 10,    5, 4, 11,      
  2, 7, 9,      7, 1, 0,    3, 9, 8,    4, 8, 0,    }; 
 glLoadIdentity(); 
 glTranslatef(0.0f,0.0f,-3.0f);  
 glRotatef(rot,1.0f,1.0f,1.0f);
 glClearColor(0.7, 0.7, 0.7, 1.0);
 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  
 glEnableClientState(GL_VERTEX_ARRAY); 
 glEnableClientState(GL_COLOR_ARRAY); 
 glVertexPointer(3, GL_FLOAT, 0, vertices);
 glColorPointer(4, GL_FLOAT, 0, colors); 
 glDrawElements(GL_TRIANGLES, 60, GL_UNSIGNED_BYTE, icosahedronFaces);
 glDisableClientState(GL_VERTEX_ARRAY); 
 glDisableClientState(GL_COLOR_ARRAY);  
 static NSTimeInterval lastDrawTime;
    if (lastDrawTime) 
 {   
  NSTimeInterval timeSinceLastDraw = [NSDate timeIntervalSinceReferenceDate] - lastDrawTime; 
  rot+=50 * timeSinceLastDraw;        
 }
 lastDrawTime = [NSDate timeIntervalSinceReferenceDate];
}

zu Beachten ist hier das in dem leeren Projekt schon etwas vorarbeit gemacht wurde mit der Common.h

In Part 3 http://iphonedevelopment.blogspot.com/2009/04/opengl-es-from-ground-up-part-3.html

wird dann die Sache mit der View erklärt glOrthof und glFrustrumf

...

Achtung: wer die Parts von dieser Seite durchprobieren möchte sollte folgende wichtige Info lesen!

http://iphonedevelopment.blogspot.com/2009/12/opengl-es-projects-and-iphone-sdk-30.html

hier die Sammlung:

http://iphonedevelopment.blogspot.com/2009/05/opengl-es-from-ground-up-table-of.html

Permalink

c3) Das OGL Templat und mal ein Coordinatenfeld  (c) Open GL fürs iPhone und nochmal von Anfang an) Verfasst: Montag, den 14. Dezember 2009 13:30

Projekt.zip (etwas geändert!) http://www.4yit.de/ip/download/GLp_coord 2.zip

das Template aus c1) gefällt mir ganz gut ... hab mal etwas in der GLViewController umgespielt...

in die h kommt noch eine Variable cc für die Farbänderung:

@interface GLViewController : UIViewController <GLViewDelegate>
{
 GLfloat cc;
}

und hier die

//
//  GLViewController.m
//  Untitled
//
//  Created by iZero MrZ on 13.12.09.
//  Copyright 4yIT.de 2009. All rights reserved.
//

#import "GLViewController.h"
#import "ConstantsAndMacros.h"
#import "OpenGLCommon.h"
@implementation GLViewController
- (void)drawViewUIView *)theView
{
 // Projection nicht reseten nur ndern
 glMatrixMode(GL_PROJECTION);
 glRotatef(0.5, 0.0, 1.0, 0.0);
 glTranslatef(0.0, 0.0, 0.01); //Camview ndern indem die ganze Welt verschoen wird
 // glLoadIdentity(); // hier nicht lschen
 
 glMatrixMode(GL_MODELVIEW); 
 glLoadIdentity();
  
 // --------------START DRAW
 glColor4f(0.0, 0.0, 0.0, 0.0);
 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   
    // lines
 const GLfloat lineh[] = {
        -10.0, 0.0, 0.0,    
        10.0, 0.0, 0.0     
    };
 const GLfloat linev[] = {
        0.0, 0.0, -10.0,    
  0.0, 0.0, 10.0     
    }; 
 glLoadIdentity();    
    glVertexPointer(3, GL_FLOAT, 0, lineh);
    glEnableClientState(GL_VERTEX_ARRAY);
 
 if ( cc >= 1.0) { cc = 0.1; };
  cc = cc + 0.01;
 
 for (int i = -10; i <= 10; i++) {
  glLoadIdentity();
  glColor4f(cc, 1.0, 0.0, 1.0);
  glTranslatef(0.0, 0.0, 0.0 - (GLfloat)i);
  glVertexPointer(3, GL_FLOAT, 0, lineh);
  glDrawArrays(GL_LINES, 0, 2);  
  
  glLoadIdentity();
  glColor4f(cc, 1.0, 0.0, 1.0);
  glTranslatef(0.0 - (GLfloat)i, 0.0, 0.0);
  glVertexPointer(3, GL_FLOAT, 0, linev);
  glDrawArrays(GL_LINES, 0, 2); 
  
  glLoadIdentity();
 } 
  
 glDisableClientState(GL_VERTEX_ARRAY); 
 
 // Punkte und linien ____________________
 const GLfloat points[] = {
        0.0, 0.0, 0.0,         1.0, 0.0, 0.0, 1.0, // First point, Red 
        1.0, -1.0, 0.0,        0.0, 1.0, 0.0, 1.0, // Second point, Green 
        -1.0, -1.0, 0.0,       0.0, 0.0, 1.0, 1.0, // Third point, Blue   
        -1.0, 1.0, 0.0,        1.0, 1.0, 0.0, 1.0  // Fourth point, Yellow   
    };

 glLoadIdentity();
 
 glEnable(GL_POINT_SMOOTH);
 glPointSize(5.0);
 
 glTranslatef(0.0, 0.0, 0.0);
 
    glVertexPointer(3, GL_FLOAT, 28, points);
    glColorPointer(4, GL_FLOAT, 28, &points[3]);
    glEnableClientState(GL_COLOR_ARRAY);
    glEnableClientState(GL_VERTEX_ARRAY);
 glDrawArrays(GL_POINTS, 0, 1);
 // glDrawArrays(GL_LINES, 0, 4); // Linien mit den gleichen Coord der Punkte
 // glDrawArrays(GL_LINE_STRIP, 0, 4);
 // glDrawArrays(GL_LINE_LOOP, 0, 4);
 
 glDisableClientState(GL_COLOR_ARRAY);
 glDisableClientState(GL_VERTEX_ARRAY); 
 

 // Dreieck
 const GLfloat Dreieck[] = {
        0.0, 1.0, 0.0,    // Triangle top centre
        1.0, -1.0, 0.0,   // bottom right
        -1.0, -1.0, 0.0   // bottom left
    };
 
 glLoadIdentity();
 
 // glScalef(2.0, 2.0, 2.0);
 glRotatef(0.0, 0.0, 0.0, 0.0);   
 glTranslatef(0.0, 0.0, -0.2);
 glColor4f(cc, 0.0, 1.0, 1.0);
 
 // glColorPointer(4, GL_FLOAT, 0, DreieckFare);      // NEW
 //glEnableClientState(GL_COLOR_ARRAY);  
 
 glEnableClientState(GL_VERTEX_ARRAY);
 glVertexPointer(3, GL_FLOAT, 0, Dreieck);
 
 glDrawArrays(GL_TRIANGLES, 0, 3);
 
 glDisableClientState(GL_VERTEX_ARRAY);
 
}
-(void)setupViewGLView*)view
{
 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);
 
 glRotatef(15.0, 0.0, 1.0, 0.0);
 glTranslatef(0.0, -1.0, -5.0); //Camview ndern indem die ganze Welt verschoen wird
 // glLoadIdentity(); // hier nicht lschen
 
 glMatrixMode(GL_MODELVIEW); 
 glLoadIdentity();
 NSLog(@"init View");
}
- (void)dealloc
{
    [super dealloc];
}
@end

Das Ergebnis kann man im Bild sehen.... und auch das sich die Projektionbewegt und nicht die Objekte

Achtung an die Smiles hier im code denken ... sry hatte jetzt keinen Bog die anzupassen ... sollte Duppelpunkt und Klammer auf sein {#}

achso und den Text kann man via IB setzen

Permalink

c4) OBJ hinzufügen - ein Flugzeug  (c) Open GL fürs iPhone und nochmal von Anfang an) Verfasst: Mittwoch, den 16. Dezember 2009 18:15

um eine Kugel aus dem Stehgreif zu erstellen wäre wohl eine mathematische Herrausvorderung da GL ES das nicht wie GL von Haus aus unterstützt .... da kann man dann besser 3d Programme wie 3dmax oder Blender benutzen ... bei 3dmax kann man dann die Objekte als Wavefront OBJ exportieren und in das eigene Programm integrieren ...

hier der Link ... http://iphonedevelopment.blogspot.com/2009/03/wavefront-obj-loader-open-sourced-to.html ...  ... fall ihr den download des Projektes nicht findet bitte bescheid geben ... ich hab noch ne orginal Kopie die ich auf meinen Server legen könnte. Die Export Datei ist auch gut lesbar und mit etwas fummeln kann man sich die faces und vertex manuell in sein Programm kopieren.

Die Sache mit dem loader ist natürlich ne feine Sache ... jedoch fehlen ja noch Texturen...

Hinweis: beim export darf zwischen v und zahl nur ein Leerzeichen sein !!

im loader werden momentan nur vertex und faces geladen

Permalink

c5) Infos zu Texturen und PVRTC  (c) Open GL fürs iPhone und nochmal von Anfang an) Verfasst: Montag, den 21. Dezember 2009 19:22

png Images sollten folgende Bildpunktgrößen aufweisen

2x2, 4x4, 8x8, 16x16, 32x32, 64x64, 128x128, 256x256, 512x512, or 1024x1024

Apple propagiert hier noch eine Kompresion PVRTC  der png images.

Die Datei die diese Compresion herstellt:

/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/texturetool

z.B.
texturetool -e PVRTC -o neu.pvr4 org.png

 

 

 

Permalink