Advertisement

allegro or SDL

Started by October 08, 2004 05:18 PM
17 comments, last by 23yrold3yrold 19 years, 11 months ago
Definitelly SDL, it IS really well documented and it is really easy to use.

The book Programming Linux Games is free to download, and should help you get started, though it covers a bit more than SDL.

if you need help setting up OpenGL on it, there is always my tutorial

best of luck
the reason i said is wasnt well documented is that every one points me to cone3d and i dont find that tutorial help ful at all
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
Advertisement
Quote: Original post by 23yrold3yrold
For ease of use, I'd recommend Allegro first. Easier to get into for a beginner; SDL is somewhat lower-level. But as far as SDL vs. Allegro, both are very capable, so you can't pick wrong. Read over the general API's; see which one you like. Whichever one you pick, you can always try the other later. [smile]

Yeah I'd have to agree that it harder to get any easier than writing games using allegro. I mean with the help of "game programming all in one" 2nd edition I was writing simple 2D games that ran on my apple powerbook,windows and linux box without any modification!
On the otherhand a lot more books seem to use SDL like data structures for game programmers,etc. But xcode on macs makes it just as easy to use either sdl or allegro since it has project templates for either one!
sdl template in xcode:

/* Simple program: Create a blank window, wait for keypress, quit.

Please see the SDL documentation for details on using the SDL API:
/Developer/Documentation/SDL/docs.html
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#include "SDL.h"


//screen dimensions
const int SCREEN_WIDTH=640;
const int SCREEN_HEIGHT=480;

//display surface
SDL_Surface* g_pDisplaySurface = NULL;

//bitmap surface
SDL_Surface* g_pBitmapSurface = NULL;

//event structure
SDL_Event g_Event;

//source and destination rectangles
SDL_Rect g_SrcRect,g_DstRect;

//clipping rectangle
SDL_Rect g_ClipRect;

//main function
int main(int argc, char* argv[])
{
//initialize SDL
if (SDL_Init(SDL_INIT_VIDEO)==-1)
{
//error initializing SDL

//report the error
fprintf(stderr,"Could not initialize SDL!\n");

//end the program
exit(1);
}
else
{
//SDL initialized

//report success
fprintf(stdout,"SDL initialized properly!\n");

//set up to uninitialize SDL at exit
atexit(SDL_Quit);
}

//create windowed environment
g_pDisplaySurface = SDL_SetVideoMode(SCREEN_WIDTH,SCREEN_HEIGHT,0,SDL_ANYFORMAT);

//error check
if (g_pDisplaySurface == NULL)
{
//report error
fprintf(stderr,"Could not set up display surface!\n");

//exit the program
exit(1);
}

//set up the clipping rectangle
g_ClipRect.x=32;
g_ClipRect.y=32;
g_ClipRect.w=SCREEN_WIDTH-64;
g_ClipRect.h=SCREEN_HEIGHT-64;

//set the clip rect
SDL_SetClipRect(g_pDisplaySurface,&g_ClipRect);

//load in the bitmap
g_pBitmapSurface=SDL_LoadBMP("ball.bmp");

//set the color key for the bitmap surface
SDL_SetColorKey(g_pBitmapSurface,SDL_SRCCOLORKEY,0);

//error check
if(g_pBitmapSurface==NULL)
{
//report error
fprintf(stderr,"Could not load bitmap surface!\n");

//exit the program
exit(1);
}

//set the widths of the source and destination rectangles
g_SrcRect.w=g_DstRect.w=g_pBitmapSurface->w;
g_SrcRect.h=g_DstRect.h=g_pBitmapSurface->h;

//set source rect x and y to 0
g_SrcRect.x=g_SrcRect.y=0;

//repeat forever
for(;;)
{
//wait for an event
if(SDL_PollEvent(&g_Event)==0)
{
//no event, so blit image onto display

//pick a random destination location
g_DstRect.x=rand()%(SCREEN_WIDTH-g_DstRect.w);
g_DstRect.y=rand()%(SCREEN_HEIGHT-g_DstRect.h);

//blit
SDL_BlitSurface(g_pBitmapSurface,&g_SrcRect,g_pDisplaySurface,&g_DstRect);

//update the screen
SDL_UpdateRect(g_pDisplaySurface,0,0,0,0);
}
else
{
//event occurred, check for quit
if(g_Event.type==SDL_QUIT) break;
}
}

SDL_FreeSurface(g_pBitmapSurface);

//normal termination
fprintf(stdout,"Terminating normally.\n");

//return 0
return(0);
}
allegro template for mac:
/*
* InitGraphics
*
* Created by daveangel on Tue Aug 10 2004.
* Copyright (c) 2004 __MyCompanyName__. All rights reserved.
*/

#include <Allegro/allegro.h>


int main(int argc, const char *argv[])
{
// Initalize Allegro
allegro_init();
// Initalize the keyboard
install_keyboard();

// initalize video mode to 640x480
int ret = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
if(ret != 0) {
// allegro_message displays error message in pop-up dialog box or to console
allegro_message(allegro_error);
return;
}

// display screen resolution
textprintf(screen, font, 0, 0, makecol(255,255,255),
"%dx%d", SCREEN_W, SCREEN_H);

// wait for keypress
while(!key[KEY_ESC]);

// end program
allegro_exit();

return 0;


}
END_OF_MAIN();

[size="2"]Don't talk about writing games, don't write design docs, don't spend your time on web boards. Sit in your house write 20 games when you complete them you will either want to do it the rest of your life or not * Andre Lamothe
Quote: Original post by raptorstrike
the reason i said is wasnt well documented is that every one points me to cone3d and i dont find that tutorial help ful at all


Ah! then you should have said, there is a lack of tutorials, rather than not well documented. [smile]

Cheers!
Well, there are always my tutorials.
See my sig.
HxRender | Cornerstone SDL TutorialsCurrently picking on: Hedos, Programmer One
I'd have to vote Allegro. I've looked at SDL, but I haven't used it. However, I've used Allegro extensively, and it's great. Very easy to use, and powerful enough for anything I want to do.
WyrmSlayer RPG - In Early Development
Advertisement
I don't like SDL very much, mostly because to do anything interesting, you need half a dozen libraries, or write your own functions. You can't even easily plot a single pixel. Yeah, I know, they didn't want to clutter up the main library. Allegro might be a mammoth compared to SDL, but everything you need is already right there. What to draw some text, lines, or rotate an image? You can do that 'out of the box' with Allegro. With SDL you'll need some auxiliary libraries.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
what does Allegro use under the hood for 2D graphics?

also if you want a 2D game with the 3D capabilities but without explicitly setting all the 3D stuff, what do you use?

Beginner in Game Development?  Read here. And read here.

 

Quote: Original post by Alpha_ProgDes
what does Allegro use under the hood for 2D graphics?

Depends. It's a partial DirectX wrapper under Windows IINM ...
Quote: Original post by Alpha_ProgDes
also if you want a 2D game with the 3D capabilities but without explicitly setting all the 3D stuff, what do you use?

Well, Allegro has fairly good 3D functionality. It's nowhere near as good as OpenGL, but it's good for simple effects. Anything more, and OpenGL can be used with Allegro anyway. Not sure what exactly you mean by "a 2D game with the 3D capabilities" though ...

Jesus saves ... the rest of you take 2d4 fire damage.

This topic is closed to new replies.

Advertisement