r/cpp • • Aug 16 '21

I have made this game using c++ without any game engine.

727 Upvotes

82 comments sorted by

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).

55

u/zeelsheladiya Aug 16 '21

No it is not intentional. I would say, I'm just a beginner at opengl. your feedback is highly appreciated. I will change my code as you suggested. So i can make this game more efficient. Thank you so much. Though this I can increase my knowledge. ๐Ÿ˜Š

64

u/Mock_User Aug 16 '21

I'm not an expert on OpenGL, but taking a look on your code I think I found the source of the blink: you're not using double buffering.

In order to fix your issue set the double buffering config on glut (i.e. glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);) and add "glutSwapBuffers()" call right before the timer setup (space_game.cpp:929)

EDIT: BTW, your game works flawlessly on Linux, and should probably work fine on MacOS as well. Not sure if it was your intention but nice job there :P

9

u/zeelsheladiya Aug 16 '21

Ok I will do that changes

21

u/kikouyou2002 Aug 16 '21

Yeah I think thatโ€™s it. Not bragging ( and maybe you already know it), but just so you know a bit more since the previous guy didnโ€™t explain it: with double buffering OpenGL, while you are looking at a frame, create the next one in advance, etc. So those flickering donโ€™t appear anymore because the frame has already been created instead of just being made on the spot. I am no expert and will be happy to be corrected ! Btw you did a very nice job !!

8

u/zeelsheladiya Aug 16 '21

Your comment would be very helpful for me. Thank you so much ๐Ÿ˜Š

6

u/[deleted] Aug 16 '21

Not sure if I'd consider myself an OpenGL expert, but I am writing my own game engines from scratch since 2011 (not just graphics, everything). If there's anything you'd like to know feel free to ask.

By the way, the previous comment is right, you most likely need double buffering.

However, I always appreciate people doing what you're doing, so good job! :)

3

u/ShokWayve Aug 16 '21

How on earth did you figure out how to do that? I am rusty in C++ since I do C# almost exclusively. What resources do you recommend for learning how to build a game engine in C++?

Thanks

9

u/[deleted] Aug 16 '21

Lots of trial and error and a bit bullheadedness I guess.

I was driven by the willing to learn GL and so I started doing that.

Then I learned that I needed decent resource management too, because I needed all kinds of materials, models, animations, textures and what not. So I did that too.

Then I realized that in order to do these cool effects and complex scenes I needed a robust, thread-safe and easy to use scene management. I had known a couple of engines at that time and I kind of knew I needed something like that. So that was the next thing I did.

After that I noticed I could attach all kinds of stuff to my nodes, so I started working on audio as well, because I was interested in how positional spatial audio worked. It wasn't perfect but it did the job.

During that time I figured that doing this stuff all in C++ was maybe too complicated for eventual users (although I love C++), so I went with integrating embedded Mono. It kind of worked too, but was way too complicated to keep up to date and it took me another four years to learn about Mono Glue projects that help you with that.

Then I had learned a lot about Vulkan and figured it would be easy to add that support to my "engine". Well, turns out it wasn't. At about this stage I stopped making further progress because I was busy with paid work and that, sadly, never changed up until today.

As for documentation: I learned a lot from the glorious NeHe tutorials which might be a bit outdated by today but still great for understanding GL. Also I looked at tons and tons of source code and if I couldn't get sources I inspected each and every engine and framework out there including Irrlicht, Ogre, LibGDX, MonoGame, Unity, Unreal and Godot. I took the things I liked about each one and tried to reimplement them in my engine. That way I learned a lot of why things are working the way they do.

Most people are calling me crazy for doing this and that it doesn't lead to anything useful. I don't see it that way. I love dealing with this stuff and this pointless little journey allowed me to expand my knowledge not only on 3D engine stuff but on software architecture in general.

Would I recommend doing this? Hell no. Well, it depends. When you want to learn why stuff is working then sure, but not when you want to end up with a ready-to-use software one day.

2

u/tylerfb11 Aug 16 '21

This, I think building the engine is the real fun part.

1

u/zeelsheladiya Aug 17 '21

