Advertisement

Game Programming 101 with C++

Started by March 04, 2019 07:47 PM
12 comments, last by 8Observer8 5 years, 6 months ago

Hello! I am a bit new to this, so pardon my etiquette. I am a student who is currently learning the basics of programming with C++ and I intend on expanding my knowledge further outside what my classes will be teaching me as I make my way towards an Engineering degree. I would like to throw my hat in on my spare time to learn to program 2D games that are based in C++, but I do not know where exactly to start doing so, particularly in the area of what software I need and can get to turn the limited black-background-white-text output from "Windows Visual Studio 2017" to generating the images/menus/sounds/visuals/controller-input needed to at least have the basic tools required to make a game.

So, long story short: what software do I need to start programming a video game? Where can I get it? Any advice, tutorial links, or input would be much appreciated! Thanks!

2 hours ago, KPK said:

Hello! I am a bit new to this, so pardon my etiquette. I am a student who is currently learning the basics of programming with C++ and I intend on expanding my knowledge further outside what my classes will be teaching me as I make my way towards an Engineering degree. I would like to throw my hat in on my spare time to learn to program 2D games that are based in C++, but I do not know where exactly to start doing so, particularly in the area of what software I need and can get to turn the limited black-background-white-text output from "Windows Visual Studio 2017" to generating the images/menus/sounds/visuals/controller-input needed to at least have the basic tools required to make a game.

So, long story short: what software do I need to start programming a video game? Where can I get it? Any advice, tutorial links, or input would be much appreciated! Thanks!

If you're looking at working with C++ and making 2D games then I would suggest SDL2 or SFML (my personal preference). :)

For SDL2

http://libsdl.org/download-2.0.php

http://lazyfoo.net/tutorials/SDL/

For SFML

https://www.sfml-dev.org/

https://www.sfml-dev.org/tutorials/2.5/

This is also a great book on C++: https://www.amazon.ca/Primer-5th-Stanley-B-Lippman/dp/0321714113 of course you'll want to update your knowledge the current standard and so forth.

You will be able to deal with graphics, sound, and input with either SDL2 or SFML.

Beyond that, if you have any issues then come back and post your problem with code and any errors you're receiving and someone will be able to help you out. :) Good luck!

Programmer and 3D Artist

Advertisement
3 hours ago, KPK said:

I would like to throw my hat in on my spare time to learn to program 2D games that are based in C++

Do you want to use game libraries, frameworks and game engines? Or do you want to start from scratch using OpenGL or DirectX? I started with deprecated/legacy OpenGL 1. I like this short tutorial that use OpenGL 1: C++ 2D Pong Game If you know how to draw squire you can practice with writing simple 2D games like: Snake, Arkanoid, Tetris and so on. Good article: Make small Games It is not a spam message. It is just good articles.

Next step is to start learning modern/shader OpenGL 3 or OpenGL ES 3.0. This is a text tutorial: https://learnopengl.com/ This is a video tutorial: Advanced C++/Graphics Tutorial You can find another great material for example ThinMatrix Channel. He uses Java + shader OpenGL and it is 3D but it is not difficult to rewrite code to C++, C#, WebGL/JavaScript (or TypeScript) and so on. A lot of things are very similar in computer graphics independ on what it is: OpenGL (GLSL), WebGL (GLSL), C++, C#, Java, Direct3D (HLSL). Choose something and use it everyday.

You can rewrite your small games from deprecated/legacy OpenGL 1 to modern/shader OpenGL 3 to improve them.

I like study shader OpenGL because it give me knowledges about how computer graphics works on low level. I want to understand in practice how to use Linear Algebra, Shader Math, Game Physics. For example, I can you this knowledges and skills to write shaders using game engines like Unity because HLSL and GLSL are very similar.

6 hours ago, KPK said:

Hello! I am a bit new to this, so pardon my etiquette. I am a student who is currently learning the basics of programming with C++ and I intend on expanding my knowledge further outside what my classes will be teaching me as I make my way towards an Engineering degree. I would like to throw my hat in on my spare time to learn to program 2D games that are based in C++, but I do not know where exactly to start doing so, particularly in the area of what software I need and can get to turn the limited black-background-white-text output from "Windows Visual Studio 2017" to generating the images/menus/sounds/visuals/controller-input needed to at least have the basic tools required to make a game.

So, long story short: what software do I need to start programming a video game? Where can I get it? Any advice, tutorial links, or input would be much appreciated! Thanks!

