<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Beau</title>
    <description>The latest articles on DEV Community by Beau (@hunterfehlan).</description>
    <link>https://dev.to/hunterfehlan</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F488229%2F1e60d4eb-eec7-4245-9ba4-af80486d0c41.jpg</url>
      <title>DEV Community: Beau</title>
      <link>https://dev.to/hunterfehlan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hunterfehlan"/>
    <language>en</language>
    <item>
      <title>Being too ambitious</title>
      <dc:creator>Beau</dc:creator>
      <pubDate>Wed, 24 Feb 2021 19:42:38 +0000</pubDate>
      <link>https://dev.to/hunterfehlan/being-too-ambitious-4a7d</link>
      <guid>https://dev.to/hunterfehlan/being-too-ambitious-4a7d</guid>
      <description>&lt;p&gt;I willing to bet any developer who's been developing for longer than a few minutes has experienced something like this cycle:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Come up with new project idea&lt;/li&gt;
&lt;li&gt;Get really excited about new project&lt;/li&gt;
&lt;li&gt;Start working immediately, little to no planning&lt;/li&gt;
&lt;li&gt;Work for a few days or weeks and get a lot done&lt;/li&gt;
&lt;li&gt;Realize scope of project way too late&lt;/li&gt;
&lt;li&gt;Try to put too many features in to meet expectations&lt;/li&gt;
&lt;li&gt;Burn out, start to work much less&lt;/li&gt;
&lt;li&gt;Go back to step 1&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It's hard to avoid sometimes, a new project can be very exciting and you want to start making progress immediately. The problem is that sometimes it's difficult to realize how involved a project is going to be until you're already into it.&lt;/p&gt;

&lt;p&gt;This happened to me recently with my graphics library, Nyx/Baphomet/Eos/Nyx. You'll notice there are 3 names there, 1 of them repeated because I went back to it, and that's because I started and restarted the project 4 separate times because of this cycle. Each time I'd start over I thought I'd solved the issue of why feature X was just not good enough, and I'd jump right back in and do the same thing again. &lt;/p&gt;

&lt;p&gt;This last time, I decided to step back and examine &lt;em&gt;why&lt;/em&gt; exactly I was failing each time. It's not that my code wasn't working, it did, and it worked well, I just always felt something was wrong with it once I got any substantial amount of functionality in. One time I even made it as far as making a basic Minesweeper clone to test it out, and still something felt off. I finally realized that the issue was the &lt;em&gt;scope&lt;/em&gt; of the project, how much I wanted it to be able to do, and how calling it a "graphics library" wasn't even accurate at that point.&lt;/p&gt;

&lt;p&gt;I wanted whatever-you-want-to-call-it-this-time to be capable of these things in no particular order:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;OpenGL abstraction&lt;/li&gt;
&lt;li&gt;Drawing primitives--points, lines, triangles, rectangles, ovals, etc&lt;/li&gt;
&lt;li&gt;Drawing textures--static and animated&lt;/li&gt;
&lt;li&gt;Window management&lt;/li&gt;
&lt;li&gt;Keyboard/mouse/gamepad input--extra game-like features for these too&lt;/li&gt;
&lt;li&gt;Sound/music&lt;/li&gt;
&lt;li&gt;Particle systems&lt;/li&gt;
&lt;li&gt;Timers&lt;/li&gt;
&lt;li&gt;Tweening&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Probably other things I'm forgetting...&lt;/p&gt;

&lt;p&gt;Point is, it wasn't feasible. I'm a single person who hasn't even graduated college yet (almost, 2 more months), much less worked on a project with a scope that large. Each time I'd make it as far as managing the window, abstracting parts of OpenGL--though never as much as I wanted--events, timers, drawing primitives, sometimes textures, and then...nothing. I'd look at what I made and hate it. I'd think about how it's missing a specific feature, or you couldn't initialize a type in a convenient way, or whatever, and not know what to do.&lt;/p&gt;

