• STL, General Game Programming Tutorial
    29 replies, posted
For the last year, I've been trying to get into simple game programming since I have a good understanding of C++ and Java. I haven't found a descent, entry level game-making tutorial for DirectX or OpenGL. Since I want to make a 2D platformer, I decided that SDL would be the best choice, but can't find a good tutorial for that either. So where did you guys learn to make games?
Use SFML. [url]http://www.gamefromscratch.com/page/Game-From-Scratch-CPP-Edition.aspx[/url] [url]http://www.sfml-dev.org/tutorials/[/url] [url]http://redkiing.wordpress.com/category/game-development/[/url]
SDL 2 is better than SFML in my opinion, as it offers better full screen support on Unix and has some neat Unicode support for key presses.
[QUOTE=Jookia;35136477]SDL 2 is better than SFML in my opinion, as it offers better full screen support on Unix and [B]has some neat Unicode support[/B] for key presses.[/QUOTE] Naturally :D
[QUOTE=Jookia;35136477]SDL 2 is better than SFML in my opinion, as it offers better full screen support on Unix and has some neat Unicode support for key presses.[/QUOTE] Fullscreen works fine on linux for me, what exactly do you mean by "better"? Other than that, I'd suggest not using SDL. It's not really designed for beginners and doesn't offer the nice high level drawing api that SFML does (which you will find very helpful to begin with). Nobody cares about unicode key presses. Most of the concepts brought up by game programming are applicable to any language, so have a look for more general tutorials or read through ones for other languages to get an idea of what it is you need to be making. The actual drawing is only a very small (and probably the easiest) part of a game.
[QUOTE=Catdaemon;35137455]Fullscreen works fine on linux for me, what exactly do you mean by "better"?[/QUOTE] Alt tabbing.
[QUOTE=Jookia;35137483]Alt tabbing.[/QUOTE] oh ok thanks that explains everything
[QUOTE=Jookia;35136477]SDL 2 is better than SFML in my opinion, as it offers better full screen support on Unix and has some neat Unicode support for key presses.[/QUOTE] I was using SDL 1.3 (now SDL 2.0) a few months ago, and it was far from ready for general use. Have they fixed everything that was horribly terribly wrong (mouse input, etc.)?
[QUOTE=ROBO_DONUT;35138054]I was using SDL 1.3 (now SDL 2.0) a few months ago, and it was far from ready for general use. Have they fixed everything that was horribly terribly wrong (mouse input, etc.)?[/QUOTE] What's wrong with mouse input?
[QUOTE=Jookia;35139003]What's wrong with mouse input?[/QUOTE] On Linux, at least: 1. Mouse input grabbing didn't work 2. The xrel and yrel values of the mouse event were always zero. 3. The function to set mouse position was a stub I know I had other problems, too, but I don't remember what they were. Mind you, this was built from the mercurial repo several months ago, so it may have changed since.
Although SDL uses software rendering, not the GPU, right?
[QUOTE=Eudoxia;35143989]Although SDL uses software rendering, not the GPU, right?[/QUOTE] SDL 1.2 uses software for 2D blitting. However, you can open a GL context with SDL to take advantage of hardware acceleration. SDL 2.0 features hardware accelerated 2D blitting.
[QUOTE]I'd suggest not using SDL. It's not really designed for beginners and doesn't offer the nice high level drawing api that SFML does (which you will find very helpful to begin with).[/QUOTE] ~I should first mention I have nerver heard of SFML before. I went from writing c++ programs that print an ascii pyramid in the console, to writing a game engine(in-development) with SDL2. I think SDL2 is better(than SDL1.2) for beginners because the syntax is more organized and easier to understand, and they have decent documentation at [URL="http://wiki.libsdl.org/"]http://wiki.libsdl.org/[/URL] Lazy Foo has some really nice tutorials that are easy to port over to SDL2. [URL="http://www.lazyfoo.net/SDL_tutorials/"]http://www.lazyfoo.net/SDL_tutorials/[/URL] As for the stability of SDL2, everything(that I'm using) seems to work fine but SDL_GetError() says the window is invalid, yet the window functions still work. It is relatively easy to backport to SDL 1.2 if you absolutely need to. If you care about portability SDL1.2 is extremely good. It runs on so many platforms, including Nintendo DS(SDL2 can too) and even Google Chrome. [URL="https://developers.google.com/native-client/pepper16/community/porting/SDLgames"]How to Port SDL to Native Client (Google Chrome)[/URL] Botom line:I knew the basics about c++ before using SDL2, and I could still use it. Note, it does use a lot of pointers, which some people might not like. I do agree it doesn't have a higher api, but it is very portable and good at what it does.
[QUOTE=danh333;35220141]I think SDL2 is better(than SDL1.2) for beginners because the syntax is more organized and easier to understand, and they have decent documentation at [URL="http://wiki.libsdl.org/"]http://wiki.libsdl.org/[/URL][/QUOTE] Would you like to point out what you found easier to understand and "more organized" than SFML? Considering most C programs/libs I've seen, I find that hard to believe.
How well developed is SDL2? I'm interested in learning SDL and I'm torn between learning the cutting edge (but possibly less thoroughly developed) version and the older, more supported version.
[QUOTE]Would you like to point out what you found easier to understand and "more organized" than SFML? Considering most C programs/libs I've seen, I find that hard to believe. [/QUOTE] I was comparing SDL-2 to SDL-1.2 in that context, but I did have a quick look at SFML tutorials and it reminded me of SDL-1.2. Personally, I like how all of the SDL functions are pre-fixed with "SDL_" and so you don't have to use the scope :: operator. For, me (being new to OOP) I find it easier to read. What I meant by 'more organized'(in relation to SDL-1.2) is that the main rendering method is different(I'm not sure if it's better) and the window is defined differently. For example, the window in SDL-1.2 was a SDL_Surface that took up the whole screen and all images were also surfaces that were applied to the screen surface. In SDL-2 the window is an SDL_Window with a SDL_Renderer, and all images are 'SDL_Textures' which are copied to the renderer. So, mainly the windowing is more organized in that it has dedicated easy to understand functions for manipulating it(which I perceive as being organized). Whereas SDL-1.2 and SFML have 'videomode' functions which to me seem more technical... The renderer in SDL-2 has functions like SDL_RenderDrawRect() or SDL_RenderDrawLines()(which I don't really use), which are still low level, but I don't think SDL-1.2 has them. These are just my thoughts, I haven't been using opengl, or any rotation on objects, but I don't need that for my game. SFML: Create a window, then make it fullscreen sf::Window App(sf::VideoMode(800, 600, 32), "SFML Window"); App.Create(sf::VideoMode(800, 600, 32), "SFML Window", sf::Style::Fullscreen); SDL2:Create a window, then make it fullscreen SDL_Window* window = SDL_CreateWindow("SDL Window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE) SDL_SetWindowFullscreen(window, SDL_TRUE) Personally, I find SDL2 style easier to use and understand than SDL-1.2, although I do like SDL-1.2's rendering method. SFML looks easier than SDL-1.2 for me, but I don't know what the rendering method is like. Note:either Library can setup the window and set it to fullscreen in one-step. [QUOTE]How well developed is SDL2?[/QUOTE] It has been in development for at least 2 years, and it is still slowly being updated. I think it is stable, but I haven't put a whole lot of stress on it. SDL-2 was SDL-1.3 which was based on SDL-1.2. They changed it to SDL-2 because the render method is completely different, SDL_Surface defintion changed, and they broke backwards compatibility(Not completely sure). They just thought it just made sense to release it outside of SDL-1.2 as something new, since SDL-1.2 is really stable and good at what it does. If was unsure and went for SDL-2. I tried to backport my game and it took half an hour, but I had wierd rendering glitches. (I backported it because my cousin couldn't move the character on his mac and I thought the mac port was severely under developed). Turned out he wasn't pressing the right keys, and the game was working flawlessly. I think it wouldn't be too hard to port either way. I went for SDL-2 because it has a license which allows static linking of the SDL2 libs for the game which overcomes the binary compatibility issues on linux. I also liked the API for SDL2 more, since it seems easier to maintain the code. SDL-1.2 may have better support for porting to android/ios though. Edit: It seems SDL2 is needed to develop for iOS.
Ah, I see. To be honest I think you just like C, because of a lot of the points you mention are simply wrong in C++. For instance prefixes are not better than namespaces, and the SFML way of creating a window is much simpler than the SDL way according to your own examples. But that's okay, everyone has their preferred language.
Yea, I know my example looks harder, but I like how you can set up everything in one step. Plus that one function gives you a lot of customizablity. You can add flags to the end that tells SDL to render using opengl, fullscreen, borderless window, etc. I like how its all in one place with one neat command. I agree namespaces are better, but since SDL isn't that big of a library, I don't think it matters quite as much. Doesn't opengl also have pre-fixes to their functions? I skipped over C and learned C++ because C syntax looks a little bit more complex. Plus I like C++ STL containers. And I thought I would rather learn C++ before Java. If I ever decide to start a game with more advanced physics I'll definitely look into SFML. Do you know if it can be ported to Android and iOS?
Actually just fyi SFML2 is less code: sf::RenderWindow* window = new sf::RenderWindow(sf::VideoMode(width, height), "title", sf::Style::Fullscreen); There's also sf::ContextSettings to define the other bits which can be passed to the constructor.
[QUOTE=danh333;35235877]Yea, I know my example looks harder, but I like how you can set up everything in one step.[/QUOTE] SFML too, you just made it harder than it needed to be (I mean you typed the resolution and window title twice, that should've been obvious) [QUOTE=danh333;35235877]Doesn't opengl also have pre-fixes to their functions?[/QUOTE] C doesn't have namespaces.
[QUOTE]C doesn't have namespaces. [/QUOTE] Ok, that makes sense. So, I guess I prefer C styled libraries (as long as they aren't too big) even though my own code makes use of namespaces. [QUOTE] (I mean you typed the resolution and window title twice, that should've been obvious)[/QUOTE] I took the example straight from their tutorials. But I did say: [QUOTE]Note:either Library can setup the window and set it to fullscreen in one-step.[/QUOTE] Sometimes you don't necessarily want the window to be fullscreen from the start (like on a desktop), but allow the user to decide. In SDL2 you don't have to re-invoke the entire create window function, but with SFML you have to re-invoke the create function re-specifing resolution(SDL-1.2 is the same way). This isn't really a big deal. Although, there may be a way to enable fullscreen in SFML that I don't know about. Either way is perfectly fine and wouldn't take that long to implement. This is just semantics. I'm curious how much SFML can without the use of openGL. SDL2 is fairly limited in this regards. SDL2 has hardware accelerated 2d functions, but it is limited to blitting images, drawing 1px lines, drawing rects, etc. I read a couple of forum posts saying that SFML is faster for 2d rendering (without opengl) than SDL1.2. I'm not sure what the performance is like compared to SDL-2 though. [URL="http://wiki.libsdl.org/moin.cgi/CategoryRender"]http://wiki.libsdl.org/moin.cgi/CategoryRender[/URL] @Larikang If you're still deciding between SDL1.2 and SDL2, the only reason not to use SDL2(that I can see, I haven't messed around with the mouse functions quite yet) is that it may be hard to find specific help for SDL2. All the problems I have run into so far, have been my own programming errors. In my experience SDL2 is much easier to setup, Textures are automatically optimized for the renderer, renderer selects best rendering method automatically. Most of SDL2 stong points over SDL-1.2 is the rendering methodology and the easy manipulation of the window. The render method isn't necessarily better, it is just way different and easier to implement for beginners because you don't need to worry about low level things like pixel formats(this also means it is harder to modify these settings). QML is also a possiblity for 2d games. I've found a couple of simple tutorials for it. It is similar to javascript and can be used with C++. Plus, it can be run on desktop OS's, android, symbian, and meego. It is part of the Qt library. It is designed for mainly making custom apps on mobile platforms AFAIK.
Later on when you actually become good at programming, you will switch to SFML because it interfaces with stuff easily because it's object orientated and opengl. Took me close to no time to integrate it into Qt. Oh did I tell you it's C++, which SDL is not? It's 2012, act like it.
sf::RenderWindow* window = new sf::RenderWindow(sf::VideoMode(width, height), "title", sf::Style::Fullscreen); vs: SDL_Window * window = SDL_CreateWindow("title", 0, 0, width, height, SDL_SHOWN | SDL_FULLSCREEN); vs: SDL-1.2: SDL_Surface* window = SDL_SetVideoMode( width, height, BPP, SDL_SWSURFACE ); //flags at the end as well Both of these are about the same length(where SDL-1.2 can be shorter), while SDL2 makes you define where to position the window(it should just let the WM decide where to put it, by default). My point was about manipulating the window after it was created. [QUOTE]There's also sf::ContextSettings to define the other bits which can be passed to the constructor. [/QUOTE] I figured they would probably have somehing like that, SDL just uses flags OR'd together.
I used SDL 1.2 Its perfectly functional compared to sfml. SFML is objected oriented, SDL is C based. I preferred to work with SDL personally, because it gives you more control over what you are doing, but SFML might perhaps be easier for a beginner to use. You can use either one though. They're both perfectly good
[QUOTE=Icedshot;35238910]I used SDL 1.2 Its perfectly functional compared to sfml. SFML is objected oriented, SDL is C based. I preferred to work with SDL personally, because it gives you more control over what you are doing, but SFML might perhaps be easier for a beginner to use. You can use either one though. They're both perfectly good[/QUOTE] It doesn't give you "more control". SFML has more drawing features than SDL but it doesn't remove your ability to get down and dirty with the underlying graphics functions.
Sounds like a case of "[URL="http://en.wikipedia.org/wiki/Not_invented_here"]not invented here[/URL]". When you get tired of reimplementing poorly written functions and debugging things that don't work quite right you'll see the reason to use libraries like SFML. Making your own is a good learning experience perhaps, but it is not the best way to approach a problem that you're trying to solve in a quick and efficient manner.
[QUOTE=artanis;35245056]Sounds like a case of "[URL="http://en.wikipedia.org/wiki/Not_invented_here"]not invented here[/URL]". When you get tired of reimplementing poorly written functions and debugging things that don't work quite right you'll see the reason to use libraries like SFML. Making your own is a good learning experience perhaps, but it is not the best way to approach a problem that you're trying to solve in a quick and efficient manner.[/QUOTE] How is NIH relevant to SDL/SFML? Nobody even vaguely suggested writing a graphics library from scratch.
[QUOTE=ROBO_DONUT;35245783]How is NIH relevant to SDL/SFML? Nobody even vaguely suggested writing a graphics library from scratch.[/QUOTE] I was under the impression that SDL omitted a lot of the functionality that SFML includes... My bad.
[QUOTE=danh333;35238483]Ok, that makes sense. So, I guess I prefer C styled libraries (as long as they aren't too big) even though my own code makes use of namespaces.[/QUOTE] I'm just saying, you shouldn't use that argument as a good point of SDL since (no offense) no good programmer is going to suggest with a straight face that prefixes are better than namespaces in C++. I mean the reason people use prefixes in C is because there are no namespaces, otherwise they'd be using them.
I really don't think how many characters it takes to open a window should be a defining point about the library. You surely are only doing it once in your program and the code is always going to be close enough to the same between programs. Also, why new an SFML window?
Sorry, you need to Log In to post a reply to this thread.