For being good game programmer ,good to use SDL?

Started by
15 comments, last by rip-off 12 years, 10 months ago

  • I would avoid SFML as there are very little tutorials and I don't really know a lot of support.

The tutorials on the SFML homepage explain pretty much anything that one needs to know, also I found that thanks to the very structured oop approach of SFML I have to study documentation and tutorials way less.
Advertisement

[quote name='Ryan Konky' timestamp='1307537241' post='4820913']
  • I would avoid SFML as there are very little tutorials and I don't really know a lot of support.

The tutorials on the SFML homepage explain pretty much anything that one needs to know, also I found that thanks to the very structured oop approach of SFML I have to study documentation and tutorials way less.
[/quote]

I'm talking of what I know from about a year ago, so it may have well changed since then. I would still choose over SDL over SFML. It was the first API that I learnt to use and helped me learn more complex APIs like WIn32 API and OpenGL.
[size="5"]My Twitter

[size="2"]I do not care for reputation, merely to help fellow users.
I used to use SDL but I switched to SFML shortly after. I mostly use it for windowing/events but I have used the graphics library that's included for my first few test projects. If you do choose SFML then I recommend you download the version 2.0 snapshot instead of the current version(1.6). Laurent, the creator, even claims that the newer "unreleased" version is more stable than 1.6 and he only has a few more major things to implement before officially releasing it. The only thing that will change drastically should be the graphics library.

Good luck!

EDIT: That reminds me, while SFML is actively being worked on, SDL hasn't been updated in years. It does have a strong community built up though.

SDL hasn't been updated in years.

SDL 1.2.x is relatively stable, and indeed hasn't had any major updates in some time. However, active development has continued on SDL 1.3. (It's still a WIP, but to say that SDL hasn't been updated in years is inaccurate.)
What's all the fuss with the Win32 API? That's what I started with, given some good tutorials on creating Windows and using the message loop. I used NeHe's openGL tutorial to get started rather quickly. Technically, you don't even need to know the ins and outs of creating a Window. Just go through the first ten or so tuts and experiment a bunch. Do realize that I have never even used SDL, so I don't know the advantages... I just know that I don't need it. Also, you don't have to use openGL, and if you want to skip the nitty gritty stuff, you could just start with an open source game engine.


http://nehe.gamedev.net/lesson.asp?index=01


Do realize that I have never even used SDL, so I don't know the advantages... I just know that I don't need it.

The primary advantage of an API such as SDL or SFML is (arguably) portability. If you're only targeting Windows, then that may not matter for you, in which case using WinAPI directly may be perfectly suitable. But if you were to try to replicate that functionality for Linux and OS X and perhaps other platforms as well, you might start to see how a cross-platform library such as SDL can be useful.
Leaving aside portability, even creating a simple window/input loop in Win32 requires a lot of (frankly ugly) boilerplate. With SDL, you can get the same result with a tiny amount of (very readable) code.

Here is a simple SDL program that draws a sine wave.

#include <cmath>
#include <cstdlib>
#include <iostream>

#include "SDL.h"

void drawSineWave(SDL_Surface *screen)
{
int h = screen->h / 2;
float time = (SDL_GetTicks() % 1000) / 1000.0f;
for(int x = 0 ; x < screen->w ; ++x)
{
float f = (x / static_cast<float>(screen->w)) + time;
int y = h + static_cast<int>(h * std::sin(360.0f * f * (M_PI / 180.0f)));
SDL_Rect r = {x, y, 1, 1};
SDL_FillRect(screen, &r, SDL_MapRGB(screen->format, 0xff, 0, 0));
}
}

int main(int, char **)
{
if(SDL_Init(SDL_INIT_VIDEO) < 0)
{
std::cerr << "Failed to init SDL " << SDL_GetError() << '\n';
return 1;
}
std::atexit(&SDL_Quit);

SDL_Surface *screen = SDL_SetVideoMode(800, 600, 0, SDL_DOUBLEBUF);
if(!screen)
{
std::cerr << "Failed to set video mode: " << SDL_GetError() << '\n';
return 2;
}

bool running = true;
while(running)
{
SDL_Event event;
while(SDL_PollEvent(&event))
{
if(event.type == SDL_QUIT)
{
running = false;
}
}

SDL_FillRect(screen, 0, 0);
drawSineWave(screen);
SDL_Flip(screen);
}

return 0;
}

Ain't it pretty!

This topic is closed to new replies.

Advertisement