&lt;p&gt;Each time I restarted I'd use some of the code I wrote from the previous attempt. I figured that for some parts there was no reason to completely rewrite it--things like a utility file to get random numbers, or the timer class that didn't have any real dependencies. These things were portable enough that I felt like I could reuse them.&lt;/p&gt;

&lt;p&gt;As you can tell from the list, calling it a "graphics library" is a bit misleading. Yes, it was definitely capable of that, but in all reality it had a graphics library buried under a lot of game development features. If someone wants to make a game, they're probably going to just use Unity or GameMaker or something already existing that's more mature, has examples, and can do a lot more. I was struggling to see the forest for the trees, and getting blinded by my own goals somehow at the same time.&lt;/p&gt;

&lt;p&gt;Rather than trying again and hoping I somehow fix the problem, I'm going to go for a different approach. This time, I'll be focusing primarily on only a single goal in the list: abstracting OpenGL. While working on this project, I actually considered using Python instead of C++ because of a really nice library I found called &lt;a href="https://github.com/moderngl/moderngl"&gt;moderngl&lt;/a&gt;. It abstracts the low level OpenGL concepts into much nicer to use pieces, and I realized quickly how useful something like that could be in C++. One of the big questions I kept asking myself while developing was "how can I implement feature X if I don't really want to use it myself but someone else might. How can I plan for that?" The answer is that realistically, by yourself, you can't.&lt;/p&gt;

&lt;p&gt;And that's okay! Trying to please everyone isn't possible, you'll eventually have to make decisions and live with them, and if whatever you make isn't a good fit for another developer, then they'll just have to move on. Unfortunately that's just life.&lt;/p&gt;

&lt;p&gt;Starting today I'll be working on a new project, hlGL - High Level OpenGL. The goal will be to create a library with a similar feel to moderngl, but in C++. I can still use some of the code from the previous graphics library/game engine/whatever as well.&lt;/p&gt;

&lt;p&gt;Even better, the original goal isn't out of the question, it'll just be more than a single piece. hlGL should be useable as a dependency on its own to make something higher level still, and that can be a goal for the future. For now, I need to keep my goals lower so they're attainable.&lt;/p&gt;

</description>
      <category>gamedev</category>
      <category>cpp</category>
      <category>opengl</category>
    </item>
    <item>
      <title>Nyx: How to make a game loop</title>
      <dc:creator>Beau</dc:creator>
      <pubDate>Wed, 20 Jan 2021 20:29:07 +0000</pubDate>
      <link>https://dev.to/hunterfehlan/nyx-how-to-make-a-game-loop-44lf</link>
      <guid>https://dev.to/hunterfehlan/nyx-how-to-make-a-game-loop-44lf</guid>
      <description>&lt;h3&gt;
  
  
  Design blog!
&lt;/h3&gt;

&lt;p&gt;Whenever you create a program, you had to do some level of designing when you first started. This could have been small, like in the case of a throwaway script, or it could be much larger, like in the case of designing an entire library. This post is going to be looking into the design of Nyx, namely where the previous attempt, Aurora, failed, and what I've done with Nyx to--in my opinion at least--fix it.&lt;/p&gt;

&lt;h3&gt;
  
  
  SDL style
&lt;/h3&gt;

&lt;p&gt;Aurora had a major flaw in that it put zero restriction on the structure of the program that was written. This was actually something I considered a feature of the library at the time: you could write your program however you want, and you'd insert the graphical stuff wherever it happened to need to go and be done with it. Unfortunately, in practice, this led to some pretty awkward things to deal with.&lt;/p&gt;

