• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 06:05
CEST 12:05
KST 19:05
  • 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
[ASL20] Ro8 Preview Pt2: Holding On9Maestros of the Game: Live Finals Preview (RO4)5TL.net Map Contest #21 - Finalists4Team TLMC #5: Vote to Decide Ladder Maps!0[ASL20] Ro8 Preview Pt1: Mile High15
Community News
Weekly Cups (Sept 29-Oct 5): MaxPax triples up2PartinG joins SteamerZone, returns to SC2 competition245.0.15 Balance Patch Notes (Live version)98$2,500 WardiTV TL Map Contest Tournament 151Stellar Fest: StarCraft II returns to Canada11
StarCraft 2
General
Weekly Cups (Sept 29-Oct 5): MaxPax triples up 5.0.15 Balance Patch Notes (Live version) PartinG joins SteamerZone, returns to SC2 competition ZvT - Army Composition - Slow Lings + Fast Banes Stellar Fest: StarCraft II returns to Canada
Tourneys
Tenacious Turtle Tussle Stellar Fest $2,500 WardiTV TL Map Contest Tournament 15 Sparkling Tuna Cup - Weekly Open Tournament LANified! 37: Groundswell, BYOC LAN, Nov 28-30 2025
Strategy
Custom Maps
External Content
Mutation # 494 Unstable Environment Mutation # 493 Quick Killers Mutation # 492 Get Out More Mutation # 491 Night Drive
Brood War
General
Question regarding recent ASL Bisu vs Larva game RepMastered™: replay sharing and analyzer site [ASL20] Ro8 Preview Pt2: Holding On BarrackS' ASL S20 Ro.8 Review&Power of Friendship BGH Auto Balance -> http://bghmmr.eu/
Tourneys
[Megathread] Daily Proleagues [ASL20] Ro8 Day 4 [ASL20] Ro8 Day 3 Small VOD Thread 2.0
Strategy
Current Meta 9 hatch vs 10 hatch vs 12 hatch TvZ Theorycraft - Improving on State of the Art I am doing this better than progamers do.
Other Games
General Games
Dawn of War IV Nintendo Switch Thread ZeroSpace Megathread Stormgate/Frost Giant Megathread Path of Exile
Dota 2
Official 'what is Dota anymore' discussion LiquidDota to reintegrate into TL.net
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
TL Mafia Community Thread
Community
General
Russo-Ukrainian War Thread US Politics Mega-thread Things Aren’t Peaceful in Palestine The Games Industry And ATVI Canadian Politics Mega-thread
Fan Clubs
The herO Fan Club! The Happy Fan Club!
Media & Entertainment
Movie Discussion! Anime Discussion Thread [Manga] One Piece
Sports
2024 - 2026 Football Thread Formula 1 Discussion MLB/Baseball 2023 NBA General Discussion TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
Recent Gifted Posts The Automated Ban List BarCraft in Tokyo Japan for ASL Season5 Final
Blogs
[AI] From Comfort Women to …
Peanutsc
Mental Health In Esports: Wo…
TrAiDoS
Try to reverse getting fired …
Garnet
[ASL20] Players bad at pi…
pullarius1
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1233 users

Game Programming with SFML

Blogs > ChristianS
Post a Reply
ChristianS
Profile Blog Joined March 2011
United States3203 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 States3203 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 States3203 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
Replay Cast
10:00
Master Swan Open #96
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
OGKoka 228
StarCraft: Brood War
BeSt 1789
Bisu 1297
Larva 512
actioN 492
ToSsGirL 43
yabsab 38
Sacsri 31
Hyun 20
NotJumperer 17
Dota 2
Dendi424
XcaliburYe179
ODPixel171
Counter-Strike
olofmeister1346
shoxiejesuss213
allub117
Heroes of the Storm
Khaldor190
Other Games
singsing1519
ceh9736
Pyrionflax210
crisheroes156
Mew2King74
rGuardiaN36
Organizations
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• Berry_CruncH201
• LUISG 66
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Stunt613
• HappyZerGling112
Upcoming Events
Monday Night Weeklies
5h 55m
Map Test Tournament
1d
PiGosaur Monday
1d 13h
Map Test Tournament
2 days
Tenacious Turtle Tussle
2 days
The PondCast
2 days
Map Test Tournament
3 days
Map Test Tournament
4 days
OSC
4 days
Korean StarCraft League
4 days
[ Show More ]
CranKy Ducklings
4 days
Map Test Tournament
5 days
OSC
5 days
[BSL 2025] Weekly
5 days
Safe House 2
5 days
Sparkling Tuna Cup
5 days
Map Test Tournament
6 days
OSC
6 days
IPSL
6 days
dxtr13 vs Napoleon
Doodle vs OldBoy
Liquipedia Results

Completed

BSL 20 Team Wars
Maestros of the Game
HCC Europe

Ongoing

BSL 21 Points
ASL Season 20
CSL 2025 AUTUMN (S18)
Acropolis #4 - TS2
C-Race Season 1
IPSL Winter 2025-26
EC S1
ESL Pro League S22
Frag Blocktober 2025
Urban Riga Open #1
FERJEE Rush 2025
Birch Cup 2025
DraculaN #2
LanDaLan #3
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025

Upcoming

SC4ALL: Brood War
BSL Season 21
BSL 21 Team A
RSL Revival: Season 3
Stellar Fest
SC4ALL: StarCraft II
WardiTV TLMC #15
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 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.