Particle Engine written in C (source code available)

Anything related in any way to game development as a whole is welcome here. Tell us about your game, grace us with your project, show us your new YouTube video, etc.

Moderator: PC Supremacists

Post Reply
MCU
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 3
Joined: Sat Jan 14, 2017 6:11 am
Favorite Gaming Platforms: SNES, N64, Genesis, Dreamcast, Wii
Programming Language of Choice: C, Assembly

Particle Engine written in C (source code available)

Post by MCU »

I remember watching Falco demonstrate DCParticles a really long time ago, and I always thought it was badass. :bow:

So I made my own in a similar style.
Its controls are position, gravity, velocity, angle, size, lifespan, and RGBA color.

I wrote this a while ago, rewrote it recently and I decided to share it cuz why not.




It's not locked into a constant framerate. On my laptop it runs at 1500fps, and my desktop PC it's nowhere near that.
If you want to compile and run it for some reason, and it's too slow, you can increase the tick rate to speed it up.

If you want to check the source code it's here
https://github.com/pxcland/GLParticles
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Particle Engine written in C (source code available)

Post by dandymcgee »

Very cool! The Proof of Concept tile engine is impressive as well. What do you plan on doing with the particle engine?

Also, I noticed you're using immediate mode rendering. If you want to learn modern OpenGL and speed it up even more, I suggest https://learnopengl.com/. Great website. In particular, the section on "instanced rendering" would help you make your particle system even faster than it already is.

Your code is very well organized and commented. Kudos on that.

Oh, and welcome to the forums Patrick!
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
MCU
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 3
Joined: Sat Jan 14, 2017 6:11 am
Favorite Gaming Platforms: SNES, N64, Genesis, Dreamcast, Wii
Programming Language of Choice: C, Assembly

Re: Particle Engine written in C (source code available)

Post by MCU »

dandymcgee wrote:Very cool! The Proof of Concept tile engine is impressive as well. What do you plan on doing with the particle engine?

Also, I noticed you're using immediate mode rendering. If you want to learn modern OpenGL and speed it up even more, I suggest https://learnopengl.com/. Great website. In particular, the section on "instanced rendering" would help you make your particle system even faster than it already is.

Your code is very well organized and commented. Kudos on that.

Oh, and welcome to the forums Patrick!
Thanks!

Haha, to be honest there really isn't much of a purpose for it. It was more of an educational thing, to get under my belt so I understand how to make one. It was pretty sloppy and slow the first time I wrote it since every particle stored way more state and took twice the memory. On the first version I was learning as I made it, this version I rewrote the code to remove all the superfluous stuff.

But now since I've made it, if I ever want to incorporate it into a project, I have a working model and won't have to write it from scratch 8-)

I'm aware that my OpenGL usage has been long deprecated :lol: When I learned basic OpenGL a while ago I went with the simplest route to get the visuals I wanted, but it's obviously not sustainable for the future.
I looked through that website and it's unbelievable how well it explains everything. I'll definitely go through it :bow:
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Particle Engine written in C (source code available)

Post by dandymcgee »

MCU wrote:I'm aware that my OpenGL usage has been long deprecated :lol: When I learned basic OpenGL a while ago I went with the simplest route to get the visuals I wanted, but it's obviously not sustainable for the future.
I looked through that website and it's unbelievable how well it explains everything. I'll definitely go through it :bow:
Cool. Ping me with @dandymcgee in Discord if you ever wanna chat.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
K-Bal
ES Beta Backer
ES Beta Backer
Posts: 701
Joined: Sun Mar 15, 2009 3:21 pm
Location: Germany, Aachen
Contact:

Re: Particle Engine written in C (source code available)

Post by K-Bal »

Great stuff, well done!

Reminds me of my own experiments I did for my bachelor's thesis. You can speed this up a lot by updating the particles in a geometry shader.

User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Particle Engine written in C (source code available)

Post by dandymcgee »

K-Bal wrote:Great stuff, well done!

Reminds me of my own experiments I did for my bachelor's thesis. You can speed this up a lot by updating the particles in a geometry shader.
Vouch. This guy's legit ^
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: Particle Engine written in C (source code available)

Post by Falco Girgis »

dandymcgee wrote:Very cool! The Proof of Concept tile engine is impressive as well. What do you plan on doing with the particle engine?

Also, I noticed you're using immediate mode rendering. If you want to learn modern OpenGL and speed it up even more, I suggest https://learnopengl.com/.
I wouldn't go so far as to say that using the OpenGL core and ditching immediate mode is necessarily going to give you a speed-up for anything like this. If you're doing something that requires shitloads of updates or basically resubmitting geometry to the GPU every frame (which is basically how immediate mode and client-side vertex arrays worked), I can basically guarantee you that the piss-poor, convoluted, highly unstandardized piece of shit GL 3+ drivers are going to absolutely rape your performance.

You will ONLY see a speedup for this type of thing if you do as K-Bal said and update the particles on the GPU itself, as you no longer have to worry about the piss-poor transfer performance. Otherwise, despite what everyone wants to think, you may very well get better performance with the legacy GL versions, and you will DEFINITELY get better performance with client-side vertex arrays.
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Particle Engine written in C (source code available)

Post by dandymcgee »

Falco Girgis wrote:
dandymcgee wrote:Very cool! The Proof of Concept tile engine is impressive as well. What do you plan on doing with the particle engine?

Also, I noticed you're using immediate mode rendering. If you want to learn modern OpenGL and speed it up even more, I suggest https://learnopengl.com/.
I wouldn't go so far as to say that using the OpenGL core and ditching immediate mode is necessarily going to give you a speed-up for anything like this. If you're doing something that requires shitloads of updates or basically resubmitting geometry to the GPU every frame (which is basically how immediate mode and client-side vertex arrays worked), I can basically guarantee you that the piss-poor, convoluted, highly unstandardized piece of shit GL 3+ drivers are going to absolutely rape your performance.

You will ONLY see a speedup for this type of thing if you do as K-Bal said and update the particles on the GPU itself, as you no longer have to worry about the piss-poor transfer performance. Otherwise, despite what everyone wants to think, you may very well get better performance with the legacy GL versions, and you will DEFINITELY get better performance with client-side vertex arrays.
I'll admit, I made the assumption he wanted to future-proof his knowledge for bigger OpenGL projects using the modern pipeline. I probably shouldn't have said "speed it up" without backing it up because you're right; for his tile engine any number of things could "speed it up" and without profiling his code I'm in no position to make specific recommendations. I meant it as general educational advice rather than an optimization tip.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
Post Reply