From 85f2956c67a9ca0eab9fa3e72637e23120c0354d Mon Sep 17 00:00:00 2001 From: Logen Kain Date: Sat, 12 Nov 2016 18:03:17 -0700 Subject: [PATCH] whatever: converted to SDL2 --- sdl/whatever/Makefile | 2 +- sdl/whatever/Makefile.sdl1 | 32 +++++++++ sdl/whatever/whatever | Bin 15088 -> 15400 bytes sdl/whatever/whatever.c | 125 ++++++++++++++++++--------------- sdl/whatever/whateverSDL1.c | 136 ++++++++++++++++++++++++++++++++++++ 5 files changed, 237 insertions(+), 58 deletions(-) create mode 100644 sdl/whatever/Makefile.sdl1 create mode 100644 sdl/whatever/whateverSDL1.c diff --git a/sdl/whatever/Makefile b/sdl/whatever/Makefile index 0fc823e..38ba9c3 100644 --- a/sdl/whatever/Makefile +++ b/sdl/whatever/Makefile @@ -11,7 +11,7 @@ CC = clang COMPILER_FLAGS = -Wall #LINKER_FLAGS specifies the libraries we're linking against -LINKER_FLAGS = -lSDL +LINKER_FLAGS = -lSDL2 #OBJ_NAME specifies the name of our executable OBJ_NAME= whatever diff --git a/sdl/whatever/Makefile.sdl1 b/sdl/whatever/Makefile.sdl1 new file mode 100644 index 0000000..0fc823e --- /dev/null +++ b/sdl/whatever/Makefile.sdl1 @@ -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/whatever b/sdl/whatever/whatever index 0a0054a5561a22aaa2bdea69bc83ba89753b9697..9c25478d47d6f22cdaa169884a615c2458cb7cff 100755 GIT binary patch literal 15400 zcmeHOeQ;dWb-%l7*|KC-E8Bo$6a0*AYzMTG{DlnI-j%iT6Ubm}IhZ77z0y8OOIEwe ze%LZoQxmZ?Z-g4B9nz%JPCfmjrJ4Sr$<(PQ36>0ur7%qqG!33KnP@1`T_B8UTI2Ag z{?5JkNN-o#Li0!e^4)pw-1EEVocsCiyZ64ce;8_Sb-P@GgInwp#QCZN5>j^|dbdbc zV@+bQ2#B@95DS4+;0nkTqAJGpsy5BEQpaYT<6(Ft9SNljUgSkm*|EX6^O$_UdbT`;CxKdKvD9ok-p zI{=RO01;iPSxT}L_P>#dQvCEX$$|!Cgz4Q17ED?10q9XVKWp%5!2>$Ka_v&7%grM7acJF0=mg1s*^_aFZQDW!k z+Ro*wz^rk^{!ZgXAegU8J2%cL&qFfbCBnBPAXT2ygK`bHrJ_olTdZ)INH;v62V2@V z*KPJU&{NqU!r`92WFnl-L{gb>ScGGVSVll3+?ukigV|Jfq|1_giflM}~ zpa-&6st9Ofx~Q$Ti~dwBk?9tFR$to6pyen+H%HrareARHEYY>Z4MJ z=1qPV5OCFj^ZZ8m3Ozmv(GfN2uUQ>HjQCzsD@;uztp5V>)b)i)$=^aeb$MY-@+*n=5I-XMrNqO!YRpra6Nb$UWIk4Dw8-LSgzx=Rizh(};etCaK+xVCdZ(4Kw!kJnk<23(HUw?kNA^xjob&C+^#?e8C z%(^iUbMUIywBIKv@eZmB&oN(s|b-8HM9AW$56o_eL*&-{5xKV&}st~7Ar6AuiS z_GR-zez)nmXukYO=K2|H)oiV1HSEA7@;|lncPNX<)*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3Ro8e!ZH{aS_KA9M{r!i!*6lNTOq+uYkD(@DMzBIO~^8LX7+H za=1RaX?a0;j&ae#D;zfCDw)J21`6ysPxA;cBVZfL@G+dsBrX-$=NVR?xA^GkLN_%P z9y3j548K*lOE5K9X!_zFlaxjW7H64YrhmV9!+gV}xmeg>f~$={ET*xH;j|?sLaq^z zA!7stZoy#|-CktRHTq;8ni0~6ATw_A(vhN#ImXvxv2tLB`?f?2irq2zLNhzqyBTir zL-*yU!S}tNyoDI+V5Twi{qC)$?qL)kD!cl-(^v9ALb=`cq7~+NSVgmPL_wZM7J~6fwSJ(hp zz7&x2%vMb*@Uv-x@Sz;bua_s}a6H#u~VwPJbzN~qNcy&FKr2?Ort^QrF+LK2*B ztmWnC2--8KmE4M!Vfkg|G%~rl-{}SBqo2XI89c?{#|Z1b04>Liub8A8CwMP#n$pPt zk7g<7-vYkabugp-Ou3AYdGG+BmXE}&PAtV)|*BeJ4T zmbcVDCi|bL!O~K0iiG9efwm?n5@$rhDo$D65sB!wXxy8;@SaMsW@ha-e8c;c368G1 zm1Pdm>|@g}n)R7eL2IurR--iV7#sNRXNINZ`nQyuvg6&q;$tXNQvMD-|BA zk&Pjdp8;hfD^2qMEWRbwx*DYT4GjJ~S+}~vI>pH;+i=h7mjp;kmNjJ-W0xMH)oWH; zunxj@lpa`91qo|>O_eDwQd8xl!bw_PS%upd;2-FCWtH{2#Y~o@>hqJgwoo9ndTo{U pYPsG~rFZ;pZDCe-kw; /* 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 */ @@ -112,25 +118,30 @@ int main ( int argc, char *argv[] ) break; } } + - /* draw the background */ - SDL_BlitSurface(bg, NULL, screen, NULL); + /* render the background */ + SDL_RenderCopy(renderer, background_texture, NULL, NULL); - /* Blit top_image to the screen */ - SDL_BlitSurface(top_image, &src, screen, &dest); + /* Render entire top_image to center of screen */ + top_image_dest.x = (screen_width / 2) - (top_image_width / 2); + top_image_dest.y = (screen_width / 2) - (top_image_height / 2); + top_image_dest.w = top_image_width; + top_image_dest.h = top_image_height; + SDL_RenderCopy(renderer, top_image, NULL, &top_image_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); + /* Render here */ + SDL_RenderPresent(renderer); + } /* cleanup SDL */ + if (renderer) SDL_DestroyRenderer(renderer); + if (screen) SDL_DestroyWindow(screen); + if (background_texture) SDL_DestroyTexture(background_texture); + if (top_image) SDL_DestroyTexture(top_image); + SDL_Quit(); return 0; + } diff --git a/sdl/whatever/whateverSDL1.c b/sdl/whatever/whateverSDL1.c new file mode 100644 index 0000000..34f351f --- /dev/null +++ b/sdl/whatever/whateverSDL1.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; +}