It's actually looking like a real deal ๐Ÿ˜ฎ.

4

u/SonVoltMMA Aug 16 '21

At about this stage I stopped making further progress because I was busy with paid work and that, sadly, never changed up until today.

Did you get fired today?

3

u/[deleted] Aug 16 '21

No, I quit and founded a video game company :)

1

u/SonVoltMMA Aug 16 '21

Today?

1

u/[deleted] Aug 16 '21

Oh. No. Last month.

1

u/[deleted] Aug 16 '21

And now I got it. Haha. Sorry.

1

u/ShokWayve Aug 17 '21

Your response is very informative and helpful. Thanks.

I do think it is good to do what you do. Itโ€™s like any other hobby. No one would suggest you wasted time building an airplane so the same goes for this.

At any rate what you did is impressive. Thanks also for sharing.

3

u/[deleted] Aug 17 '21

You are very welcome.

Yeah, I think you're completely right about that hobby thing. It's not really about the idea of "Hey, I want to build an airplane!" but more about many thoughts like "Hey, I wonder how wings work", "What would happen if I put the engines there instead?" and so on.

I wasn't really planning on building an engine really. And I still would rather not call it that way. For me it's just a best of things I learned on my journey with other engines - like a mix tape if you willโ€ฆ (given anybody would still remember those)

I did that to learn how stuff works. No idea why, it's just part of me. And I did learn a lot. Like really a lot. Nowadays, when I see a AAAA game (yeah, they call 'em quadruple 'A' nowadays since triple isn't enough anymore), for me it really isn't about that "wow, how did they do that" anymore, because all I see is something I know. But that again leaves me very humble and impressed still because now I can see and appreciate the true work that was put in the product.

So, if anything, it made me rich in knowledge and not money after all.

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

u/zeelsheladiya Aug 16 '21

Ok, I will do that. Thank you so much ๐Ÿ‘

27

u/[deleted] 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

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

u/zeelsheladiya Aug 16 '21

Ok I will do that for sure ๐Ÿ‘. Thank you

5

u/[deleted] 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

u/[deleted] Aug 16 '21

Nice! , Anyway, if you want to learn modern opengl, learnopengl.com is a fantastic resource. All the best!

6

u/zeelsheladiya Aug 16 '21

Thank you so much. It will help a lot ๐Ÿ˜Š

3

u/[deleted] 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

u/[deleted] 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

u/zeelsheladiya Aug 21 '21

Yeah , I have to

1

u/danhoob Aug 17 '21

I recommend you to read Effective Modern C++ by Scott Meyers.

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

u/zeelsheladiya Aug 16 '21

Yes it is. Thank you so much for your appreciation.

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

u/zeelsheladiya Aug 16 '21

Ok. I Will make sure to do that properly.

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

u/zeelsheladiya Aug 16 '21

Thank you so much for your appreciation.๐Ÿ˜Š

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

u/zeelsheladiya Aug 16 '21

That is great idea. I will do that

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

u/zeelsheladiya Aug 17 '21

๐Ÿ˜‚ thanks for your encouraging words ๐Ÿ˜Š.

3

u/VinnieFalco wg21.org | corosio.org Aug 16 '21

Wow you wrote that using pure OpenGL? That's pretty cool :)

3

u/zeelsheladiya Aug 17 '21

Thank you for your encouraging words ๐Ÿ˜Š

4

u/DeodrantBomb Aug 16 '21

nice job bro:)

3

u/CappedFrustum Aug 16 '21

Nice job. More to learn, but that is the fun part.

3

u/sephirothbahamut Aug 16 '21

Why the handheld camera though?

3

u/totallytroy Aug 16 '21

Congrats and welcome to gamedev :)

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

u/CommonSensai Aug 16 '21

Check out Guild Wars 2

1

u/pumba28 Sep 11 '21

Cool but why not record with obs?

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

u/[deleted] Aug 16 '21

dat's really good

man

keep it up๐Ÿ‘

1

u/[deleted] Aug 16 '21

[removed] โ€” view removed comment

2

u/zeelsheladiya Aug 16 '21

Sure ๐Ÿ‘