I’ve been following the trusty lazyfoo’s sdl2 series. But I’m more of a learner by looking at code…
Do you guys recommend something? Not too complex that it adds to the overall complexity of learning the tool, but not too simple like “oh, gameloop, show texture”.
Let me also take the opportunity to ask, how was your learning experience? What did you use?
The source code itself is an excellent resource. If you’re on Linux or Mac you can use “grep -ri searchWord” to quickly find functions. Often times it feels like the online documentation is meant to be a companion to the source code. The source code also contains many examples. In the folder called “test” there are 80 or more such as how to open an audio device, how to open a shaped window, how to capture drag and drop messages, how to remap a controller and run rumble on same (and some of the more basic ones such as how to use a renderer and surface.
You can see the source, you’ll have to include the headers too, so.it doesn’t matter if you’re on linux or windows.
That was doing it for me… seeing the comments in the methods, but it is a more of a discoverable approach than I would like in this case.
I’m looking for a way to read the implementation without having to run the code and look for a specific file.
Currently, whenever I run SDL code, I try to look at the implementation of the code by going to the Definition.
In SDL, this results in a forward definition. E.g. void SDL_RenderDrawSomething();.
There’s no implementation. Thus, I have to run the code, find the file it’s in, open said file in another window, then read it.
What I’m asking for is static linking. I want to read the code to understand what the function is doing.
As for the tutorial, thank you for the offer. Without understanding the implementation, it’s like closed-source code. The tutorial wouldn’t help if you don’t know what the functions are doing. It would be a major waste of your time.
If you’re using an IDE, it will likely have a “go to definition” shortcut that will take you directly to the function’s definition. For example, in CLion I believe the shortcut is Ctrl+Alt+B. Compared to finding and searching through a copy of the code online, this has the advantage of showing the exact implementation you’ll be compiling against.
If you’re not using an IDE, there are options for searching text files such as grep. If you have Git Bash or similar installed, you should be able to use a command-line tool like grep to search the source code directory for mentions of the function you’re interested in. However, depending on how exactly you search for the function name, grep may also return other occurrences of the function’s name, such as uses of the function.
Personally, I use the SDL wiki’s index when I’m wondering what a particular function does. While it doesn’t link to implementation, the descriptions on the wiki are often thorough enough that I’m able to use the function correctly after reading them.
Ah that’s a shame. It looks like VS2019 would show you the definition if it could, as there’s a separate option to Go To Declaration as is visible in your image—I suppose VS2019 doesn’t have any copies of the source available to it. It’s entirely possible that there are no copies of an implementation on your device, unless you built SDL from source. It’s likely that there’s a way to configure VS2019 so as to add some sources you’ve procured yourself to its search path, though that goes beyond my knowledge of the IDE.
After finishing reading the code and the written explanations I can say that I have the answer to my original question.
Thanks for this material. I think we need more stuff like that to ease people in sdl.