{"id":26269,"date":"2015-04-02T07:40:52","date_gmt":"2015-04-02T12:40:52","guid":{"rendered":"http:\/\/www.shamusyoung.com\/twentysidedtale\/?p=26269"},"modified":"2015-04-02T07:40:52","modified_gmt":"2015-04-02T12:40:52","slug":"the-strange-evolution-of-opengl-part-1","status":"publish","type":"post","link":"https:\/\/www.shamusyoung.com\/twentysidedtale\/?p=26269","title":{"rendered":"The Strange Evolution of OpenGL Part 1"},"content":{"rendered":"<p>Let&#8217;s talk about OpenGL. No wait. Don&#8217;t hit the back button yet! <em>Let&#8217;s talk about OpenGL in a way that non-coders can hopefully follow.<\/em> I&#8217;ll even sprinkle some screenshots of my most recent OpenGL project through the article to break up the scary walls of text. It&#8217;ll be easy and maybe even fun<span class='snote' title='1'>I&#8217;ve found that people&#8217;s definitions of &#8220;fun&#8221; are surprisingly flexible!<\/span>.<\/p>\n<p>OpenGL stands for Open Graphics Library. It was originally devised in 1991. When it comes to talking to your graphics card, OpenGL is one of only two ways to get the job done. If you want to render some polygons, you have to use either Direct X or OpenGL<span class='snote' title='2'>Well, a third option would be to render WITHOUT using the graphics card. This will &#8211; no exaggeration &#8211; be thousands of times slower. So <a href=\"?p=890\" title=\"Outcast: Something Different\">it&#8217;s been years since the last time<\/a> I  saw a software-rendered game.<\/span>. Everything else &#8211; Unreal Engine, Unity, or any other game Engine &#8211; has to go through either DirectX or OpenGL if it wants to make some graphics<span class='snote' title='3'>Assuming you&#8217;re working on a desktop computer. Things are a little different in console world.<\/span>. <\/p>\n<p><!--more-->OpenGL pre-dates graphics cards. At least, it pre-dates cards as we understand them today. There were industrial-grade cards in 1991, used by render farms and CAD stations. I don&#8217;t know enough about that hardware to know how OpenGL worked at the time, so let&#8217;s just ignore all of that stuff while I make broad, hand-wavy gestures. The point is that the world of consumer-grade graphics acceleration sort of grew up around OpenGL, and over time it adapted to give us programmers a way to talk to all that fancy graphics hardware. OpenGL also pre-dates the widespread adoption of C++ as a programming language. Also, it was devised long before multi-threading was part of normal development. This means that OpenGL has a lot of things about it that just don&#8217;t make a lot of sense to game developers in 2015. It&#8217;s a system that uses crusty old C code, it doesn&#8217;t play well with multi-threaded approaches, and it&#8217;s filled with legacy systems that nobody is supposed to use anymore. <\/p>\n<p><table width='800' class=\"\" cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/bughunt0.jpg' class='insetimage' width='800' alt='This is my game &#8220;World of Stone Pillars in a Blue Void With No GamePlay&#8221;. Coming soon to Kickstarter!' title='This is my game &#8220;World of Stone Pillars in a Blue Void With No GamePlay&#8221;. Coming soon to Kickstarter!'\/><\/td><\/tr><tr><td class='insetcaption'>This is my game &#8220;World of Stone Pillars in a Blue Void With No GamePlay&#8221;. Coming soon to Kickstarter!<\/td><\/tr><\/table><\/p>\n<p>The full story of the rise and fall of OpenGL is much too long to recount here. <a href=\"http:\/\/programmers.stackexchange.com\/questions\/60544\/why-do-game-developers-prefer-windows\/88055#88055\" title=\"Why Do Game Developers Prefer Windows\">This is the fullest version of events<\/a> as I&#8217;ve been able to find, tucked into the middle of a very long thread on StackExchange. Imagine a world where the only coherent account of the rise of the Ford motor company was from a single user in an <tt>r\/automobiles<\/tt> subreddit. That&#8217;s what this is like. I&#8217;m not even going to try and outline it here. It&#8217;s a mad story that involves several hardware companies, Microsoft, a committee, and a lot of bad decisions on the part of everyone. The most important player in that drama was the committee, which is called the ARB.<\/p>\n<p>The point is: OpenGL has changed quite a bit over the years. As graphics technology changed, the ARB would bolt some new functionality onto the Frankenstein monster of OpenGL and it would shamble onward. That&#8217;s fine, inasmuch as adding functionality is what they&#8217;re supposed to be doing. But now, 23 years after the release of OpenGL, things are a mess. There are now five ways to do everything, and the four most obvious and straightforward ways are bad and wrong and slow and people will yell at you if they catch you doing them.<\/p>\n<p>This is a shame, because like most programmers I&#8217;m really attracted to &#8220;obvious and straightforward&#8221; solutions. In the old days, you could sit down and write a dozen or so lines of code that would put some polygons up on the screen. <\/p>\n<p>The old way:<\/p>\n<ol>\n<li>Set up your OpenGL context so you can draw stuff.\n<li>Position the camera.\n<li>Specify a few vertices to make a triangle.\n<li>If you&#8217;re feeling creative, you could maybe color them or put a texture map in there, but whatever.\n<\/ol>\n<p>The new way:<\/p>\n<ol>\n<li>Set up your OpenGL context so you can draw stuff.\n<li>You&#8217;ll need a vertex shader. That&#8217;s another whole program witten in GLSL, which looks a bit like C++ but is actually its own language.\n<li>You&#8217;ll also need a fragment shader. Yes, another program.\n<li>You&#8217;ll need to compile both shaders. That is, your program runs some code to turn some other code into a program. It&#8217;s very meta.\n<li>You&#8217;ll need to build an interface so your game can talk to the shaders you just wrote.\n<li>You&#8217;ll need to gather up your vertices and pack them into a vertex buffer, along with any data they might need.\n<li>Explain the format of your vertex data to OpenGL and store that data on the GPU<span class='snote' title='4'>The graphics card. But you knew that.<\/span>.\n<li>Position the camera.\n<li>Draw those triangles you put together a couple of steps ago.\n<li>If you&#8217;re feeling creative, you can re-write your shaders and their interface to support some color or texture. Hope you planned ahead!\n<\/ol>\n<p>This list kind of undersells the drastic spike in work required to get something to appear on screen. Every one of these new steps is more difficult on both a conceptual (What is happening here and why do I need to do this?) and programmatic (How do I do this?) sense. If you have any experience with modern gaming engines you&#8217;re probably used to ignoring all of this. You&#8217;ve most likely got a game engine between you and the fussy details. These steps are difficult to wrap your head around, but they only need to be done once and most people don&#8217;t do it at all.<\/p>\n<p><table width='800' class=\"\" cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/bughunt1.jpg' class='insetimage' width='800' alt='Colored lighting! Let&#8217;s party like it&#8217;s 1999!' title='Colored lighting! Let&#8217;s party like it&#8217;s 1999!'\/><\/td><\/tr><tr><td class='insetcaption'>Colored lighting! Let&#8217;s party like it&#8217;s 1999!<\/td><\/tr><\/table><\/p>\n<p>Note that I&#8217;m not really faulting OpenGL for this rise in complexity. The way things are done today is unavoidably difficult. You&#8217;ve got your multi-core computer there running a game, and that computer is talking to another fabulously sophisticated computer (the GPU) with hundreds or thousands of cores. Each computer has its own memory and its own native processor language, and as a programmer it&#8217;s your job to get these two systems to talk to each other long enough and well enough to make some polygons happen. <\/p>\n<p>So that&#8217;s what this series is going to be about: How OpenGL used to work, how it works now, and what I think we&#8217;ve lost in the transition.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s talk about OpenGL. No wait. Don&#8217;t hit the back button yet! Let&#8217;s talk about OpenGL in a way that non-coders can hopefully follow. I&#8217;ll even sprinkle some screenshots of my most recent OpenGL project through the article to break up the scary walls of text. It&#8217;ll be easy and maybe even funI&#8217;ve found that [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[66],"tags":[],"class_list":["post-26269","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/26269","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=26269"}],"version-history":[{"count":0,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/26269\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=26269"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=26269"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=26269"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}