&lt;p&gt;A lot of this stemmed from me unintentionally pulling from what I'd used in the past. The main library I used whenever I needed graphics was SDL2. SDL is great, I talked about that in the "libraries" article, but it has a lot of boilerplate code you are effectively &lt;em&gt;required&lt;/em&gt; to put in place. For example, here's just opening a window in SDL2 (minus some initialization code):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="cp"&gt;#include &amp;lt;SDL2/SDL.h&amp;gt;
&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;[])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="cm"&gt;/* initialize the window and renderer */&lt;/span&gt;

  &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;running&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;SDL_Event&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;SDL_PollEvent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;type&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;SDL_QUIT&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;running&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="cm"&gt;/* update game state */&lt;/span&gt;

    &lt;span class="n"&gt;SDL_RenderClear&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="cm"&gt;/* ... */&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="cm"&gt;/* draw stuff */&lt;/span&gt;

    &lt;span class="n"&gt;SDL_RenderPresent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="cm"&gt;/* ... */&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;running&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="n"&gt;SDL_Quit&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;SDL is first and foremost a C library, and you can see that in the coding style. Everything is procedural, and it's up to you to call everything in the right order. Some things can be mixed around, but not much.&lt;/p&gt;

&lt;p&gt;Now here's that same thing in Aurora:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="cp"&gt;#include "aurora/aurora.h"
&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;[])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;auto&lt;/span&gt; &lt;span class="n"&gt;engine&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;aurora&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;Engine&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="s"&gt;"Example"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;800&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;600&lt;/span&gt;&lt;span class="p"&gt;}});&lt;/span&gt;

  &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;engine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;update&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="cm"&gt;/* update game state */&lt;/span&gt;

    &lt;span class="n"&gt;engine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;window&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;clear&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="cm"&gt;/* draw stuff */&lt;/span&gt;

    &lt;span class="n"&gt;engine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;window&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;flip&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;engine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;is_running&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sure, it's shorter, but you can see the parallels between the two snippets of code. Open your window, then start your game loop. Within the game loop, run your events through, clear the window, draw, then flip. Check your exit condition, and either stop or continue. There's nothing wrong with this loop, and in fact basically every game library in existence--no I did not fact check this--likely works in a similar way. Why, though, is it up to the user to code that in? If it's the same every time, you just have boilerplate, and that's not reasonable.&lt;/p&gt;

&lt;h3&gt;
  
  
  LÖVE
&lt;/h3&gt;

&lt;p&gt;Some libraries don't work this way, and take a more structured approach. LÖVE is a great example of this--being still pretty low level in terms of what the programmer is responsible for, but taking that boilerplate part of the code out of the equation. To make an application in LÖVE, your code will look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight lua"&gt;&lt;code&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nc"&gt;love&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="c1"&gt;-- initialization code&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nc"&gt;love&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="c1"&gt;-- update game state&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nc"&gt;love&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;draw&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="c1"&gt;-- draw stuff&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are the 3 main callback functions in a LÖVE program, and they allow you to do quite a lot. They are called in a loop similar to this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;love.load()
while game is running:
  love.update()
  love.draw()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The callback way of doing things keeps the focus on the content of the functions, rather than how they're structured in the code. Even better, it doesn't need to be rewritten every time, &lt;em&gt;and&lt;/em&gt; and the library developers don't need to add in some new thing to update backend structures that the user has to call: they'll just add it to their existing game loop. This is less cognitive load on the developer, and requires less knowledge of the backend of the library--something that arguably you shouldn't need to know about especially for simple programs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Nyx
&lt;/h3&gt;

