diff --git a/sdl/whatever/Makefile b/sdl/whatever/Makefile new file mode 100644 index 0000000..0fc823e --- /dev/null +++ b/sdl/whatever/Makefile @@ -0,0 +1,32 @@ +PREFIX=/usr + +#OBJS specifies which files to compile as part of the project +OBJS = whatever.c + +#CC specifies which compiler to use +CC = clang + +#COMPILER_FLAGS specifies the additional compilation options we're using +# -w suppress all warnings +COMPILER_FLAGS = -Wall + +#LINKER_FLAGS specifies the libraries we're linking against +LINKER_FLAGS = -lSDL + +#OBJ_NAME specifies the name of our executable +OBJ_NAME= whatever + +#This is the target that compiles our executable +all : $(OBJS) + $(CC) $(OBJS) $(COMPILER_FLAGS) $(LINKER_FLAGS) -o $(OBJ_NAME) +install : + mkdir -p ${PREFIX}/share/${OBJ_NAME} + cp ${OBJ_NAME} ${PREFIX}/share/${OBJ_NAME}/ + ln -si ${PREFIX}/share/${OBJ_NAME}/${OBJ_NAME} ${PREFIX}/bin/${OBJ_NAME} +uninstall : + rm ${PREFIX}/bin/${OBJ_NAME} + rm ${PREFIX}/share/${OBJ_NAME}/${OBJ_NAME} + rm -r ${PREFIX}/share/${OBJ_NAME} +clean : + rm ${OBJ_NAME} + diff --git a/sdl/whatever/dinowheel.bmp b/sdl/whatever/dinowheel.bmp new file mode 100644 index 0000000..ee83ec3 Binary files /dev/null and b/sdl/whatever/dinowheel.bmp differ diff --git a/sdl/whatever/sdl_logo.bmp b/sdl/whatever/sdl_logo.bmp new file mode 100644 index 0000000..f88c6ba Binary files /dev/null and b/sdl/whatever/sdl_logo.bmp differ diff --git a/sdl/whatever/sdltest.tar.gz b/sdl/whatever/sdltest.tar.gz new file mode 100644 index 0000000..ae0b542 Binary files /dev/null and b/sdl/whatever/sdltest.tar.gz differ diff --git a/sdl/whatever/sdltest/Makefile b/sdl/whatever/sdltest/Makefile new file mode 100644 index 0000000..6fe0f67 --- /dev/null +++ b/sdl/whatever/sdltest/Makefile @@ -0,0 +1,5 @@ +sdltest: sdltest.cpp + g++ `sdl-config --cflags --libs` sdltest.cpp -o sdltest + +clean: + rm sdltest diff --git a/sdl/whatever/sdltest/sdltest.cpp b/sdl/whatever/sdltest/sdltest.cpp new file mode 100644 index 0000000..49eee86 --- /dev/null +++ b/sdl/whatever/sdltest/sdltest.cpp @@ -0,0 +1,66 @@ + +#include "SDL.h" + +int main( int argc, char* argv[] ) +{ + /* initialize SDL */ + SDL_Init(SDL_INIT_VIDEO); + + /* set the title bar */ + SDL_WM_SetCaption("SDL Test", "SDL Test"); + + /* create window */ + SDL_Surface* screen = SDL_SetVideoMode(640, 480, 0, 0); + + /* load bitmap to temp surface */ + SDL_Surface* temp = SDL_LoadBMP("sdl_logo.bmp"); + + /* convert bitmap to display format */ + SDL_Surface* bg = SDL_DisplayFormat(temp); + + /* free the temp surface */ + SDL_FreeSurface(temp); + + SDL_Event event; + int gameover = 0; + + /* message pump */ + while (!gameover) + { + /* look for an event */ + if (SDL_PollEvent(&event)) { + /* an event was found */ + switch (event.type) { + /* close button clicked */ + case SDL_QUIT: + gameover = 1; + break; + + /* handle the keyboard */ + case SDL_KEYDOWN: + switch (event.key.keysym.sym) { + case SDLK_ESCAPE: + case SDLK_q: + gameover = 1; + break; + } + break; + } + } + + /* draw the background */ + SDL_BlitSurface(bg, NULL, screen, NULL); + + /* update the screen */ + SDL_UpdateRect(screen, 0, 0, 0, 0); + } + + /* free the background surface */ + SDL_FreeSurface(bg); + + /* cleanup SDL */ + SDL_Quit(); + + return 0; +} + diff --git a/sdl/whatever/whatever b/sdl/whatever/whatever new file mode 100755 index 0000000..0a0054a Binary files /dev/null and b/sdl/whatever/whatever differ diff --git a/sdl/whatever/whatever.c b/sdl/whatever/whatever.c new file mode 100644 index 0000000..34f351f --- /dev/null +++ b/sdl/whatever/whatever.c @@ -0,0 +1,136 @@ +#include "SDL/SDL.h" + +//Write a function that moves an image based on which arrow keys are pressed. +//something like +//void move_image(direction, image); + + + + +int main ( int argc, char *argv[] ) +{ + /* initialize SDL */ + if (SDL_Init(SDL_INIT_VIDEO) != 0){ + printf("Unable to init SDL!: %s\n", SDL_GetError()); + return 1; + } + + /* set the title bar */ + SDL_WM_SetCaption("SDL Test", "SDL Test"); + + /* init surfaces */ + SDL_Surface* screen; + SDL_Surface* temp; + SDL_Surface* bg; + SDL_Surface* top_image; + SDL_Rect src, dest; + + + /* create window of size 640x480 in hi-color (16-bit) mode*/ + screen = SDL_SetVideoMode(640, 480, 16, 0); + + if (screen == NULL){ + printf("Unable to set video mode: %s\n", SDL_GetError()); + return 1; + } + atexit(SDL_Quit); + + /* load bitmap to temp surface */ + temp = SDL_LoadBMP("sdl_logo.bmp"); + + if (temp == NULL){ + printf("Unable to find image!!: %s\n", SDL_GetError()); + return 1; + } + + /* convert bitmap to display format */ + bg = SDL_DisplayFormat(temp); + if (bg == NULL){ + printf("Unable to format image!: %s\n", SDL_GetError()); + } + + + /* free the temp surface + * What we are doing above, with temp is simply + * making everything easier to deal with + * then freeing the extra memory space. + * i.e: We could have just as easily done + * SDL_DisplayFormat(SDL_LoadBMP("sdl_logo.bmp"));*/ + SDL_FreeSurface(temp); + + /* load top_image image to practice blit on top of surface*/ + temp = SDL_LoadBMP("dinowheel.bmp"); + if (temp == NULL){ + printf("Unable to load top_image: %s/n", SDL_GetError()); + return 1; + } + + top_image = SDL_DisplayFormat(temp); + if (top_image == NULL){ + printf("Unable to format top_image: %s/n", SDL_GetError()); + return 1; + } + + SDL_FreeSurface(temp); + + src.x = 0; + src.y = 0; + src.w = top_image->w; /* copy entire image */ + src.h = top_image->h; + /* Could also do "dest = src" if they were to start at the same spot */ + dest.x = 25; + dest.y = 25; + dest.w = top_image->w; + dest.h = top_image->h; + + SDL_Event event; + int gameover = 0; + + /* message pump */ + while (!gameover) + { + /* look for an event */ + if (SDL_PollEvent(&event)) { + /* an event was found */ + switch (event.type) { + /* close button clicked */ + case SDL_QUIT: + gameover = 1; + break; + + /* handle the keyboard */ + case SDL_KEYDOWN: + switch (event.key.keysym.sym) { + case SDLK_ESCAPE: + case SDLK_q: + gameover = 1; + break; + case SDLK_w: + printf("You just pressed 'w'\n"); + break; + } + break; + } + } + + /* draw the background */ + SDL_BlitSurface(bg, NULL, screen, NULL); + + /* Blit top_image to the screen */ + SDL_BlitSurface(top_image, &src, screen, &dest); + + /* update the screen */ + SDL_UpdateRect(screen, 0, 0, 0, 0); + } + + /* free the background surface */ + SDL_FreeSurface(bg); + + /* free top_image */ + SDL_FreeSurface(top_image); + + /* cleanup SDL */ + SDL_Quit(); + + return 0; +}