• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 03:26
CET 09:26
KST 17:26
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10
Community News
Weekly Cups (Nov 24-30): MaxPax, Clem, herO win2BGE Stara Zagora 2026 announced15[BSL21] Ro.16 Group Stage (C->B->A->D)4Weekly Cups (Nov 17-23): Solar, MaxPax, Clem win3RSL Season 3: RO16 results & RO8 bracket13
StarCraft 2
General
Maestros of the Game: Live Finals Preview (RO4) BGE Stara Zagora 2026 announced Weekly Cups (Nov 24-30): MaxPax, Clem, herO win SC2 Proleague Discontinued; SKT, KT, SGK, CJ disband Information Request Regarding Chinese Ladder
Tourneys
$5,000+ WardiTV 2025 Championship Constellation Cup - Main Event - Stellar Fest RSL Revival: Season 3 Tenacious Turtle Tussle [Alpha Pro Series] Nice vs Cure
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 502 Negative Reinforcement Mutation # 501 Price of Progress Mutation # 500 Fright night Mutation # 499 Chilling Adaptation
Brood War
General
Which season is the best in ASL? [ASL20] Ask the mapmakers — Drop your questions BW General Discussion FlaSh's Valkyrie Copium BGH Auto Balance -> http://bghmmr.eu/
Tourneys
[Megathread] Daily Proleagues [BSL21] RO16 Group B - Sunday 21:00 CET [BSL21] RO16 Group C - Saturday 21:00 CET Small VOD Thread 2.0
Strategy
Game Theory for Starcraft How to stay on top of macro? Current Meta PvZ map balance
Other Games
General Games
Stormgate/Frost Giant Megathread The Perfect Game Path of Exile Nintendo Switch Thread Should offensive tower rushing be viable in RTS games?
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Mafia Game Mode Feedback/Ideas TL Mafia Community Thread
Community
General
Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine US Politics Mega-thread The Big Programming Thread Artificial Intelligence Thread
Fan Clubs
White-Ra Fan Club
Media & Entertainment
[Manga] One Piece Movie Discussion! Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion NBA General Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Where to ask questions and add stream? The Automated Ban List
Blogs
James Bond movies ranking - pa…
Topin
Esports Earnings: Bigger Pri…
TrAiDoS
Thanks for the RSL
Hildegard
Saturation point
Uldridge
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1256 users

Game Programming with SFML

Blogs > ChristianS
Post a Reply
ChristianS
Profile Blog Joined March 2011
United States3261 Posts
January 27 2021 01:03 GMT
#1
Irrelevant Metablogging
Every blog has to start with a few irrelevant paragraphs about why you're blogging, right?

I want to write more blogs on stuff I'm ignorant about.

It's not a natural impulse for me. When I first made a TL account I was terrified that these internet strangers would think I was ignorant or immature or bad at Starcraft (it didn't help that I was ignorant and immature and bad at Starcraft), so I tended to want to agonize over every single thing I wrote and make sure it was completely buttoned up and unassailable before I posted it. That went okay, I guess – it doesn't hurt to want to be a good poster. But if there was something I knew I was ignorant about I tended to want to hide it. Either I'd avoid posting about that thing entirely, or, if I had to for some reason, I'd go study up really quick and try to learn about the thing as much as possible, then come back and pretend I'd always known about that thing. That habit continued as I started posting in the politics thread, leading to a tendency to post about trivial things I knew I was right about, rather than important things I didn't feel confident about. I would reread every post about 3 times before posting, and about half the time I'd finish typing it up and then change my mind and close the tab instead of posting.

It's a terrible approach for self-improvement, for one thing. If you only ever talk about something if you're certain you don't need to adjust your thinking about it, you don't give people a lot of opportunities to point out what you're wrong about. But the forum tends to suffer for it, too, especially if other people are doing the same thing you are. USPMT used to suffer from a phenomenon where if someone posted a serious, reasonable attempt at addressing an important question in a nuanced way, nobody would respond to the post; but if some numbskull came in spouting some idiotic nonsense, the thread would light up as 30 posters jumped in to tell them just how dumb and wrong they are (and a couple of those would also be dumb and wrong, prompting another 30 responses, etc.). Once upon a time there were hundreds of new posts in the thread per day, and 90% of them were replies to someone else trying to tell them how wrong they were.

Maybe it's better to talk (humbly, maybe) about the stuff you're most interested in, even if you're not totally confident in your thoughts and you're probably wrong about a lot of it. With that in mind:

Game Programming with SFML
The reason you're here, presumably.

