r/cpp • u/zeelsheladiya • Aug 16 '21
I have made this game using c++ without any game engine.
49
u/G_ka Aug 16 '21
Well done. Just a piece of advice: use a screen recorder such as OBS studio. Recording videos this way makes it look very unprofessional
9
27
Aug 16 '21
The Ui is more impressive than the game, Did you make it yourself or is it a library?
20
u/zeelsheladiya Aug 16 '21
I made this whole game + ui using c++ from scratch without any library except opengl.
13
u/ShillingAintEZ Aug 16 '21 edited Aug 16 '21
You are using glut, which is a separate library from opengl, but there is nothing wrong with that.
Other libraries that people use for the same purpose are SDL and GLFW (I like GLFW)
18
u/zeelsheladiya Aug 16 '21
Here, you can go through the code :- https://github.com/zeelsheladiya/space-shooting-game-in-c-programing-and-opengl
28
u/Mock_User Aug 16 '21
With Github you have an specific page for your releases so you don't have to upload a binary into your repo.
Also, you don't have a build system script in place. I suggest you to use cmake or meson.
6
5
Aug 16 '21
Why are you using the old immediate mode api?
20
u/zeelsheladiya Aug 16 '21
Because I'm beginner when it comes to opengl. I was not aware about where to start. So I started learning and making this game, what I had found.
23
Aug 16 '21
Nice! , Anyway, if you want to learn modern opengl, learnopengl.com is a fantastic resource. All the best!
6
3
Aug 16 '21 edited Oct 20 '24
whole workable boat sugar profit entertain like shocking piquant disgusted
This post was mass deleted and anonymized with Redact
5
Aug 16 '21
Technically, I agree, but since these few tris won't hit performance, immediate mode won't harm here too.
But yes, this old thing needs to be forgotten.
21
u/Hovercraft2915 Aug 16 '21
As a seasoned dev, let me tell you few things. First of all, your project although rather small and simple is impressive nonetheless, not because of it's scope, but because you've set a goal and achieved it. That is something to be proud of.
As others already pointed out, you should look at recoding software like OBS (probably the second best after nVidia ShadowPlay). Shaky camera and zooming in and out doesn't make your video more interesting, quite the opposite.
Since you use Windows, the all round best IDE you can get there is Visual Studio (don't get it confused with glorified text editor named Visual Studio Code, these are two completely different tools). Community edition is great and generally speaking have all you need, especially a powerful debugger (aka programmers best friend), that small IDE's often lack. At the point when you need more, you will know better what tool you have to switch to. On top of that it is industry standard for development for Windows, so the more familiar you are with it, the better.
Git, like any other, version control system is meant to be used for you source code (*.h, *.cpp, *.py, whatever you feed into compiler) and resources (meshes, bitmaps, configs). Build artefacts (*.exe, *.dll, *.lib, etc.) don't belong there. GitHub does have a release feature, where you can upload those artifacts, but by all means you should still keep these two separated. The sooner you learn how to nicely organized your code and resources, the better, and good developers are the ones who keep their work tidy, not the ones who write a lot of code.
You have plenty of "magic values" (e.g. game_panel ones explained with comment), those are great candidates for class enums, that will greatly improve readability of your code. Combined with more use of switch statements, especially when you have simple checks against constants, like your entire enemy function. Another thing that would help you organize your code is object oriented design.
Implementing functions in headers is widely seen as a bad move, it has an impact on compilation time, and even if it's not applicable in the project of your size it's still a good practice to not put in headers anything that doesn't have to be there.
There are few minor mistakes, like for example when you create a temporary table for 6 arguments of the zeelTriangleDisplay function just to pass them to another set of functions. That table is absolutely unnecessary, you can pass these values as they are. Naming of your functions doesn't need the prefix, it's just a clutter, and also consistent naming conventions are great at improving readability and help with searching through code. Either use snake_case, PascalCase or camelCase. You can use different ones for functions and classes, but be consistent with them. If you really need prefixes for a sort of encapsulation, use namespaces.
Personally I would avoid declaring multiple variable of the same type in the same line (comma separated), e.g. from zeelCircleDisplay int x=0,y=radius,d=3-(2*radius); it just doesn't look clean and may cause you some confusion in the future.
Finally last point, OpenGL. You are using what's called legacy OpenGL, also known as immediate mode. It was deprecated 15 years ago, don't waste your time on it. It's good to know how it worked, but it's a dead end. Its performance is worse than if you'd render everything on CPU. Modern OpenGL (aka. everything at OpenGL 3.0 and above) is a little bit more complicated, but at the same time much more relevant. Somewhat decent learning material would be learnopengl.com The core difference being, old OpenGL renders one primitive at a time, you are basically telling your GPU triangle by triangle how to render stuff. Modern OpenGL will instead take a Vertex Buffer Object containing all your triangles and all you have to do then is to tell it, render all this for me please. And it's done. Sure you have to write some boiler plate (Vertex Array Objects, Element Buffer Objects and shaders), but once you get the hang of it, it's not that bad.
Overall, 7/10, mostly for effort and because it's finished, and I wish you many more successful projects.
6
u/zeelsheladiya Aug 17 '21
Thank you for your advice. Your words are very vital for me. I will work on it. As well as I will try to improve programming skills. now I have installed visual studio. It has features. Thank you so much for this advice. I'm just confused about GitHub. How can I learn to manage projects like a pro? Any website for that. And also I will try to use proper naming convention in my next projects. As well as thank you for advising me learnopengl.com . I will help me a lot to improve my knowledge for sure. Thank you so much ๐
2
u/thebestinthewest911 May 06 '23
I would look at other cpp projects in GitHub and how they organize their code to help you with overall project organization. Probably best to look at a well established code base, so you don't pick up weird/niche habits. There are also a handful of books that talk about proper/modern organization (non come to mind off the top of my head rn, but I'm sure a quick search on the interwebs will give you plenty of resources on that end).
18
u/Doggynotsmoker Aug 16 '21
Well done, that looks really good! What is your openGL experience?
But C and C++ are not the same language, so that should be changed in video.
2
u/zeelsheladiya Aug 16 '21
Experience was very great. And also you are right. I will do that changes.
9
u/danhoob Aug 17 '21 edited Aug 17 '21
Author, I have studied your codebase, but it lack so much Modern C++ things you could utilize to reduce code duplication. It just feels very C-ish rather C++ish. You also need to stop the use of `using namespace std;` which I noticed on your database repo ('https://github.com/zeelsheladiya/OurDB-Database").
3
u/zeelsheladiya Aug 17 '21
Ohhh I get it. I will do that changes. Thanks to help me to improve ๐
2
u/danhoob Aug 17 '21
I've looked at your commit that you made yesterday
https://github.com/zeelsheladiya/OurDB-Database/commit/306a253f00a783c092785e61f1dbd56aaa85732c
True that I told you remove using namespace std but thought you aware that you also have to append the std:: prefix.
Eg, your code full of stuff like `string, regex, vector` or whatever and they should have the std:: prefix. So, `std::string, std:;regex, std:;vector` etc
1
u/zeelsheladiya Aug 18 '21
Ok I will do that changes too.
1
u/danhoob Aug 20 '21
The header files should be there too. You should not comment out them.
#include <iostream>
#include <vector>
Looks like you got a lot of works to do..
1
1
6
u/__anonsmoker__ Aug 16 '21
Dev-C++ !! I haven't used that IDE in a long time, but good to see it still going strong
3
8
u/jherico VR & Backend engineer, 30 years Aug 16 '21
If you want to write this kind of game I'd suggest looking into https://processing.org/ as it will let you make lots of simple experimental things like this. Or you could use PyGame, or something similar.
As it stands your game is an impressive accomplishment, but using C with no build system and the archaic OpenGL dialect you've been is rapidly going to become limiting. For instance, if you add a single additional source file using the same header you're going to start getting link errors.
Unless your intent is to spend the next month learning about build systems and linking, instead of actually making things, I'd find a framework to play with.
2
u/zeelsheladiya Aug 16 '21
It is very important and useful information for me. Next time, I will make sure make things properly. So , I can increase my productivity. Thank you ๐
4
u/Whiispard Aug 16 '21
>If you want to write this kind of game I'd suggest looking into https://processing.org/
as it will let you make lots of simple experimental things like this.Thanks,I've been looking for ideas that are between a game and a GUI program.
Since making a useful project which actually does something is hard to do,A game is better thing to get started.
But It gives feeling to use game engine or library instead (Since we have to care about realistic physics, different sprite costumes etc)
Which is why games like this, feels better to code to learn, they're more like code logic and minimum GUI to display them.
4
u/Gunslinging_Gamer Aug 16 '21 edited Aug 16 '21
I learned C++ and DirectX to start but never managed to finish my game. Ended up working on Android projects. Great work!
Oh, make sure you're not rendering a stupid number of FPS. Put a limiter on as standard. 100, 120, or 144 is more than enough for that type of game.
3
4
u/xland44 Aug 17 '21
> knows enough about computers to program a game without an engine
>doesn't know how to download a screen recorder
Jokes aside, this looks super cool man! good job :D
2
u/zeelsheladiya Aug 17 '21
๐ sorry for the inconveniences. As you can see in video in my taskbar obs studio already installed. I was having terminate issues while using thata. so, I used my phone. Apart from that, Thank you for your encouraging words ๐.
3
u/OkConsideration6593 Aug 16 '21
Thankyou so much for putting this here.
Thankyou for the motivation. I am gonna quickly get a free coin and give you!
1
3
u/ShokWayve Aug 16 '21
This impressive. Very impressive. What is the purpose? Fun and exploration or something else?
Also, did you follow a tutorial of some sort?
2
u/zeelsheladiya Aug 16 '21
I did this because I want to gain knowledge about opengl the basic of graphics and also I had fun by making this.
3
u/antoniocs Aug 16 '21
Was that Bloodshed IDE I saw???
Also... there is software that will record your screen, no need to use your mobile.
2
u/zeelsheladiya Aug 16 '21
Ide is dev c++. And I know I have obs studio in that but I was having issues while using that. So I did that using phone. But next time I will fix the problem and do that by recoding screen. Thank you so much for your feedback. ๐
3
u/antoniocs Aug 16 '21
I know it is... and it's SUPER OLD, like really really old... you should try Visual Studio or at least Visual Studio Code
3
u/zeelsheladiya Aug 16 '21
Yeah sure. For next projects I will upgrade my tools so I can incline my productivity. Thank you โบ๏ธ
3
u/GAMEYE_OP Aug 16 '21
Another large improvement to the rendering speed that will help along with the double buffering is that you are drawing everything one pixel at a time. Start/End are expensive moments in the GL pipeline. You can get some big benefits by updating your render functions.
3
3
u/Melon_Chief Aug 16 '21
I have good news and bad news.
The good news is that you're a legend.
The bad news is that you inadvertently made an engine.
2
3
u/VinnieFalco wg21.org | corosio.org Aug 16 '21
Wow you wrote that using pure OpenGL? That's pretty cool :)
3
4
3
3
3
3
u/DevBen80 Aug 17 '21
This takes me back :) I did the same thing 20 years ago, great fun. It's a useful learning experience and you get more insight into how unreal or unity works.
3
u/laam-egg Aug 17 '21
Surprised that you didn't use a screen recording software (like OBS Studio). Eager to see your game refactored (e.g. with double buffering) and then recorded with such a utility. Keep up your creativity !
2
2
2
1
1
u/aCuria Feb 09 '22
Looks like one of my assignments long agoโฆ had 2 weeks to make something like this in C
0
1
84
u/Rhawk187 Aug 16 '21
Is the flickering intentional? Or is it an artefact of recording the screen?
If you are getting tearing, make sure to look into double buffering (glSwapBuffers).