&lt;p&gt;I drew inspiration from LÖVE heavily for how I implemented the game loop--taking into consideration, of course, that C++ is a very different language with a different way of making programs. Here's that same example as above where a window is opened and simply cleared and flipped until the user closes it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="cp"&gt;#include "nyx.hpp"
&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Example&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;nyx&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;App&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="nl"&gt;public:&lt;/span&gt;
  &lt;span class="n"&gt;Example&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nyx&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;AppCfg&lt;/span&gt; &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;cfg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;nyx&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;App&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cfg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;
  &lt;span class="o"&gt;~&lt;/span&gt;&lt;span class="n"&gt;Example&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;delta&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
    &lt;span class="cm"&gt;/* update game state */&lt;/span&gt; 
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;draw&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;clear_window&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;[])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;Example&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="s"&gt;"Example"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;800&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;600&lt;/span&gt;&lt;span class="p"&gt;}}).&lt;/span&gt;&lt;span class="n"&gt;mainloop&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Admittedly, there's a lot going on here, but that's mostly because of C++ boilerplate, not because of the library itself. To create an application in Nyx, the &lt;code&gt;App&lt;/code&gt; class is overridden, and at least the &lt;code&gt;void draw()&lt;/code&gt; function must be implemented. The &lt;code&gt;void update(double time, double delta)&lt;/code&gt; function is optional if you don't need it for some reason, but I showed it here to show that it exists. &lt;code&gt;mainloop&lt;/code&gt; does a lot behind the scenes, but effectively boils down to doing event handling and assorted update functions, calling &lt;em&gt;your&lt;/em&gt; update function, drawing the screen, then presenting it automatically. You also inherit some functions like &lt;code&gt;clear_window&lt;/code&gt; than can be used in your draw loop or elsewhere that are needed for full functionality. This removes the need for the user to have to manually structure their program, as a structure is enforced this way. &lt;/p&gt;

&lt;p&gt;You may argue that the way I've done this adds in its own boilerplate code, and to some degree I'd agree with you. Overriding a class in C++ isn't that short, and it is somewhat annoying that there's no way to really get around this without doing some GL3W style function callbacks. Working a few different ideas, I think this is the best balance between solving the issue I described with manually creating a game loop, and also having it still be relatively convenient to use. In a larger program, the extra code associated with this method is negligible.&lt;/p&gt;

&lt;h3&gt;
  
  
  Final remarks
&lt;/h3&gt;

&lt;p&gt;Lack of structure plagued Aurora from all sides, but I'm not allowing those same mistakes to happen again with Nyx. I want an easy to grok, understandable structure in all programs written with the library--allowing me to add as much extra functionality as I want behind the scenes. In another post I'll go into what those behind the scenes things are. Soon I'll make a post about "stickies", which are mostly meant for debugging but have been incredibly valuable for development.&lt;/p&gt;

&lt;p&gt;Nyx is coming along quite well--primitives are almost implemented--and then I'll be starting on implementing more and more drawing functionality. Stay tuned!&lt;/p&gt;

</description>
      <category>opengl</category>
      <category>cpp</category>
      <category>gamedev</category>
    </item>
    <item>
      <title>Nyx: 3rd party libraries</title>
      <dc:creator>Beau</dc:creator>
      <pubDate>Wed, 13 Jan 2021 18:35:07 +0000</pubDate>
      <link>https://dev.to/hunterfehlan/nyx-3rd-party-libraries-4721</link>
      <guid>https://dev.to/hunterfehlan/nyx-3rd-party-libraries-4721</guid>
      <description>&lt;h3&gt;
  
  
  Don't reinvent the wheel
&lt;/h3&gt;

&lt;p&gt;This is already a somewhat hypocritical statement as I've already mentioned that there are many existing libraries that are great for graphics in C++, but it really is true in most cases.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Do not reinvent the wheel, you will likely do it worse than those who came before you.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Obviously I have some level of hubris here in that I think I can do better than what's out there, but that's okay! What I'm referring to here is that it's okay to take advantage of the work of others (with permission, of course), especially when you're doing something as complicated as a whole framework. There are many things that I do not want to write myself, and I have employed libraries where appropriate. &lt;/p&gt;

&lt;h3&gt;
  
  
  SDL2 [&lt;a href="https://www.libsdl.org/"&gt;link&lt;/a&gt;]
&lt;/h3&gt;