I've been trying to teach myself some programming recently. I've written acouple blogs about my programming skills over the years, and you'd probably get a pretty good idea of my (lack of) skill level from those - I've done a little learning since then, worked (most of the way) through a couple programming textbooks, but I'm still pretty novice.

But one of the textbooks I've worked through (Beginning Game Programming by John Horton) taught me how to use a pretty neat little library called SFML (short for Simple Fast Media Library), a pretty straight-forward graphics library for C++ that seems to be pretty powerful. Horton teaches you how to make a couple very simple games with it (a tree-chopping arcade game, a little zombie arena shooter, and a very simple platformer).

I'm really impressed with SFML. Previously even simple video games seemed like massive undertakings, but after that textbook they seem totally achievable. In fact, here's a video series that uses SFML to make some classic games that writes the code for the entire game from scratch, demonstrates each element of the code as it's added by running the program, and finishes the whole thing in ~5 minutes:


I think this video is more impressive as a performance piece than a tutorial, but damn it's cool.


The obvious thing to do after finishing a textbook about how to program video games is to go try to program a video game. The problem, though, is that none of the game-making resources I've encountered so far actually give very good ideas about smart organization or code design. That Tetris video is just declaring everything it uses in main with one- or two-letter variable names. Horton's code architecture in that textbook starts out atrocious (declaring separate cloud1, cloud2, cloud3 variables) and by the end he's abstracted things out a bit (creating a global Engine object with separate input(), update(), and draw() functions (each in their own source code file) that each run once per frame). Near the end he kind of gestures in the direction of what sounds like some good object-oriented design; but he doesn't actually cover it, he just finishes the platformer and leaves you with "okay, have fun!"

Example:
Now look at this hypothetical code:
+ Show Spoiler +
vector<GameObject> m_GameObjects;

// Code to initialise all game objects
// Including tiles, characters, enemies, bullets and anything else
// In the update function
for (i = m_GameObjects.begin(); i != m_GameObjects.end(); i++)
{
(*i).update(elapsedTime);
}

// That's it!
// In the draw function
// Rub out the last frame
m_Window.clear(Color::Black);
for (i = m_GameObjects.begin(); i != m_GameObjects.end(); i++)
{
m_Window.draw(*i);
}

// Show everything we have just drawn
m_Window.display();
// That's it!


The preceding code is a big step up in terms of encapsulation, code manageability, and
elegance when compared to even this final project. If you look at the previous code, you
will notice there are, however, unanswered questions, such as where collision detection fits
in, for example. Hopefully, however, you can see that further study (by building lots of
games) will be necessary to master C++.
Although we will not be implementing an entire game in this manner...

-Beginning C++ Game Programming by John Horton, pg. 459

I get the impression that game programmers tend to be a... pragmatic bunch. Partly because most of the computational tasks you actually need to accomplish in a video game aren't actually all that complicated - stuff like update each object's position based on its velocity, detect collisions, read inputs and update whatever the input is supposed to change, and draw everything once per frame. But maybe the bigger reason (and this is purely a guess on my part) is that game programmers are a lot more likely to be self-taught nerds that started programming in high school and may or may not have ever had any formal training (like me! ...except the starting in high school part).

That's not to say game programming is easy or game programmers aren't smart. Just that games (especially hobbyist/indie games) are probably more likely to employ the kind of code that folks on Stack Exchange will probably say you really shouldn't be doing. Manually creating objects with new() and killing them with delete(), for instance, and managing them with raw pointers. Brute forcing some conditional with a massive if...else tree. Lots and lots of global objects and variables. That sort of thing.

For instance, from a book by Robert Nystrom I'm thinking of reading next:

In 2001, I landed my dream job: software engineer at Electronic Arts. I couldn’t wait to get a look at some real games and see how the pros put them together. What was the architecture like for an enormous game like Madden Football? How did the different systems interact? How did they get a single codebase to run on multiple platforms?

Cracking open the source code was a humbling and surprising experience. There was brilliant code in graphics, AI, animation, and visual effects. We had people who knew how to squeeze every last cycle out of a CPU and put it to good use. Stuff I didn’t even know was possible, these people did before lunch.

But the architecture this brilliant code hung from was often an afterthought. They were so focused on features that organization went overlooked. Coupling was rife between modules. New features were often bolted onto the codebase wherever they could be made to fit. To my disillusioned eyes, it looked like many programmers, if they ever cracked open Design Patterns at all, never got past Singleton.

source

On the one hand, if I'm going to start on some big project, I'd like to figure out some decent architecture first so it doesn't get too unmanageable (and/or I don't have to spend a lot of time later going back and rewriting everything to fit an architecture I should have thought of in the first place). On the other hand, I'm maybe suffering from some analysis paralysis here – perhaps its best to just write the spaghetti code for a while, until you have a better idea why spaghetti code is bad (and what you could do better).

