Making my own 3D GAME ENGINE and GAME in 48 HOURS? C++ OPENGL

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
I recently participated in the gmtk game Jam 2023 an event hosted by Mark Brown from the gmtk YouTube channel I wanted to step it up a level by not just making my own game but also my own game engine people often use an existing game engine because it provides so much for you you can just focus on making the game that you want to make but I wanted to challenge myself to create a game without using an existing game engine or framework creating a game engine is a huge effort and there's a lot of stuff that you can do I'm not going to implement everything but I'm going to make sure that it's at least kind of cool so the game Jam is just about to start and the theme is rolls reversed so the only good way to start is by first making a hello world program and making sure it compiles then to easily build my project I make a cmake file so I start with the most basic feature which is the ability to have a window so now I have one and I can move it around to draw stuff on the window I have to add opengl to the project and create an open gel context for that window I need to specify some opengl libraries to link to and add a game Loop to handle the inputs to update and then to render okay so let's talk a bit about opengl let's say you have three points that form a triangle you could store that in memory in what's called a buffer you can also write some code that's called the Shader normally written in glsl that when you send a Shader and your buffer to the GPU it will render the triangle colored in the way that you specified in the Shader this is a simplified explanation but you're going to see that I'm going to write code that sends buffers and I'm going to write shaders in glsl I create points in 3D for a triangle and put them in a buffer and send that to the GPU I rate two shaders one that just passes data through and the other one will color the triangle orange I tell cmake to properly copy these assets to the build directory to use these shaders I have to read the contents of the file and then I decided to open sea lion and make a class for shaders because I'm going to have many different shaders and I want to be able to reuse this code after reading the contents of the Shader I have to compile it then link it to a Shader program so of course the project doesn't compile and nothing works so I fix all the bugs and eventually it works I finally have a triangle it's orange and I'm super happy but now it's 252 so I've already been at this for two hours after one triangle the goal is two triangles my two triangles are orange but I don't want my entire game to be orange so I make a texture a great resource is learnopengl.com this is a site I had open on my second monitor for most of the gem so now I had to load the PNG file create a texture and send it to the Shader unfortunately it didn't immediately work so I had to spend some time solving the bug but then it worked since I had no idea what I was going to actually make as a game for the game Jam I decided to keep my code clean and make a texture class in case I have many textures now I wanted to see something moving on the screen so I decided to rotate the squad after four hours of work this felt super satisfying just for fun I decided to create a spinning Cube even though the textures are messed up it doesn't matter up to now I had specified every vertex on the mesh I wanted to load my own meshes so I added a simp to the project this Library allows me to get vertices and normals information from obj files so I can make a model in blender and then export it to obj so let's talk about what I used to make my game engine so I use C plus plus as a programming language then I use cmake to build the project I used sdl to create a window opengl and glue as a graphics API glm for math stb image to load PNG files for textures I used a Sim to load obj files for models later on I use Python and I used numpy for math opencv for image processing you might be wondering what opencv is doing here and that's a good question but you'll have to find out later let's talk about lighting and shading so let's say you have an object and you have a light source the light source is sending array to the object and the ray bounces on the object depending on how the ray bounces there's going to be an angle the smaller the angle the more direct the ray is on this object so the brighter the object should be the bigger the angle the darker the object should be what I just said was a simplification of the Fung reflection Mall which is what I'm implementing in the engine I spent around two hours on this it's mostly shared or code and I decided to add the actual light in the scene and make it rotate around the model I imported I was really satisfied with this if you look closely you will see the specular reflection it's been over eight hours since the jam started and I still have no idea what I'm going to do as a game recall that the theme is rolls reverse so I started writing some ideas in a document all my ideas were pretty bad so I just went to sleep I woke up the next day and got to work on finding an idea I wanted to find my idea as soon as possible I ended up picking golf but you play as the whole so the first thing I wanted to do was to Maul a golf ball in blender and then import it in the engine I don't have much experience with blender so this took me some time eventually I had a golf ball and it looked pretty good I really like how it looked with a specular reflection so I went back into blender and followed some tutorials to do something nice with the terrain but I ended up doing something really simple so I knew I wanted my game to have uneven terrain I wanted some hills and I wanted the ball to be able to roll down the hills but due to time constraints I decided to not make the ball bounce so this game is like mini golf so since the ball would always be on the ground I wanted to export height data from blender I wanted a height field so I would know where to place the ball on the terrain depending on the height let's talk about physics so let's say you have a ball in what direction will the ball accelerate so if you said something like this this is a good answer and you could get it from the derivative that's in one dimension in two Dimensions you would get it from the gradient it turns out you can get the gradient of an image so earlier when I said I wanted the height field as an image it's because I want the gradient of the image so I know how to accelerate the ball on this Terrain to do this I used opencv a library I've used in the past before but for some reason I wasn't getting the results I was expecting and my motivation was really low so I just decided to take a break for an hour I went to eat I went for a walk and I just needed a break back from my break I felt so much better and was much more productive I implemented the tearing data in the code and I wanted to see if the ball would actually follow the terrain so it was kind of working but there was something that wasn't quite right eventually I found the problem so blender did not account for gamma correction when I exported the height field so with that out of the way I implemented the physics using the image gradients that I got from my python script with opencv and I tried it out it needed a bit of tweaking but I was pretty happy now I wanted to simulate a hit from the putter to the golf ball this consisted of just setting an initial velocity to the ball there's maybe a bit too much friction before the ball got hit I wanted to show the player where the ball would go so I started by modeling an arrow but then decided that having points trace the path that the golf ball should take in the future would be much more interesting so I had to predict the boss position in the future I want you to look at the red Point those are supposed to be eight points tracing a path but they're all stacked together so that's a bug and a really difficult one so I opened render dock which is a graphics debugger and it told me that the position was zero zero zero at all of those eight points eventually I figured out the problem it was just because I was missing this line I now had the red points showing up in the game I could now predict the future I simulated the 30 next frames of the game and traced the path that the ball would take in the future and added points there so I also added a model of the hole and I just moved it around to make sure it worked with the terrain of course it's too big now so I'll make it smaller and then I want to add a flag I started working on the flag I opened blender and proceeded to mall the world's best flag model and then I added it to the game at this point I had something decent I had a ball rolling with some Physics I had a flag moving I was split with a choice do I make this game better by spending time trying to make it fun or do I spend the rest of my time adding Shadows the choice was easy I added Shadows let's talk about Shadows so let's say you have a light source and you have a camera this is where you view the world and you have an object in this scene so how do Shadows work the trick is to place a camera where the light is and render the scene this means that everything that this camera cannot see is a shadow so we save this render in a buffer we don't show it on the screen and we use the real camera to render the scene and use the frame buffer that we got from the first camera to darken the scene for the second camera which the player actually sees so it was about 10 pm when I started implementing the shadows and one of the key things is debugging Shadows is really hard if something goes wrong it's really hard to figure out what the problem is especially in a Time constrained game Jam so I had something not really working and it was midnight so I decided to just go to sleep the next day I got to my laptop at 8 30. the Shadows were broken the game was non-existent there was like no mechanics there was only 4 hours and 30 minutes left I started slow by making a submission page since this is a golf game I selected the sports category I relaxed by doing a banner for the game and then I actually fix the Shadows really quickly you might not think this looks good but I knew how to fix this problem and my actual bug was fixed so shortly after I had working Shadows with a couple small bugs but I knew how to fix them so I was really excited so I fixed a bunch of problems with the shadows and then I had something super satisfying look how nicely the shadow behaves on the hill let's watch that again I wanted to make the game look better so I first added anti-aliasing to the objects of the game so you can see before and then after and then I worked on smoothing the Shadows again you can see before and then after I spent a bit of time working on changing the map and now it was actually time to work on the game the way the game works is that the player moves the hole when the player is ready the player presses space and the ball rolls and hopefully it's in the hole so the player kind of has to predict where the ball will land I made it so that the ball cannot go outside of the boundaries and that the hole needs to be far enough from the starting position of the ball if now you could just put it in front and I finished the game by adding my favorite feature a super cool wind animation so let's look at some gameplay I never had the time to actually fix the controls to make them good so they're a bit painful but I'm pretty happy with how the game turned out and this game is officially called portable par so I was finished it was time to submit I was 30 minutes early everything was good until I see this in the submission rules I had to build on Windows I use Arch by the way and I wasn't going to build on windows so I was just ready to get disqualified but I talked to one of my friends and he offered to build on Windows and he built it pretty fast due to thousands of participants trying to submit their game at the same time the website handling the submissions crash and Mark Brown allowed one extra submission hour and during that time I didn't touch my game but I did have my friend ported to Windows so that Windows users could play most importantly I needed to add the Shadows I had spent all morning fixing in the banner of my game
Info
Channel: Hexel
Views: 145,089
Rating: undefined out of 5
Keywords: gamedev, gmtk, opengl, c++, cpp, learn opengl, game jam, 48 hours
Id: NYW1TKZG-58
Channel Id: undefined
Length: 14min 21sec (861 seconds)
Published: Wed Jul 26 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.