&lt;p&gt;As much as I was talking down to SDL2, it actually makes a great windowing library. I won't use anything out of it that actually draws things onto the screen, but it's great for creating a window and getting an OpenGL context ready. The event handling is also pretty good--it's a very C-ish idiom, but polling events to me is way nicer than using callbacks--and it'll even enable me to add gamepad support in the future if I really want to.&lt;/p&gt;

&lt;h3&gt;
  
  
  Glad [&lt;a href="https://github.com/Dav1dde/glad"&gt;link&lt;/a&gt;]
&lt;/h3&gt;

&lt;p&gt;You have to have an OpenGL context open to do anything, and that's where Glad comes in. For those unaware, OpenGL has two major profiles, compatibility and core. The compatibility profile is deprecated &lt;em&gt;since 2008/9 and should not be used&lt;/em&gt;, but is there so old software doesn't break. Unfortunately, when we make an OpenGL context, it only actually loads compatibility functions, so we need an OpenGL loader to load the new things for us. That's where Glad comes in, it loads those functions after we've created our context. There are a lot of loaders, none of them are really good or bad, they just sort of &lt;em&gt;are&lt;/em&gt;. The one thing I don't like about Glad is that I don't know how to use it with CMake, but I wrote a script to update dependencies like Glad that don't work with the rest of my system.&lt;/p&gt;

&lt;h3&gt;
  
  
  ImGui [&lt;a href="https://github.com/ocornut/imgui"&gt;link&lt;/a&gt;]
&lt;/h3&gt;

&lt;p&gt;ImGui is definitely more a nicety than a necessity, but it'll allow for adding in text onto the screen before I'm able to draw it with the library. It's great for quick tests if you want to be able to interact with what you've made, and I'd highly recommend it.&lt;/p&gt;

&lt;h3&gt;
  
  
  {fmt} [&lt;a href="https://github.com/fmtlib/fmt"&gt;link&lt;/a&gt;]
&lt;/h3&gt;

&lt;p&gt;fmt is the definition of extraneous, but it's &lt;em&gt;so&lt;/em&gt; nice that I can't not use it. It's an I/O library that is actually an implementation of things that are going to be added into C++20. C++20 is a bit too new for me to feel comfortable putting my project on it yet, but using fmt for now is much nicer than the fresh hell that is iostream.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Isn't this nice?&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  stduuid [&lt;a href="https://github.com/mariusbancila/stduuid"&gt;link&lt;/a&gt;]
&lt;/h3&gt;

&lt;p&gt;I use UUIDs on the timers, so I needed a way to generate them. I could do it myself--but we're trying to not reinvent the whole wheel only some it.&lt;/p&gt;

&lt;h3&gt;
  
  
  stb [&lt;a href="https://github.com/nothings/stb"&gt;link&lt;/a&gt;]
&lt;/h3&gt;

&lt;p&gt;The stb headers are great, they're single file units that each do some specific thing--in this case I use the ones for reading and writing images to disk. Great libraries, never done me wrong, I recommend them.&lt;/p&gt;

&lt;h3&gt;
  
  
  glm [&lt;a href="https://github.com/g-truc/glm"&gt;link&lt;/a&gt;]
&lt;/h3&gt;

&lt;p&gt;You need matrices to deal with anything in code OpenGL, and I'm not going to write that library myself. glm is a mature library for dealing with all the matrices and vectors that you have to use, including building projection matrices, and they are also very easily upload-able into vertex buffers. Neat!&lt;/p&gt;

&lt;h3&gt;
  
  
  Wrap up
&lt;/h3&gt;

&lt;p&gt;That's all the 3rd party stuff that Nyx is using for now. If I add more libraries in the future I'll add them here.&lt;/p&gt;

