OpenGL ESã§ã®ç»è§ã®æå®
iPhone ä¸ã§Open GL ES1ãå©ç¨ãã¦ãç»è§ãæå®ãã¦ã®ãªãã¸ã§ã¯ãã®æç»æ¹æ³ã調ã¹ã¦ã¿ã¾ãã®ã§ã
ã¡ã¢ã§ãã
ï¼ãã£ã¨ããã¡ãã¨ããæ¹æ³ãä»ã«ããã®ã ã¨ãã¨ã¯ãããã¾ãã....ï¼
åææºå
- XCodeã§Open GL ES Applicationãé¸æãã¦ããã¸ã§ã¯ããä½æãããã«ãã£ã¦ããã³ãã¬ã¼ãã½ã¼ã¹ãçæãããã
- OpenGL ES 2.0 対å¿ãç¡å¹ã«ãã
EAGLView.m ã® initWithCoder ã¡ã½ããã§ã®ES2Rendererãªãã¸ã§ã¯ãã®çæé¨åãã³ãããããã ã.
// renderer = [[ES2Renderer alloc] init];
ããã§ãES1Renderer.m ã® renderã¡ã½ãããç·¨éãããã¨ã«ããã
Open GL ES1 ã§ã®æç»ããããã¨ãã§ããã
ãããã¯こちらãªã©ãåç §.
æç»å®è£ ã®åæ
ã¨ãããããç°¡ç¥å¯ããããã«ä»¥ä¸ã®å¶éãåæã§ã®å®è£ ã¨ãã¾ããã
- å¹ ->1.0, é«ã->1.0 / (Window ã®å¹ / é«ã), 奥è¡ã1.0ã®ãµã¤ãºã®ãªãã¸ã§ã¯ã空éã«æç»ãããã¨ã¨ããã座æ¨ã¨ãã¦ã¯ãx -> -0.5ã 0.5, y -> -0.5 * (Window ã®å¹ / é«ã)ã0.5 * (Window ã®å¹ / é«ã), z -> -0.5 ã0.5ã®
ç¯å²ã®ãªãã¸ã§ã¯ããæç»ããããã®ã¨ããã
- æ°´å¹³ç»è§ã§ã®è¨ç®ã¨ããã
å®è£
ç»è§/2ã«å¯¾ããtanã®é(ä½æ¥)ã«Object座æ¨ã®å¤§ãã(1.0)ãæãããã®ãã表示ç¯å²ï¼è¦ä½ç©ï¼ã®ä¸çªæåã¨ãªãã
ãã¤ããªãã¸ã§ã¯ãã®æåã«ãªãããã«å®è£
ãã¾ããã
æé ã¨ãã¦ã¯ã
- ç»è§/2ã«å¯¾ããtangentã®é(ä½æ¥)ã«Object座æ¨ã®å¤§ãã(1.0)ãæãããã®ãã表示ç¯å²ï¼è¦ä½ç©ï¼ã®ä¸çªæåã¨ãªããããglFrustumfã§ã®è¨å®ãè¡ãã
- æç»ãªãã¸ã§ã¯ããåç¹ãã表示ç¯å²ã®æåã¾ã§ã®è·é¢ã¨Object座æ¨ä¸ã®Z座æ¨ã®ãã¤ãã¹æ¹åã®å¤§ãããå ããè·é¢ã ããã¤ãã¹æ¹åã«ç§»å.ããã§ãObjectã®ãã¤ãã¹å´ã®ä¸çªæåãã表示ç¯å²ï¼è¦ä½ç©ï¼ã®ä¸çªæåã¨ãªã.
ES1Renderer.m ã® renderã¡ã½ããã®å®è£
ã¯ä»¥ä¸ã®ã¨ããã§ããç»è§ã¯60度ã¨ãã¿ã«æå®ãã¦ãã¾ãã
- (void)render { // This application only creates a single context which is already set current at this point. // This call is redundant, but needed if dealing with multiple contexts. [EAGLContext setCurrentContext:context]; // This application only creates a single default framebuffer which is already bound at this point. // This call is redundant, but needed if dealing with multiple framebuffers. glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer); glViewport(0, 0, backingWidth, backingHeight); glMatrixMode(GL_PROJECTION); glLoadIdentity(); GLfloat fovy = 60.0f; // ç»è§ã60度ã¨ãã /* è§åº¦ã«ããããè¦ä½ç©ã®è¨å®. tanã®é(ä½æ¥)ã«Object座æ¨ã®å¤§ãããæãããã®ãã nearã®ä½ç½®ã«ããããã«ãã. */ GLfloat aspect = (GLfloat)backingWidth / (GLfloat)backingHeight; GLfloat width = 1.0f; GLfloat height = width / aspect; GLfloat near = 1.0f; GLfloat far = 100.0f; near = 1.0f / tan(fovy * 0.5 * M_PI / 180.0) * width; GLfloat x = width / 2; GLfloat y = height / 2; glFrustumf(-x, x, -y, y, near, far); NSLog(@"glFrustumf(%f,%f,%f,%f,%f,%f)",-x, x, -y, y, near, far); /* è¦ä½ç©ã®nearã®ä½ç½®ã«ãããã¦ãã¢ãã«Z座æ¨ã移å åç¹ããnearã¾ã§ã®è·é¢ï¼Objectã®Z座æ¨ã®ãã¤ãã¹æ¹åã¸ã®å¤§ããåã ããã¤ãã¹æ¹åã«ç§»å. ããã§ãObjectã®ãã¤ãã¹å´ã®ä¸çªæåãã è¦ä½ç©ã®ä¸çªæåã¨ãªã. */ // glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0f, 0.0f, -(width / 2) - near); NSLog(@"glTranslatef z = %f",-(width / 2) - near); // .... ããã§ãªãã¸ã§ã¯ãã®æç»ã.... // [self draw]; // // This call is redundant, but needed if dealing with multiple renderbuffers. glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer); [context presentRenderbuffer:GL_RENDERBUFFER_OES]; }