This blog is already too long, so I'm gonna end it here. But...

[radio voice]Next time on ChristianS's occasional programming blog...

I'm gonna take a look at the code of an actual (more or less) functional RTS, in hopes of learning something about how to smartly organize a game's code.

*****
"Never attribute to malice that which is adequately explained by stupidity." -Robert J. Hanlon
GroT
Profile Blog Joined January 2004
Belgium3003 Posts
January 27 2021 14:35 GMT
#2
Love your enthusiasm man nice blog post! But if I can say something negative, you remind me of this quote:


The first step of any project is to grossly underestimate its complexity and difficulty.


My advice is to go easy dude! Pick a project that you think will be INSANELY easy because you'll inevitably find out that it's not so easy. Making an RTS by yourself seems like insanity to me, more power to you if you pull that off
DANCE ALL DAY
ChristianS
Profile Blog Joined March 2011
United States3261 Posts
January 27 2021 15:18 GMT
#3
Good advice, but to be clear, I’m not gonna build an RTS, I’m gonna look at someone else’s code. My first project was to make a little screensaver where particles bounce around the screen, and I got confused enough trying to do collisions that I think I’m gonna do another book on game architecture first.
"Never attribute to malice that which is adequately explained by stupidity." -Robert J. Hanlon
GroT
Profile Blog Joined January 2004
Belgium3003 Posts
January 28 2021 07:19 GMT
#4
Ah cool I misunderstood that part and almost had a heart attack lol

That project sounds ideal actually! Good work

I recommend javidx9 on youtube for you. The guy has a good mix of doing amazing stuff while introducing minimal complexity and really teaching some fundamentals. His coding style is also really retro which I think is fun.




DANCE ALL DAY
ChristianS
Profile Blog Joined March 2011
United States3261 Posts
February 03 2021 04:18 GMT
#5
Somewhat delayed response: That YouTube channel looks great, and I'm gonna try to watch some of his stuff when I get a chance. In particular I saw a series in which he's making an RPG with some more involved OOP I think I could learn a lot from. Thanks for the recommendation!
"Never attribute to malice that which is adequately explained by stupidity." -Robert J. Hanlon
Please log in or register to reply.
Live Events Refresh
Next event in 3h 34m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
SortOf 218
ProTech117
StarCraft: Brood War
Horang2 2516
actioN 695
Larva 221
PianO 135
Zeus 133
Dewaltoss 53
Sharp 41
soO 29
NotJumperer 27
Hm[arnc] 8
Dota 2
XaKoH 565
XcaliburYe88
League of Legends
JimRising 581
C9.Mang0294
Counter-Strike
shoxiejesuss299
Super Smash Bros
Westballz18
Other Games
summit1g13331
WinterStarcraft523
Happy265
Organizations
Other Games
gamesdonequick725
StarCraft: Brood War
UltimateBattle 87
lovetv 5
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 13 non-featured ]
StarCraft 2
• Berry_CruncH249
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Lourlo999
• Stunt576
Upcoming Events
Wardi Open
3h 34m
StarCraft2.fi
8h 34m
Replay Cast
15h 34m
The PondCast
1d 1h
OSC
1d 7h
Demi vs Mixu
Nicoract vs TBD
Babymarine vs MindelVK
ForJumy vs TBD
Shameless vs Percival
Replay Cast
1d 15h
Korean StarCraft League
2 days
CranKy Ducklings
3 days
SC Evo League
3 days
BSL 21
3 days
Sziky vs OyAji
Gypsy vs eOnzErG
[ Show More ]
OSC
3 days
Solar vs Creator
ByuN vs Gerald
Percival vs Babymarine
Moja vs Krystianer
EnDerr vs ForJumy
sebesdes vs Nicoract
Sparkling Tuna Cup
4 days
OSC
4 days
BSL 21
4 days
Bonyth vs StRyKeR
Tarson vs Dandy
Replay Cast
5 days
Wardi Open
5 days
StarCraft2.fi
5 days
Replay Cast
5 days
StarCraft2.fi
6 days
PiGosaur Monday
6 days
Liquipedia Results

Completed

Proleague 2025-11-30
RSL Revival: Season 3
Light HT

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
YSL S2
BSL Season 21
CSCL: Masked Kings S3
Slon Tour Season 2
Acropolis #4 - TS3
META Madness #9
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
Kuram Kup
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Disclosure: This page contains affiliate marketing links that support TLnet.

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.