Use GLFW library in Visual Studio to set up an OpenGL window (it also reads keyboard and controller input). Then, figure out how to draw a simple quad with OpenGL. Use lodepng library to load a texture and put it on the quad. Now you have the basics of what you need to make a 2D game, graphics-wise. For sound, use sndfile library to load files into audio buffers and OpenAL to play them back.

To draw sprites efficiently and improve frame rate, make a texture atlas, draw all the sprites to it via a frame buffer, then on each frame, draw them all at once with one draw call. Draw multiple quads at once, but in the shader, pick the transformation matrix (position of sprite in your case) and texture coordinates (for the correct sprite) based on the quad's index (send quad index as a vertex attribute). Send the transformation matrices in a new VBO on every frame.

For someone who is a total beginner at programming games, I would recommend stepping away from OpenGL and the other raw ways of doing it, and using an existing engine - two obvious choices for use with C++ are Godot and Unreal - which provides many of these capabilities pre-rolled, has established tools, and wraps everything in an easier to use and more consistent framework.

6 hours ago, VoxycDev said:

Use lodepng library to load a texture and put it on the quad.

This is a very good video lesson how to use lodePNG: Advanced C++/Graphics Tutorial 12: lodePNG, GLTexture

I think it is one of the best library for loading images with transparency. I like it library because it is header-only library, like GLAD. This lesson shows how to use GLAD and GLFW: https://learnopengl.com/Getting-started/Hello-Window

1 hour ago, Irusan, son of Arusan said:

two obvious choices for use with C++ are Godot

You can write plugins in C++ only, but not a game logic.

1 hour ago, Irusan, son of Arusan said:

and Unreal

Topic Starter wants to write 2D games. When I was a beginner like him I tried to write 2D games in UE/C++. It was very difficult. If you want to get game engine it is better to get Unity because it is the most popular game engine and it will not very difficult to find jobs in Unity in the future. Scripting in C# is more friendly than in C++ for beginners. It is my opinion.

Advertisement

Looking to go c++ windows or cross platform? I use VSCode with standard c/c++ plugin for debugger and disable language service and use cquery for auto completion. Really do not like tabbed workspace vs studio provides... plus my main platform is linux due to the number of computers my family goes through but i need it all to "work" on windows at least... anyways..

Grab any OpenGL window manager and go to town. Some do a whole lot more - but ultimately on any OS it is some API such as OpenGL, Vulkan, DirectX, Metal, etc that provide the non-console graphics experience... easiest to use these things with some sort of library on top... I have used several - Urho3D, Ogre3D, Unreal, Unity (not c++), sdl (actually used by others too such as urho), sfml, heck even Qt has some stuff now - they all have their quirks. You can do the whole opengl or vulkan from scratch thing - a good learning experience really - but you likely won't create any games directly going that route.

Just jump in - start downloading libraries and making sample programs with them. It might seem like a waste of time at first - but make some stupid silly games with a couple of them. This will take longer than you think.

After you have done all of this - you really won't need much advice on where to go next

With regards to learning c++ I would consider also aiming for "pure" c++ using for example CodeBlocks and MinGW rather than Visual Studio

Maybe start with a simple console application and then start playing with basic opengl

You are likely to be, at least temporary, forced into visual c++ sooner or later if developing for windows but Standard C++ and Visual Studios one is not an exact 1 to 1 match, something worth keeping in mind

Currently making BorderStrain, 2D Sandbox ARPG www.BorderStrain.com

Visual Studio has delivered standard C++ for a long time. There are things you can choose to use outside but it's by no means remotely necessary.

On 3/5/2019 at 9:53 PM, Irusan, son of Arusan said:

Visual Studio has delivered standard C++ for a long time. There are things you can choose to use outside but it's by no means remotely necessary.

Ok I know my post got downvote so please allow me to ellaborate

I consider "compliance" in vc++ still to be taken in quotationmarks, due to multiple bugs and issues handling for example preprocessor

One example would be emplace_back which had issues due to support of variadic templates

Sure a lot is fixed over time but there are still bugs popping up that can force a lot of gymnastics getting around

Fortunately we are not considering for example c99, c11 support which is even worse

I am just saying beware that if your c++ code compiles in gcc it is not guranteed to compile correctly in vc++

For me compliance is when you are compliant and "compliance" is when you hope you are but leave it to you users to find the bugs you forgot

Oh yes, Im in that mood today... ;)

Currently making BorderStrain, 2D Sandbox ARPG www.BorderStrain.com

This topic is closed to new replies.

Advertisement