ãŸããå²è·¯ã«ç«ããããŸãããèšäºãäœæããªãããã«ã1ã€ã®èšäºã§ãŠã£ã³ããŠãšã³ã³ããã¹ããäœæãããªã©ããã¹ãŠã®åºæ¬ã説æããŸããããã®å Žåã誰ãããã®ãããªå·šå€§ãªèšäºããã¹ã¿ãŒã§ããããã§ã¯ãããŸãã ãŸãã¯ã以åã®ããã«ãå ã®éå±€ã«åºã¥ããŠç¿»èš³ããŸãã 2çªç®ã®ãªãã·ã§ã³ãéžæããããšã«ããŸããã
Vulkanã¬ãã¹ã³ãç ç²ã«ããŠïŒæ®å¿µãªãããçŸæç¹ã§ã¯Vulkan APIããµããŒãããŠããªããããªã«ãŒããäžè¶³ããŠããããããã®APIã®ã¬ãã¹ã³ãæžãã®ã¯é£ããã®ã§ããã®APIã®ã¬ãã¹ã³ã¯ãããªã«ãŒãã®æŽæ°åŸã«ã®ã¿è¡ãããŸãã
å
容
ããŒã1.ã¯ããã«
ããŒã2.åºæ¬çãªç §æ
ããŒã3. 3Dã¢ãã«ãããŠã³ããŒããã
ããŒã4.é«åºŠãªOpenGLæ©èœ
ããŒã5.é«åºŠãªç §æ
- Opengl
- ãŠã£ã³ããŠäœæ
- ããã«ã¡ã¯ãŠã£ã³ããŠ
- ããã«ã¡ã¯ãã©ã€ã¢ã³ã°ã«
- ã·ã§ãŒããŒ
- ãã¯ã¹ãã£ãŒ
- å€æ
- 座æšç³»
- ã«ã¡ã©
ããŒã2.åºæ¬çãªç §æ
ããŒã3. 3Dã¢ãã«ãããŠã³ããŒããã
ããŒã4.é«åºŠãªOpenGLæ©èœ
- 深床ãã¹ã
- ã¹ãã³ã·ã«ãã¹ã
- è²æ··å
- é¡ã®ã¯ãªããã³ã°
- ãã¬ãŒã ãããã¡
- ãã¥ãŒããã¯ã«ãŒã
- é«åºŠãªããŒã¿åŠç
- é«åºŠãªGLSL
- 幟äœåŠã·ã§ãŒããŒ
- ã€ã³ã¹ã¿ã³ã¹å
- ã¹ã ãŒãžã³ã°
ããŒã5.é«åºŠãªç §æ
- é«åºŠãªç §æã Blinn-Fongã¢ãã«ã
- ã¬ã³ãè£æ£
- ã·ã£ããŠã«ãŒã
- å šæ¹åã·ã£ããŠããã
ããŒã1.1-OpenGL
ãšã³ããªãŒ
æ ãå§ããåã«ãOpenGLãšã¯äœããç解ããå¿ èŠããããŸãã åºæ¬çã«ãOpenGLã¯APIïŒã¢ããªã±ãŒã·ã§ã³ããã°ã©ãã³ã°ã€ã³ã¿ãŒãã§ã€ã¹ïŒãšããŠç解ãããŠãããã°ã©ãã£ãã¯ã¹ãšç»åã®ç®¡çã«äœ¿çšã§ããæ©èœã®å€§ããªã»ãããæäŸããŸãã ããããå®éã«ã¯ãOpenGLã¯Khronos Groupã«ãã£ãŠéçºããã³ä¿å®ãããŠããä»æ§ã§ãã
OpenGLä»æ§ã«ã¯ãåç¹å®ã®é¢æ°ã®çµæãã©ããªãããäœããã¹ãããèšè¿°ãããŠããŸãã ãããŠããã§ã«ãããã®ä»æ§ã®å®è£ ã¯éçºè ã«ããã£ãŠããŸãã ãŸããä»æ§ã«ã¯å®è£ ã®è©³çŽ°ãèšèŒãããŠããªããããå°ãªããšãä»æ§ã«æºæ ããŠããéããããŸããŸãªOpenGLå®è£ ã«ã¯ååšããæš©å©ããããŸãã
OpenGLã©ã€ãã©ãªãéçºãã人ã ã¯ãå€ãã®å Žåããããªã«ãŒãã®ã¡ãŒã«ãŒã§ãã è³Œå ¥ããåãããªã«ãŒãã¯ããã®äžé£ã®ãããªã«ãŒãçšã«éçºãããäžé£ã®ã©ã€ãã©ãªã®OpenGLã®ç¹å®ã®ããŒãžã§ã³ããµããŒãããŠããŸãã Appleã·ã¹ãã ã䜿çšããå ŽåãOpenGLã©ã€ãã©ãªã¯Appleã«ãã£ãŠãµããŒããããŸããLinuxã§ã¯ããããã®ã©ã€ãã©ãªã®ãµãã©ã€ã€ãšãŠãŒã¶ãŒã®é©å¿ã®ããŒãžã§ã³ã®çµã¿åããããããŸãã ãŸãã䜿çšããŠããOpenGLã®ããŒãžã§ã³ãå¥åŠãªåäœã瀺ããŠããå Žåãé«ã確çã§ããããããªã«ãŒãã¡ãŒã«ãŒã®ééãã§ããããšãæå³ããŸãã
ã»ãšãã©ã®å®è£ ã¯ãããªã«ãŒãã®ã¡ãŒã«ãŒã«ãã£ãŠéçºãããŠããããããã°ãä¿®æ£ããã«ã¯ããããªã«ãŒãã®ãã©ã€ããŒãæŽæ°ããå¿ èŠããããŸãã ããããã»ãšãã©ãã¹ãŠã®ã¬ãã¹ã³ã§ãããªã«ãŒãã®ãã©ã€ããŒã®æŽæ°ãæšå¥šãããçç±ã®1ã€ã§ãã
Khronosã¯ãOpenGLã®ãã¹ãŠã®ããŒãžã§ã³ã®ãã¹ãŠã®ä»æ§ãå ¬éããŠããŸãã èå³ã®ããèªè ã¯ãããã§OpenGL 3.3ã®ä»æ§ïŒããã䜿çšããOpenGLã®ããŒãžã§ã³ã§ãïŒãèŠã€ããããšãã§ããŸãã ä»æ§ã¯ããã¹ãŠã®æ©èœã®åäœèŠåãå®å šã«ç€ºããŠããŸãã
ã³ã¢ãããã¡ã€ã«ãšå³æã¢ãŒã
以åã¯ãOpenGLã®äœ¿çšã«ã¯ã€ããã£ãšã€ãã¢ãŒãïŒåºå®æ©èœãã€ãã©ã€ã³ãšãåŒã°ããïŒã§ã®éçºãå«ãŸããŠããŸãããããã¯ã°ã©ãã£ãã¯ã¹ã®æç»ã«äœ¿ãããããã®ã§ããã OpenGLã®ã»ãšãã©ã®æ©èœã¯ã©ã€ãã©ãªã«é ãããŠãããéçºè ã¯OpenGLã«ãã£ãŠå®è¡ãããèšç®ãç解ããèªç±ããããŸããã§ããã
éçºè ã¯éçºã®æè»æ§ãèŠæ±ããåŸã«ä»æ§ãããæè»ã«ãªããéçºè ã¯ã°ã©ãã£ãã¯ã¹ã®ã¬ã³ããªã³ã°ããã»ã¹ãããã«å¶åŸ¡ã§ããããã«ãªããŸããã å³æã¢ãŒãã¯äœ¿ãããããç解ãããããã®ã§ããããéåžžã«éå¹ççã§ããã ãã®ãããä»æ§ã§ã¯ã€ããã£ãšã€ãã¢ãŒããéæšå¥šã§ããããšã瀺ãããããŒãžã§ã³3.2以éããã¹ãŠã®å€ãæ©èœãé€å€ããã³ã¢ãããã¡ã€ã«ã¢ãŒãã䜿çšããããã«ããã°ã©ããŒãåæ©ä»ãå§ããŸããã
ã³ã¢ãããã¡ã€ã«ã䜿çšããå ŽåãOpenGLã¯ææ°ã®ãã©ã¯ãã£ã¹ã®äœ¿çšã匷å¶ããŸãã å»æ¢ãããé¢æ°ã䜿çšããããšãããšãOpenGLã¯ãšã©ãŒãã¹ããŒããã¬ã³ããªã³ã°ãåæ¢ããŸãã ææ°ã®ãã©ã¯ãã£ã¹ã䜿çšããå©ç¹ã¯ãæè»æ§ãšå¹çæ§ã§ãããæ®å¿µãªããåŠç¿ãããå°é£ã«ãªããŸãã ã€ããã£ãšã€ãã¢ãŒãã¯å€§ããªæœè±¡åã§ãããOpenGLã«ãã£ãŠå®è¡ãããå®éã®äœæ¥ã®å€ããé ããããåŠç¿ã¯ç°¡åã§ããããOpenGLãå®éã«ã©ã®ããã«æ©èœããããææ¡ããã®ã¯å°é£ã§ãã ææ°ã®ã¢ãããŒãã§ã¯ãéçºè ãOpenGLãšã°ã©ãã£ã«ã«ããã°ã©ãã³ã°å šè¬ãå®å šã«ç解ããå¿ èŠããããããã¯å°ãè€éã§ããããã®ã¹ããŒã ã«ããæè»æ§ãšå¹çãåäžããŸãã
ãããããã¥ãŒããªã¢ã«ãCore-Profile OpenGLããŒãžã§ã³3.3ã«åºã¥ããŠããçç±ã§ãã
å°ãè€éã§ãããããã ãã®äŸ¡å€ããããŸãã
OpenGLã®å€ãã®æ°ããããŒãžã§ã³ãæ¢ã«ãªãªãŒã¹ãããŠããŸãïŒ4.5ã®å·çæç¹ïŒã çãã¯éåžžã«ç°¡åã§ãã ããŒãžã§ã³3.3以éã®ãã¹ãŠã®å€ãããŒãžã§ã³ã®OpenGLã¯ãåºæ¬çãªä»çµã¿ãå€æŽããªãéããããŸããŸãªäŸ¿å©ãªæ©èœãè¿œå ããŸããã æ°ããããŒãžã§ã³ã¯ãåãæäœãå®è¡ããããã®ãããã«å¹ççãŸãã¯äŸ¿å©ãªæ¹æ³ãæäŸããã ãã§ãã ãã®çµæãOpenGL 3.3ã«é©çšå¯èœãªãã¹ãŠã®æŠå¿µãšæè¡ãOpenGLã®æ°ããããŒãžã§ã³ã«é©çšã§ããŸãã
OpenGLã®ææ°ããŒãžã§ã³ã®äœ¿çšã«ã¯1ã€ã®åé¡ããããŸãã ææ°ã®ã°ã©ãã£ãã¯ã«ãŒãã®ã¿ãææ°ã®APIãå®è¡ã§ããŸãã
æ¡åŒµæ©èœ
OpenGLã®åªããæ©èœã¯ãæ¡åŒµæ©èœã®ãµããŒãã§ãã ãããªã«ãŒãã®è£œé å ãæ°ãããã¯ãããžãŸãã¯ã¬ã³ããªã³ã°ã®åºç¯ãªæ°ããæé©åãå°å ¥ããŠãããšãã«ããã®ã€ãã³ãã«é¢é£ããæ¡åŒµæ©èœããã©ã€ããŒã«è¡šç€ºãããŸãã ã¢ããªã±ãŒã·ã§ã³ãå®è¡ãããŠããããŒããŠã§ã¢ãæ¡åŒµæ©èœããµããŒãããŠããå Žåãéçºè ã¯ããã®æ¡åŒµæ©èœã«ãã£ãŠæäŸãããæ©èœã䜿çšããŠãã°ã©ãã£ãã¯ã¹ãããé«åºŠã«ããŸãã¯å¹ççã«ã¬ã³ããªã³ã°ã§ããŸãã ãããã£ãŠãã°ã©ãã£ãã¯ããã°ã©ãã¯ãOpenGLã®æ°ããããŒãžã§ã³ã§ã®å®è£ ãåŸ ããã«ããããªã«ãŒãã§ãã¯ãããžã®ãµããŒãã確èªããã ãã§ãæ°ãããã¯ãããžã䜿çšã§ããŸãã å€ãã®å Žåãäžéšã®æ¡åŒµæ©èœã®éèŠãé«ãå Žåã次ã®ããŒãžã§ã³ã®OpenGLã®äžéšãšããŠå®è£ ãããŸãã
éçºè ã¯ãæ¡åŒµæ©èœã®å©çšå¯èœæ§ã確èªããïŒãŸãã¯æ¡åŒµæ©èœã©ã€ãã©ãªã䜿çšããïŒã ãã§ãã ãã®ã¢ãããŒãã«ãããããã°ã©ãã¯èªåã®æ¡åŒµæ©èœã«åºã¥ããŠã¢ã¯ã·ã§ã³ãããå¹ççã«å®è¡ã§ããŸãã
if(GL_ARB_extension_name) { // . } else { // : -. }
OpenGL 3.3ã§ã¯ãæ¡åŒµæ©èœã¯ã»ãšãã©å¿ èŠãããŸããããå¿ èŠãªå Žåã¯å¿ èŠãªæ瀺ãæäŸãããŸãã
ã¹ããŒããã·ã³
OpenGLã¯ãæ¬è³ªçã«å€§ããªç¶æ ãã·ã³ã§ããOpenGLã®åäœãå®çŸ©ããå€æ°ã®ã»ããã§ãã OpenGLã®ç¶æ ã¯ãåºæ¬çã«OpenGLã®ã³ã³ããã¹ããæããŸãã OpenGLã䜿çšããããã»ã¹ã§ã¯ãããã€ãã®ãªãã·ã§ã³ãèšå®ããŠç¶æ ãå€æŽãããããã¡ãŒã管çããŠãããçŸåšã®ã³ã³ããã¹ãã䜿çšããŠæç»ããããšããããããŸãã
OpenGLã«ãäžè§åœ¢ã§ã¯ãªãç·ãªã©ã®æç»ãéå§ãããããšãäŒãããšãOpenGLã®æç»æ¹æ³ãå¶åŸ¡ãããªãã·ã§ã³ãå€æŽããŠãOpenGLã®ç¶æ ãå€æŽããŸãã OpenGLã®ç¶æ ãå€æŽããåŸãç·ãæç»ããããã«ãåŸç¶ã®ãã¹ãŠã®æç»é¢æ°ã¯äžè§åœ¢ã§ã¯ãªãç·ãæç»ããŸãã
OpenGLã䜿çšããªãããã³ã³ããã¹ããå€æŽããããã€ãã®ç¶æ å€æŽæ©èœãããã³OpenGLã®çŸåšã®ç¶æ ã«å¿ããŠã¢ã¯ã·ã§ã³ãå®è¡ããããã€ãã®ç¶æ å€æŽæ©èœãå®è¡ããŸãã OpenGLã倧èŠæš¡ãªã¹ããŒããã·ã³ã§ãããšããäºå®ã念é ã«çœ®ããŠããéããã»ãšãã©ã®æ©èœã¯æããã§ãã
ãªããžã§ã¯ã
OpenGLã©ã€ãã©ãªã¯Cã§èšè¿°ãããè€æ°ã®ãã©ã³ãããããŸãããããã¯äž»ã«Cã©ã€ãã©ãªã§ãã ã»ãšãã©ã®Cèšèªæ§æäœã¯é«æ°Žæºèšèªã«ç¿»èš³ãããŠããªããããOpenGLã¯å€æ°ã®æœè±¡åã䜿çšããŠéçºãããŠããŸãã ãã®ãããªæœè±¡åã®1ã€ã¯ãOpenGLã®ãªããžã§ã¯ãã·ã¹ãã ã§ãã
OpenGLã®ãªããžã§ã¯ãã¯ãOpenGLç¶æ ã®ãµãã»ãããè¡šããªãã·ã§ã³ã®ã»ããã§ãã ããšãã°ããŠã£ã³ããŠã®ã¬ã³ããªã³ã°æ§æãèšè¿°ãããªããžã§ã¯ããäœæã§ããŸãã ãµã€ãºãè²æ°ãªã©ãèšå®ã§ããŸãã ãã®ãããªãªããžã§ã¯ãã¯ãCã®ãããªæ§é ã§è¡šãããšãã§ããŸãã
struct object_name { GLfloat option1; GLuint option2; GLchar[] name; };
ããªããã£ãå
OpenGLã䜿çšããå Žåã¯ãOpenGLã§å®çŸ©ãããããªããã£ãã䜿çšããããšããå§ãããŸãã ãããŒãã䜿çšãã代ããã«ãæ·»ä»ã®GLã§èšè¿°ããŸãã intãuint charãboolãªã©ã«ã€ããŠãåãã§ãã OpenGLã¯ãäžéšã®ãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ãç°ãªãããŒã¯ã¢ãããæã€å¯èœæ§ããããããã¯ãã¹ãã©ãããã©ãŒã ãæäŸããããã«ãGLããªããã£ãã®ã¡ã¢ãªããŒã¯ã¢ãããå®çŸ©ããŸãã OpenGLããªããã£ãã䜿çšãããšãã¢ããªã±ãŒã·ã§ã³ã®å®å šãªã¯ãã¹ãã©ãããã©ãŒã æ§ãå®çŸã§ããŸãã
ãªããžã§ã¯ãã䜿çšãããã³ã«ãåºæ¬çã«æ¬¡ã®ããã«èšè¿°ããŸãã
// OpenGL struct OpenGL_Context { ... object* object_Window_Target; ... };
// GLuint objectId = 0; glGenObject(1, &objectId); // glBindObject(GL_WINDOW_TARGET, objectId); // , GL_WINDOW_TARGET glSetObjectOption(GL_WINDOW_TARGET, GL_OPTION_WINDOW_WIDTH, 800); glSetObjectOption(GL_WINDOW_TARGET, GL_OPTION_WINDOW_HEIGHT, 600); // glBindObject(GL_WINDOW_TARGET, 0);
ãã®å°ããªã³ãŒãã¯ãOpenGLã§ã®äœæ¥äžã«ããééãããã®ã§ãã æåã«ããªããžã§ã¯ããäœæãããã®ãªããžã§ã¯ããžã®ãªã³ã¯ãèå¥çªå·ïŒidïŒã®åœ¢åŒã§ä¿åããŸãã ïŒãªããžã§ã¯ãã®å®éã®ããŒã¿ã¯å®è£ ã«é ãããŠããŸãïŒã 次ã«ããªããžã§ã¯ããã³ã³ããã¹ãã®å¿ èŠãªéšåã«ã¢ã¿ããããŸãïŒäŸã®ãŠã£ã³ããŠã¿ãŒã²ãããªããžã§ã¯ãã®å Žæ㯠`GL_WINDOW_TARGET`ãšããŠæå®ãããŸãïŒã 次ã«ããŠã£ã³ããŠãªãã·ã§ã³ã®å€ãèšå®ããæåŸã«idã0ã«èšå®ããŠãªããžã§ã¯ãã解æŸããŸããèšå®ããå€ã¯åŒãç¶ããªããžã§ã¯ãã«æ ŒçŽããã objectIdãä»ããŠã¢ã¯ã»ã¹ãããªããžã§ã¯ããGL_WINDOW_TARGETã«ãã€ã³ãããŠåã³åŸ©å ã§ããŸãã
ãã®ã³ãŒãã¯ãOpenGLã®åäœã®äŸã瀺ããŠããŸãã ãã®åŸãå®éã®äŸã瀺ããŸãã
ãããã®ãªããžã§ã¯ãã®äž»ãªæ©èœã¯ãã¢ããªã±ãŒã·ã§ã³ã§å€ãã®ãªããžã§ã¯ãã宣èšãããªãã·ã§ã³ãèšå®ããOpenGLç¶æ ã䜿çšããŠæäœãéå§ãããã³ã«ããªããžã§ã¯ããåžæã®èšå®ã«ãã€ã³ãã§ããããšã§ãã ããšãã°ãããã¯ã3Dã¢ãã«ããŒã¿ãŸãã¯ãã®ã¢ãã«ã«æç»ããããã®ããããªããžã§ã¯ãã§ãã è€æ°ã®ãªããžã§ã¯ããææãããšãã¬ã³ããªã³ã°ããã»ã¹äžã«ããããç°¡åã«åãæ¿ããããšãã§ããŸãã
ããå§ããŸããã
ããã§ãä»æ§ãšã©ã€ãã©ãªã®äž¡æ¹ã«ã€ããŠOpenGLã«ã€ããŠå°ãåŠã³ãŸããã ããããã®äœæ¥ã¢ã«ãŽãªãºã ãšOpenGLã§äœ¿çšãããããã€ãã®æ©èœãåŠã³ãŸããã äœãã誀解ããŠããã£ããããªãã§ãã ããããã¹ãŠã®æé ãé ãè¿œã£ãŠèª¬æããOpenGLã®ãã¹ãŠã®è€éããç解ããã®ã«ååãªäŸãåç §ããŸãã éå§ããæºåãã§ããããOpenGLã³ã³ããã¹ãã®äœæãéå§ã§ããŸããæåã®ãŠã£ã³ããŠã¯ããã«ãããŸãã
è¿œå ã®ãªãœãŒã¹
- opengl.org ïŒå ¬åŒOpenGLãµã€ãã
- OpenGLã¬ãžã¹ããª ïŒ OpenGLã®ä»æ§ã®ãªããžããªãšãOpenGLã®ãã¹ãŠã®ããŒãžã§ã³ã®ãã¹ãŠã®æ¡åŒµæ©èœã