</description>
      <category>opengl</category>
      <category>cpp</category>
      <category>gamedev</category>
    </item>
    <item>
      <title>Nyx: A Graphics Library for C++</title>
      <dc:creator>Beau</dc:creator>
      <pubDate>Wed, 13 Jan 2021 18:10:35 +0000</pubDate>
      <link>https://dev.to/hunterfehlan/nyx-a-graphics-library-for-c-dfa</link>
      <guid>https://dev.to/hunterfehlan/nyx-a-graphics-library-for-c-dfa</guid>
      <description>&lt;h3&gt;
  
  
  Ugh, how many of these do we need?
&lt;/h3&gt;

&lt;p&gt;I'm tired of using the same old graphics libraries in C++. I want something simple, something as easy to use as LÖVE or Pyglet. I could use these in their respective languages but I quite honestly just like the speed of C++. Also, modern C++ isn't nearly as painful to use as I think some of us may have learned in school (aka doing C with classes). &lt;/p&gt;

&lt;p&gt;A lot of the existing libraries that are out there aren't really C++ at all, but simply C. These are fine if you're coding in C, but they tend to be unnatural and clunky when it comes to C++. A good example would be SDL2: totally functional, but dated naming conventions and a less than stellar build process (I just want CMake support!).&lt;/p&gt;

&lt;p&gt;Some of those libraries are also pretty feature incomplete, in my opinion. Ragging on SDL2 again, why are basic primitives not really a thing it supports? To be fair, primitives are mostly used in the early stages of the development process, not in a final product, but why not have them available anyway? It doesn't make much sense to me. Yes, you can use SDL2_gfx, but I feel like it should be something the base library has included.&lt;/p&gt;

&lt;p&gt;That's why I've decided to start my own graphics library instead, taking advantage of everything I can to make it a one-stop-shop for your graphics (and some game development) needs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Okay but like have you considered X?
&lt;/h3&gt;

&lt;p&gt;Probably! I've tried out many different things over the years, none of them come even close to the simplicity of libraries you find in higher level languages. I don't see why they can't, and I'm tired of waiting for someone to make it for me. Plus, this is just a great project to put on my resume given that I do have an actual interest in engine development as a career.&lt;/p&gt;

&lt;p&gt;That said, I haven't tried everything, if you really would like me to check out some other library, I'll probably at least take a cursory glance at its git repo.&lt;/p&gt;

&lt;h3&gt;
  
  
  Introducing: Nyx
&lt;/h3&gt;

&lt;p&gt;Nyx is the name of a graphics library that I'm currently developing. There isn't any particular inspiration behind the name, it's just really short, which makes it nice for a namespace, and mythology is cool.&lt;/p&gt;

&lt;p&gt;For now, it's in a private repo until I think it's at least useable for &lt;em&gt;something&lt;/em&gt;. As of now, it's quite literally useless as it basically just opens a screen and can draw an FPS counter and memory usage indicator on the top. This isn't nothing, and there's actually quite a bit of code to handle some events and everything as well, but I'll make another post for those.&lt;/p&gt;

&lt;p&gt;This is actually a rewrite of a project I had been working on for a while--that's why there's that seemingly random functionality in there already, it's just copied over. I have a scrapped project called Aurora that had the exact same goal, but I hit a wall when I realized I had structured it pretty poorly. The way the library was set up, certain things were hard to access, or all had to go through a central object I called "Engine". This was all well and good but added a lot of unnecessary noise to the code. Then, I remembered how LÖVE does it. I'll discuss what happened there in the next article.&lt;/p&gt;

&lt;p&gt;Anyway, this was just a quick intro post. I'm hoping to document the process as I go along, don't expect 100% consistency with me writing these, but it shouldn't be terribly slow either. I tend to try and get a little something done on it every day, though I likely won't write an article every day, that feels a bit excessive. If somehow this gets popular, I'll consider doing live coding streams, that's always seemed like a fun idea to me, though I'm not sure how exciting it would be to watch me do it. :)&lt;/p&gt;

</description>
      <category>opengl</category>
      <category>cpp</category>
      <category>gamedev</category>
    </item>
  </channel>
</rss>
