• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 12:21
CET 17:21
KST 01:21
  • 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
[ASL21] Ro24 Preview Pt1: New Chaos0Team Liquid Map Contest #22 - Presented by Monster Energy7ByuL: The Forgotten Master of ZvT30Behind the Blue - Team Liquid History Book19Clem wins HomeStory Cup 289
Community News
Weekly Cups (March 16-22): herO doubles, Cure surprises3Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool43Weekly Cups (March 9-15): herO, Clem, ByuN win42026 KungFu Cup Announcement6BGE Stara Zagora 2026 cancelled12
StarCraft 2
General
Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool Weekly Cups (March 16-22): herO doubles, Cure surprises Weekly Cups (August 25-31): Clem's Last Straw? Team Liquid Map Contest #22 - Presented by Monster Energy What mix of new & old maps do you want in the next ladder pool? (SC2)
Tourneys
Sparkling Tuna Cup - Weekly Open Tournament World University TeamLeague (500$+) | Signups Open RSL Season 4 announced for March-April WardiTV Team League Season 10 KSL Week 87
Strategy
Custom Maps
Publishing has been re-enabled! [Feb 24th 2026]
External Content
The PondCast: SC2 News & Results Mutation # 518 Radiation Zone Mutation # 517 Distant Threat Mutation # 516 Specter of Death
Brood War
General
mca64Launcher - New Version with StarCraft: Remast BGH Auto Balance -> http://bghmmr.eu/ ASL21 General Discussion Soulkey's decision to leave C9 JaeDong's form before ASL
Tourneys
[ASL21] Ro24 Group B 2026 Changsha Offline Cup [ASL21] Ro24 Group A ASL Season 21 LIVESTREAM with English Commentary
Strategy
Fighting Spirit mining rates Simple Questions, Simple Answers Soma's 9 hatch build from ASL Game 2
Other Games
General Games
General RTS Discussion Thread Stormgate/Frost Giant Megathread Nintendo Switch Thread Path of Exile Dawn of War IV
Dota 2
Official 'what is Dota anymore' discussion The Story of Wings Gaming
League of Legends
G2 just beat GenG in First stand
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
TL Mafia Community Thread Five o'clock TL Mafia Mafia Game Mode Feedback/Ideas Vanilla Mini Mafia
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread European Politico-economics QA Mega-thread YouTube Thread
Fan Clubs
The IdrA Fan Club
Media & Entertainment
[Req][Books] Good Fantasy/SciFi books Movie Discussion! [Manga] One Piece
Sports
2024 - 2026 Football Thread Cricket [SPORT] Formula 1 Discussion Tokyo Olympics 2021 Thread General nutrition recommendations
World Cup 2022
Tech Support
Laptop capable of using Photoshop Lightroom?
TL Community
The Automated Ban List
Blogs
Funny Nicknames
LUCKY_NOOB
Money Laundering In Video Ga…
TrAiDoS
Iranian anarchists: organize…
XenOsky
FS++
Kraekkling
Shocked by a laser…
Spydermine0240
Unintentional protectionism…
Uldridge
ASL S21 English Commentary…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 3122 users

Game Programming with SFML

Blogs > ChristianS
Post a Reply
ChristianS
Profile Blog Joined March 2011
United States3304 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 States3304 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 States3304 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 7h 40m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
LamboSC2 383
Trikslyr45
Rex 40
Codebar 26
StarCraft: Brood War
Britney 24947
Calm 5625
Shuttle 2760
Bisu 2696
Larva 647
ggaemo 632
Mini 506
BeSt 498
firebathero 389
Soma 353
[ Show more ]
Stork 336
Leta 287
Snow 280
Light 278
EffOrt 270
ZerO 253
PianO 239
Rush 219
actioN 169
Zeus 82
Mind 66
Sharp 58
sorry 49
HiyA 44
[sc1f]eonzerg 42
Dewaltoss 36
Free 34
Barracks 28
Movie 19
soO 16
IntoTheRainbow 16
Terrorterran 10
ajuk12(nOOB) 9
Sacsri 9
ivOry 7
Dota 2
Gorgc7650
Counter-Strike
fl0m1332
ceh9427
edward127
oskar68
adren_tv52
Heroes of the Storm
MindelVK17
Other Games
singsing1895
hiko937
Grubby772
B2W.Neo729
FrodaN725
DeMusliM342
Hui .146
crisheroes136
Liquid`VortiX129
Sick117
QueenE109
ArmadaUGS102
ZerO(Twitch)16
Organizations
Dota 2
PGL Dota 2 - Main Stream37
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 16 non-featured ]
StarCraft 2
• poizon28 45
• intothetv
• AfreecaTV YouTube
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• FirePhoenix2
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• WagamamaTV71
League of Legends
• Nemesis3922
• TFBlade929
• Shiphtur247
Upcoming Events
PiGosaur Cup
7h 40m
Replay Cast
16h 40m
Afreeca Starleague
17h 40m
hero vs YSC
Larva vs Shine
Kung Fu Cup
18h 40m
Replay Cast
1d 7h
KCM Race Survival
1d 16h
The PondCast
1d 17h
WardiTV Team League
1d 19h
OSC
1d 19h
Replay Cast
2 days
[ Show More ]
WardiTV Team League
2 days
RSL Revival
3 days
Cure vs Zoun
herO vs Rogue
WardiTV Team League
3 days
Platinum Heroes Events
3 days
BSL
4 days
RSL Revival
4 days
ByuN vs Maru
MaxPax vs TriGGeR
WardiTV Team League
4 days
BSL
5 days
Replay Cast
5 days
Replay Cast
5 days
Afreeca Starleague
5 days
Light vs Calm
Royal vs Mind
Wardi Open
5 days
Monday Night Weeklies
5 days
OSC
6 days
Sparkling Tuna Cup
6 days
Afreeca Starleague
6 days
Rush vs PianO
Flash vs Speed
Liquipedia Results

Completed

Proleague 2026-03-23
WardiTV Winter 2026
Underdog Cup #3

Ongoing

KCM Race Survival 2026 Season 1
BSL Season 22
CSL Elite League 2026
CSL Season 20: Qualifier 1
ASL Season 21
Acropolis #4 - TS6
RSL Revival: Season 4
Nations Cup 2026
NationLESS Cup
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual

Upcoming

2026 Changsha Offline CUP
CSL Season 20: Qualifier 2
CSL 2026 SPRING (S20)
Acropolis #4
IPSL Spring 2026
BSL 22 Non-Korean Championship
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
IEM Atlanta 2026
Asian Champions League 2026
PGL Astana 2026
BLAST Rivals Spring 2026
CCT Season 3 Global Finals
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
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 © 2026 TLnet. All Rights Reserved.