(iPhone)ãã¯ã¹ãã£ã使ã
(â»å½åãæ²è¼ãã¦ããããã°ã©ã ã¯ä¸é¨ãã¹ãæã£ãã®ä¿®æ£ãã¾ãã)
ä»åã¯iPhoneã§ãã¯ã¹ãã£(ã¢ã«ãã¡ä»ããç¡ãã®ä¸¡æ¹)ã使ç¨ããæ¹æ³ã解説ãã¾ãã
iPhoneã®ããã°ã©ã ã®glDrawArrays()ã使ã£ããã®ã¨glDrawElements()ã使ã£ããµã³ãã«ãæºåãã¾ããããã¡ãã確èªããªããèªã¿é²ãã¦ä¸ããã
Macçã®ããã°ã©ã ã¯こちらãåç §ãã¦ä¸ããã
ãã¬ã³ãé¢æ°ã®è¨å®ã¨ãã¬ã³ãå¦çã®æå¹å
ä»åã¯ã¢ã«ãã¡å¤ãå«ãã ãã¯ã¹ãã£ã使ç¨ããããã»ããã¢ããå¦çã®é¨åã§ä»¥ä¸ã®è¨è¿°ã追å ãã¾ãã
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND);
ãã¯ã¹ãã£ãã¡ã¤ã«ã®èªã¿è¾¼ã¿
ãã¯ã¹ãã£ãã¡ã¤ã«ã¯ NSImage ã使ããPNGãã¡ã¤ã«ãèªã¿è¾¼ãã§mallocã§ç¢ºä¿ããã¡ã¢ãªä¸ã«å±éãã¦ãã¾ãã
詳細ã¯ä»¥ä¸ã®ã¡ã½ãããåç
§ä¸ããã
(â»ãã¡ãã®ã¡ã½ããã¯32ãããã¨24ãããã®PNGãã¡ã¤ã«ããã¯ã¹ãã£ã¨ãã¦èªã¿è¾¼ããã¡ã½ããã¨ãªã£ã¦ãã¾ãããèªèº«ã®ããã°ã©ã ã«ã¦ãèªç±ã«ã使ãä¸ãã)
- (BOOL)loadTexture:(NSString *)filename toOutput:(unsigned char**)textureData andTextureSize:(int*)pTextureSize
ãã¬ã¼ã ã¯ã¼ã¯ã®è¿½å
ãã¡ãã®ã¡ã½ããã§ã¯ CoreGraphics ãã¬ã¼ã ã¯ã¼ã¯ã使ç¨ãã¦ãã¾ãã®ã§ä»¥ä¸ã®ãã¹ãã CoreGraphics.framework ã追å ãã¦ä¸ããã
/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.2.1.sdk/System/Library/Frameworks/CoreGraphics.framework
â»ãã£ã¬ã¯ã㪠iPhoneOS2.2.1.sdk ã¯å¯¾è±¡ã«ããããã¼ã¸ã§ã³æ¯ã«ç°ãªãã¾ããèªåãã¿ã¼ã²ããã«ããOSã®ãã£ã¬ã¯ããªãé¸æãã¦ä¸ããã
- (BOOL)loadTexture:(NSString *)filename toOutput:(unsigned char**)textureData andTextureSize:(int*)pTextureSize
ã¡ã½ããã®å¼æ°ã®èª¬æã¯ä»¥ä¸ã¨ãªãã¾ãã
filename | ãã¯ã¹ãã£ã«ä½¿ãç»åãã¡ã¤ã«(ãã«ãã¹ã§æå®)ã |
---|---|
textureData | ãã¯ã¹ãã£ã«ä½¿ãã¡ã¢ãªé åãæããã¤ã³ã¿ãç»åãã¡ã¤ã«ã®èªã¿è¾¼ã¿ã«æåããå ´åã« malloc() ã§ç¢ºä¿ãããé åãè¨å®ããã¾ããã¢ããªçµäºåã« free() ãã¦ä¸ããã |
pTextureSize | ãã¯ã¹ãã£ã®ãµã¤ãºãè¿ãã¾ããiPhoneã§ã¯ç¸¦ã横ã®ãµã¤ãºãåä¸ã§æãå¿ è¦ããããããã®å¤ã縦ã横両æ¹ã®ãµã¤ãºã示ãã¦ãã¾ãã |
次ã«ãã¯ã¹ãã£åãåå¾ã
glGenTextures(1, &flowerPanelTextureName);
ãããBindããã«ã¬ã³ãã«è¨å®ãã¾ãã
glBindTexture(GL_TEXTURE_2D, flowerPanelTextureName);
ããã«ãã以éã®å¦çã¯ãã®ãã¯ã¹ãã£åã«é¢é£ä»ãããã¾ãã
ãã¯ã¹ãã£é¢é£ã®å種è¨å®ãè¡ãã¾ãã
glTexImage2D(GL_TEXTURE_2D, 0, // MIPMAPã®ãã¯ã¹ãã£è§£å度(使ç¨ããªãã¨ãã¯0) GL_RGBA, // OpenGLå é¨ã§ã®ãã¯ã»ã«ãã¼ã¿ã®ãã©ã¼ããã flowerPanelTextureSize, // å¹ flowerPanelTextureSize, // é«ã 0, // ãã¯ã¹ãã£ã®å¢çç·ã®å¤ªã GL_RGBA, // ã¡ã¢ãªä¸(æ ¼ç´å)ã®ãã¯ã»ã«ãã¼ã¿ã®ãã©ã¼ããã GL_UNSIGNED_BYTE, // ã¡ã¢ãªä¸(æ ¼ç´å)ã®ãã¯ã»ã«ãã¼ã¿ã®ãã¼ã¿å flowerPanelTextureData // ã¡ã¢ãªä¸(æ ¼ç´å)ã®ãã¯ã»ã«ãã¼ã¿ã¸ã®ãã¤ã³ã¿ ); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); // Sæ¹å(横æ¹å)ã§å ã®ãã¯ã¹ãã£ç»åå¤ã®ä½ç½®ã // æå®ãããã¨ãã®å¦çæ¹æ³ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // Tæ¹å(縦æ¹å)ã§å ã®ãã¯ã¹ãã£ç»åå¤ã®ä½ç½®ã // æå®ãããã¨ãã®å¦çæ¹æ³ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // ãã¯ã¹ãã£æ¡å¤§æã®è£å®æ¹æ³ãæå® glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // ãã¯ã¹ãã£ç¸®å°æã®è£å®æ¹æ³ãæå®
æç»
æç»å¦çã®ä¸»ãªé¨åã¯ä»¥ä¸ã¨ãªãã¾ãã
ã¾ãã¯ãã¯ã¹ãã£ã®Bindãè¡ãã¾ããããã«ãã以éã®å¦çã§ãã¯ã¹ãã£ãå¿ è¦ã«ãªã£ãå ´åã flowerPanelTextureName ã§è¨å®ãããã¼ã¿ã使ããã¾ãã
glBindTexture(GL_TEXTURE_2D, flowerPanelTextureName);
ããã¦æ¬¡ã«ã¡ã¤ã³ã®æç»ã³ãã³ããå®è¡ãã¾ãã
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
以ä¸ã¨ãªãã¾ãããã¯ã¹ãã£ã®ç»åãã¡ã¤ã«ãå¤æ´ãããªã©èªåã§ãè²ã ã¨è©¦ãã¦ã¿ã¦ä¸ããã
iPhone3Dããã°ã©ãã³ã°è¬åº§ã®ä¸è¦§ã¯こちら