## G-Engine #4: Basic 3D Rendering

In the last G-Engine post, we got the game loop and frame “delta time” calculations working. We’ve now got a blank, empty game window - yay? Despite the unimpressive result, we’ve got a beating heart under the hood: an update loop being called at roughly 60 frames per second.

Empty windows are no fun, so my next goal is to get something - anything - rendering in the game window. Graphics are a vital and exciting part of any game, and rendering can give us vital visual feedback as we move on to implementing and debugging 3D object placement, cameras, rotations, and data loading for 3D meshes and animations.

This post will focus on rendering a single triangle on screen. Though the result is simple, we’ll cover a lot of ground towards building a 3D rendering system that will be extended and enhanced as we move forward.

## G-Engine #3: Game Loop

In my last G-Engine post, I did some setup work and finally got a basic OS window appearing that could be moved around, minimized/maximized, and closed. Good start!

In this post, we’ll do a bit more planning, and then we’ll structure our code into a high-level class (GEngine) that’ll be more conducive to building an engine than just shoving everything into the main function. We’ll also implement our “delta time” calculations, which will be critical for updating the state of our game as we move forward.

## G-Engine #2: Project Setup

The previous post introduced the G-Engine project. So here we are, ready to build a 3D game engine! This post walks through some early decisions, starting from absolutely nothing to having just an empty application window that can be moved around and closed.

This is not the most exciting end result, but there are plenty of important decisions to be made before we dig into actually writing game engine code.

## G-Engine #1: Introduction

“G-Engine” is a hobby game engine project that’s been kicking around in my head for a few years. In December 2017, I finally took the dive and started working on it! This post (and those following it) document my progress.

The idea is to build a 3D game engine in C++. But building a game engine without a game can be difficult to do, so my goal is to use the engine to recreate a video game: Gabriel Knight 3: Blood of the Sacred, Blood of the Damned (or GK3 for short), a 1999 release from Sierra Studios!

If that sounds like an odd choice, read on to learn why I’m quite excited to work on something like this!

## Insert, Push, and Emplace

Standard C++ containers (or collections) are essential tools. Some, like vector, queue, deque, and stack are list-like: elements are accessed by position. Others, such as map or set, are more associative in nature: elements are accessed by a key.

To add an object to a vector, you can call insert or push_back. Stacks and queues both allow you to add elements using push. Map allows insertions with insert or using the [ ] operator.

In C++11 and beyond, all these containers have new functions that seem to behave similarly to the above methods: emplace, emplace_back, and emplace_front.

Which begs the question: what’s the difference between these different methods of adding items to collections?

## When to Inherit from MonoBehaviour

When you create a new C# class in Unity, it automatically inherits from the MonoBehaviour class, which is Unity’s base class for components. In Unity, you tend to create a lot of components, but it’s important to keep in mind that you don’t have to.

When I was new to Unity, I thought everything should inherit from MonoBehaviour - that’s just how you work in Unity! Some of my students have also had this misconception. In fact, there are often scenarios where it makes more sense to not inherit at all, or to inherit from another base class. This post explains situations where it makes sense to use MonoBehaviour, and some cases where you’d be better off without it.