├── 01_hello_SDL ├── 01_hello_SDL.cpp ├── Makefile ├── assets │ └── place_holder.txt └── readme.txt ├── 02_getting_an_image_on_the_screen ├── 02_getting_an_image_on_the_screen.cpp ├── Makefile ├── assets │ └── hello_world.bmp └── readme.txt ├── 03_event_driven_programming ├── 03_event_driven_programming.cpp ├── Makefile ├── assets │ └── x.bmp └── readme.txt ├── 04_key_presses ├── 04_key_presses.cpp ├── Makefile ├── assets │ ├── down.bmp │ ├── left.bmp │ ├── press.bmp │ ├── right.bmp │ └── up.bmp └── readme.txt ├── 05_optimized_surface_loading_and_soft_stretching ├── 05_optimized_surface_loading_and_soft_stretching.cpp ├── Makefile ├── assets │ └── stretch.bmp └── readme.txt ├── 06_extension_libraries_and_loading_other_image_formats ├── 06_extension_libraries_and_loading_other_image_formats.cpp ├── Makefile ├── assets │ └── loaded.png └── readme.txt ├── 07_texture_loading_and_rendering ├── 07_texture_loading_and_rendering.cpp ├── Makefile ├── assets │ └── texture.png └── readme.txt ├── 08_geometry_rendering ├── 08_geometry_rendering.cpp ├── Makefile ├── assets │ └── place_holder.txt └── readme.txt ├── 09_the_viewport ├── 09_the_viewport.cpp ├── Makefile ├── assets │ └── viewport.png └── readme.txt ├── 10_color_keying ├── 10_color_keying.cpp ├── Makefile ├── assets │ ├── background.png │ └── foo.png └── readme.txt ├── 11_clip_rendering_and_sprite_sheets ├── 11_clip_rendering_and_sprite_sheets.cpp ├── Makefile ├── assets │ └── dots.png └── readme.txt ├── 12_color_modulation ├── 12_color_modulation.cpp ├── Makefile ├── assets │ └── colors.png └── readme.txt ├── 13_alpha_blending ├── 13_alpha_blending.cpp ├── Makefile ├── assets │ ├── fadein.png │ └── fadeout.png └── readme.txt ├── 14_animated_sprites_and_vsync ├── 14_animated_sprites_and_vsync.cpp ├── Makefile ├── assets │ └── foo.png └── readme.txt ├── 15_rotation_and_flipping ├── 15_rotation_and_flipping.cpp ├── Makefile ├── assets │ └── arrow.png └── readme.txt ├── 16_true_type_fonts ├── 16_true_type_fonts.cpp ├── Makefile ├── assets │ └── lazy.ttf └── readme.txt ├── 17_mouse_events ├── 17_mouse_events.cpp ├── Makefile ├── assets │ └── button.png └── readme.txt ├── 18_key_states ├── 18_key_states.cpp ├── Makefile ├── assets │ ├── down.png │ ├── left.png │ ├── press.png │ ├── right.png │ └── up.png └── readme.txt ├── 19_gamepads_and_joysticks ├── 19_gamepads_and_joysticks.cpp ├── Makefile ├── assets │ └── arrow.png └── readme.txt ├── 20_force_feedback ├── 20_force_feedback.cpp ├── Makefile ├── assets │ └── splash.png └── readme.txt ├── 21_sound_effects_and_music ├── 21_sound_effects_and_music.cpp ├── Makefile ├── assets │ ├── beat.wav │ ├── high.wav │ ├── low.wav │ ├── medium.wav │ ├── prompt.png │ └── scratch.wav └── readme.txt ├── 22_timing ├── 22_timing.cpp ├── Makefile ├── assets │ └── lazy.ttf └── readme.txt ├── 23_advanced_timers ├── 23_advanced_timers.cpp ├── Makefile ├── assets │ └── lazy.ttf └── readme.txt ├── 24_calculating_frame_rate ├── 24_calculating_frame_rate.cpp ├── Makefile ├── assets │ └── lazy.ttf └── readme.txt ├── 25_capping_frame_rate ├── 25_capping_frame_rate.cpp ├── Makefile ├── assets │ └── lazy.ttf └── readme.txt ├── 26_motion ├── 26_motion.cpp ├── Makefile ├── assets │ └── dot.bmp └── readme.txt ├── 27_collision_detection ├── 27_collision_detection.cpp ├── Makefile ├── assets │ └── dot.bmp └── readme.txt ├── 28_per-pixel_collision_detection ├── 28_per-pixel_collision_detection.cpp ├── Makefile ├── assets │ └── dot.bmp └── readme.txt ├── 29_circular_collision_detection ├── 29_circular_collision_detection.cpp ├── Makefile ├── assets │ └── dot.bmp └── readme.txt ├── 30_scrolling ├── 30_scrolling.cpp ├── Makefile ├── assets │ ├── bg.png │ └── dot.bmp └── readme.txt ├── 31_scrolling_backgrounds ├── 31_scrolling_backgrounds.cpp ├── Makefile ├── assets │ ├── bg.png │ └── dot.bmp └── readme.txt ├── 32_text_input_and_clipboard_handling ├── 32_text_input_and_clipboard_handling.cpp ├── Makefile ├── assets │ └── lazy.ttf └── readme.txt ├── 33_file_reading_and_writing ├── 33_file_reading_and_writing.cpp ├── Makefile ├── assets │ ├── lazy.ttf │ └── nums.bin └── readme.txt ├── 35_window_events ├── 35_window_events.cpp ├── Makefile ├── assets │ └── window.png └── readme.txt ├── 36_multiple_windows ├── 36_multiple_windows.cpp ├── Makefile ├── assets │ └── place_holder.txt └── readme.txt ├── 37_multiple_displays ├── 37_multiple_displays.cpp ├── Makefile ├── assets │ └── place_holder.txt └── readme.txt ├── 38_particle_engines ├── 38_particle_engines.cpp ├── Makefile ├── assets │ ├── blue.bmp │ ├── dot.bmp │ ├── green.bmp │ ├── red.bmp │ └── shimmer.bmp └── readme.txt ├── 39_tiling ├── 39_tiling.cpp ├── Makefile ├── assets │ ├── dot.bmp │ ├── lazy.map │ └── tiles.png └── readme.txt ├── 40_texture_manipulation ├── 40_texture_manipulation.cpp ├── Makefile ├── assets │ └── foo.png └── readme.txt ├── 41_bitmap_fonts ├── 41_bitmap_fonts.cpp ├── Makefile ├── assets │ └── lazyfont.png └── readme.txt ├── 42_texture_streaming ├── 42_texture_streaming.cpp ├── Makefile ├── assets │ ├── foo_walk_0.png │ ├── foo_walk_1.png │ ├── foo_walk_2.png │ └── foo_walk_3.png └── readme.txt ├── 43_render_to_texture ├── 43_render_to_texture.cpp ├── Makefile ├── assets │ └── place_holder.txt └── readme.txt ├── 44_frame_independent_movement ├── 44_frame_independent_movement.cpp ├── Makefile ├── assets │ └── dot.bmp └── readme.txt ├── 45_timer_callbacks ├── 45_timer_callbacks.cpp ├── Makefile ├── assets │ └── splash.png └── readme.txt ├── 46_multithreading ├── 46_multithreading.cpp ├── Makefile ├── assets │ └── splash.png └── readme.txt ├── 47_semaphores ├── 47_semaphores.cpp ├── Makefile ├── assets │ └── splash.png └── readme.txt ├── 48_atomic_operations ├── 48_atomic_operations.cpp ├── Makefile ├── assets │ └── splash.png └── readme.txt ├── 49_mutexes_and_conditions ├── 49_mutexes_and_conditions.cpp ├── Makefile ├── assets │ └── splash.png └── readme.txt ├── 50_SDL_and_opengl_2 ├── 50_SDL_and_opengl_2.cpp ├── Makefile ├── assets │ └── place_holder.txt └── readme.txt ├── 51_SDL_and_modern_opengl ├── 51_SDL_and_modern_opengl.cpp ├── Makefile ├── assets │ └── place_holder.txt └── readme.txt ├── 52_hello_mobile ├── 52_hello_mobile.cpp ├── Makefile ├── assets │ └── hello.bmp └── readme.txt ├── 53_extensions_and_changing_orientation ├── 53_extensions_and_changing_orientation.cpp ├── Makefile ├── assets │ ├── landscape.png │ └── portrait.png └── readme.txt ├── 54_touches ├── 54_touches.cpp ├── Makefile ├── assets │ ├── touch_down.png │ ├── touch_motion.png │ └── touch_up.png └── readme.txt ├── 55_multitouch ├── 55_multitouch.cpp ├── Makefile ├── assets │ ├── pinch_close.png │ ├── pinch_open.png │ └── rotate.png └── readme.txt ├── Makefile ├── Makefile.Conf ├── README.md ├── docs ├── 01_hello_SDL │ ├── 01_hello_SDL.data │ ├── 01_hello_SDL.html │ ├── 01_hello_SDL.html.mem │ └── 01_hello_SDL.js ├── 02_getting_an_image_on_the_screen │ ├── 02_getting_an_image_on_the_screen.data │ ├── 02_getting_an_image_on_the_screen.html │ ├── 02_getting_an_image_on_the_screen.html.mem │ └── 02_getting_an_image_on_the_screen.js ├── 03_event_driven_programming │ ├── 03_event_driven_programming.data │ ├── 03_event_driven_programming.html │ ├── 03_event_driven_programming.html.mem │ └── 03_event_driven_programming.js ├── 04_key_presses │ ├── 04_key_presses.data │ ├── 04_key_presses.html │ ├── 04_key_presses.html.mem │ └── 04_key_presses.js ├── 05_optimized_surface_loading_and_soft_stretching │ ├── 05_optimized_surface_loading_and_soft_stretching.data │ ├── 05_optimized_surface_loading_and_soft_stretching.html │ ├── 05_optimized_surface_loading_and_soft_stretching.html.mem │ └── 05_optimized_surface_loading_and_soft_stretching.js ├── 06_extension_libraries_and_loading_other_image_formats │ ├── 06_extension_libraries_and_loading_other_image_formats.data │ ├── 06_extension_libraries_and_loading_other_image_formats.html │ ├── 06_extension_libraries_and_loading_other_image_formats.html.mem │ └── 06_extension_libraries_and_loading_other_image_formats.js ├── 07_texture_loading_and_rendering │ ├── 07_texture_loading_and_rendering.data │ ├── 07_texture_loading_and_rendering.html │ ├── 07_texture_loading_and_rendering.html.mem │ └── 07_texture_loading_and_rendering.js ├── 08_geometry_rendering │ ├── 08_geometry_rendering.data │ ├── 08_geometry_rendering.html │ ├── 08_geometry_rendering.html.mem │ └── 08_geometry_rendering.js ├── 09_the_viewport │ ├── 09_the_viewport.data │ ├── 09_the_viewport.html │ ├── 09_the_viewport.html.mem │ └── 09_the_viewport.js ├── 10_color_keying │ ├── 10_color_keying.data │ ├── 10_color_keying.html │ ├── 10_color_keying.html.mem │ └── 10_color_keying.js ├── 11_clip_rendering_and_sprite_sheets │ ├── 11_clip_rendering_and_sprite_sheets.data │ ├── 11_clip_rendering_and_sprite_sheets.html │ ├── 11_clip_rendering_and_sprite_sheets.html.mem │ └── 11_clip_rendering_and_sprite_sheets.js ├── 12_color_modulation │ ├── 12_color_modulation.data │ ├── 12_color_modulation.html │ ├── 12_color_modulation.html.mem │ └── 12_color_modulation.js ├── 13_alpha_blending │ ├── 13_alpha_blending.data │ ├── 13_alpha_blending.html │ ├── 13_alpha_blending.html.mem │ └── 13_alpha_blending.js ├── 14_animated_sprites_and_vsync │ ├── 14_animated_sprites_and_vsync.data │ ├── 14_animated_sprites_and_vsync.html │ ├── 14_animated_sprites_and_vsync.html.mem │ └── 14_animated_sprites_and_vsync.js ├── 15_rotation_and_flipping │ ├── 15_rotation_and_flipping.data │ ├── 15_rotation_and_flipping.html │ ├── 15_rotation_and_flipping.html.mem │ └── 15_rotation_and_flipping.js ├── 16_true_type_fonts │ ├── 16_true_type_fonts.data │ ├── 16_true_type_fonts.html │ ├── 16_true_type_fonts.html.mem │ └── 16_true_type_fonts.js ├── 17_mouse_events │ ├── 17_mouse_events.data │ ├── 17_mouse_events.html │ ├── 17_mouse_events.html.mem │ └── 17_mouse_events.js ├── 18_key_states │ ├── 18_key_states.data │ ├── 18_key_states.html │ ├── 18_key_states.html.mem │ └── 18_key_states.js ├── 19_gamepads_and_joysticks │ ├── 19_gamepads_and_joysticks.data │ ├── 19_gamepads_and_joysticks.html │ ├── 19_gamepads_and_joysticks.html.mem │ └── 19_gamepads_and_joysticks.js ├── 20_force_feedback │ ├── 20_force_feedback.data │ ├── 20_force_feedback.html │ ├── 20_force_feedback.html.mem │ └── 20_force_feedback.js ├── 22_timing │ ├── 22_timing.data │ ├── 22_timing.html │ ├── 22_timing.html.mem │ └── 22_timing.js ├── 23_advanced_timers │ ├── 23_advanced_timers.data │ ├── 23_advanced_timers.html │ ├── 23_advanced_timers.html.mem │ └── 23_advanced_timers.js ├── 24_calculating_frame_rate │ ├── 24_calculating_frame_rate.data │ ├── 24_calculating_frame_rate.html │ ├── 24_calculating_frame_rate.html.mem │ └── 24_calculating_frame_rate.js ├── 25_capping_frame_rate │ ├── 25_capping_frame_rate.data │ ├── 25_capping_frame_rate.html │ ├── 25_capping_frame_rate.html.mem │ └── 25_capping_frame_rate.js ├── 26_motion │ ├── 26_motion.data │ ├── 26_motion.html │ ├── 26_motion.html.mem │ └── 26_motion.js ├── 27_collision_detection │ ├── 27_collision_detection.data │ ├── 27_collision_detection.html │ ├── 27_collision_detection.html.mem │ └── 27_collision_detection.js ├── 28_per-pixel_collision_detection │ ├── 28_per-pixel_collision_detection.data │ ├── 28_per-pixel_collision_detection.html │ ├── 28_per-pixel_collision_detection.html.mem │ └── 28_per-pixel_collision_detection.js ├── 29_circular_collision_detection │ ├── 29_circular_collision_detection.data │ ├── 29_circular_collision_detection.html │ ├── 29_circular_collision_detection.html.mem │ └── 29_circular_collision_detection.js ├── 30_scrolling │ ├── 30_scrolling.data │ ├── 30_scrolling.html │ ├── 30_scrolling.html.mem │ └── 30_scrolling.js ├── 31_scrolling_backgrounds │ ├── 31_scrolling_backgrounds.data │ ├── 31_scrolling_backgrounds.html │ ├── 31_scrolling_backgrounds.html.mem │ └── 31_scrolling_backgrounds.js ├── 32_text_input_and_clipboard_handling │ ├── 32_text_input_and_clipboard_handling.data │ ├── 32_text_input_and_clipboard_handling.html │ ├── 32_text_input_and_clipboard_handling.html.mem │ └── 32_text_input_and_clipboard_handling.js ├── 33_file_reading_and_writing │ ├── 33_file_reading_and_writing.data │ ├── 33_file_reading_and_writing.html │ ├── 33_file_reading_and_writing.html.mem │ └── 33_file_reading_and_writing.js ├── 35_window_events │ ├── 35_window_events.data │ ├── 35_window_events.html │ ├── 35_window_events.html.mem │ └── 35_window_events.js ├── 36_multiple_windows │ ├── 36_multiple_windows.data │ ├── 36_multiple_windows.html │ ├── 36_multiple_windows.html.mem │ └── 36_multiple_windows.js ├── 37_multiple_displays │ ├── 37_multiple_displays.data │ ├── 37_multiple_displays.html │ ├── 37_multiple_displays.html.mem │ └── 37_multiple_displays.js ├── 38_particle_engines │ ├── 38_particle_engines.data │ ├── 38_particle_engines.html │ ├── 38_particle_engines.html.mem │ └── 38_particle_engines.js ├── 39_tiling │ ├── 39_tiling.data │ ├── 39_tiling.html │ ├── 39_tiling.html.mem │ └── 39_tiling.js ├── 40_texture_manipulation │ ├── 40_texture_manipulation.data │ ├── 40_texture_manipulation.html │ ├── 40_texture_manipulation.html.mem │ └── 40_texture_manipulation.js ├── 41_bitmap_fonts │ ├── 41_bitmap_fonts.data │ ├── 41_bitmap_fonts.html │ ├── 41_bitmap_fonts.html.mem │ └── 41_bitmap_fonts.js ├── 42_texture_streaming │ ├── 42_texture_streaming.data │ ├── 42_texture_streaming.html │ ├── 42_texture_streaming.html.mem │ └── 42_texture_streaming.js ├── 43_render_to_texture │ ├── 43_render_to_texture.data │ ├── 43_render_to_texture.html │ ├── 43_render_to_texture.html.mem │ └── 43_render_to_texture.js ├── 44_frame_independent_movement │ ├── 44_frame_independent_movement.data │ ├── 44_frame_independent_movement.html │ ├── 44_frame_independent_movement.html.mem │ └── 44_frame_independent_movement.js ├── 45_timer_callbacks │ ├── 45_timer_callbacks.data │ ├── 45_timer_callbacks.html │ ├── 45_timer_callbacks.html.mem │ └── 45_timer_callbacks.js ├── 46_multithreading │ ├── 46_multithreading.data │ ├── 46_multithreading.html │ ├── 46_multithreading.html.mem │ └── 46_multithreading.js ├── 47_semaphores │ ├── 47_semaphores.data │ ├── 47_semaphores.html │ ├── 47_semaphores.html.mem │ └── 47_semaphores.js ├── 48_atomic_operations │ ├── 48_atomic_operations.data │ ├── 48_atomic_operations.html │ ├── 48_atomic_operations.html.mem │ └── 48_atomic_operations.js ├── 49_mutexes_and_conditions │ ├── 49_mutexes_and_conditions.data │ ├── 49_mutexes_and_conditions.html │ ├── 49_mutexes_and_conditions.html.mem │ └── 49_mutexes_and_conditions.js ├── 50_SDL_and_opengl_2 │ ├── 50_SDL_and_opengl_2.data │ ├── 50_SDL_and_opengl_2.html │ ├── 50_SDL_and_opengl_2.html.mem │ └── 50_SDL_and_opengl_2.js ├── 51_SDL_and_modern_opengl │ ├── 51_SDL_and_modern_opengl.data │ ├── 51_SDL_and_modern_opengl.html │ ├── 51_SDL_and_modern_opengl.html.mem │ └── 51_SDL_and_modern_opengl.js ├── 52_hello_mobile │ ├── 52_hello_mobile.data │ ├── 52_hello_mobile.html │ ├── 52_hello_mobile.html.mem │ └── 52_hello_mobile.js ├── 53_extensions_and_changing_orientation │ ├── 53_extensions_and_changing_orientation.data │ ├── 53_extensions_and_changing_orientation.html │ ├── 53_extensions_and_changing_orientation.html.mem │ └── 53_extensions_and_changing_orientation.js ├── 54_touches │ ├── 54_touches.data │ ├── 54_touches.html │ ├── 54_touches.html.mem │ └── 54_touches.js ├── 55_multitouch │ ├── 55_multitouch.data │ ├── 55_multitouch.html │ ├── 55_multitouch.html.mem │ └── 55_multitouch.js └── index.html └── make_help.sh /01_hello_SDL/01_hello_SDL.cpp: -------------------------------------------------------------------------------- 1 | /*This source code copyrighted by Lazy Foo' Productions (2004-2015) 2 | and may not be redistributed without written permission.*/ 3 | 4 | //Using SDL and standard IO 5 | #include 6 | #include 7 | 8 | //Screen dimension constants 9 | const int SCREEN_WIDTH = 640; 10 | const int SCREEN_HEIGHT = 480; 11 | 12 | int main( int argc, char* args[] ) 13 | { 14 | //The window we'll be rendering to 15 | SDL_Window* window = NULL; 16 | 17 | //The surface contained by the window 18 | SDL_Surface* screenSurface = NULL; 19 | 20 | //Initialize SDL 21 | if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) 22 | { 23 | printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() ); 24 | } 25 | else 26 | { 27 | //Create window 28 | window = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN ); 29 | if( window == NULL ) 30 | { 31 | printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() ); 32 | } 33 | else 34 | { 35 | //Get window surface 36 | screenSurface = SDL_GetWindowSurface( window ); 37 | 38 | //Fill the surface white 39 | SDL_FillRect( screenSurface, NULL, SDL_MapRGB( screenSurface->format, 0xFF, 0xFF, 0xFF ) ); 40 | 41 | //Update the surface 42 | SDL_UpdateWindowSurface( window ); 43 | 44 | //Wait two seconds 45 | SDL_Delay( 2000 ); 46 | } 47 | } 48 | 49 | //Destroy window 50 | SDL_DestroyWindow( window ); 51 | 52 | //Quit SDL subsystems 53 | SDL_Quit(); 54 | 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /01_hello_SDL/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /01_hello_SDL/assets/place_holder.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/01_hello_SDL/assets/place_holder.txt -------------------------------------------------------------------------------- /01_hello_SDL/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | 12 | *nix: 13 | SDL2 14 | -------------------------------------------------------------------------------- /02_getting_an_image_on_the_screen/02_getting_an_image_on_the_screen.cpp: -------------------------------------------------------------------------------- 1 | /*This source code copyrighted by Lazy Foo' Productions (2004-2015) 2 | and may not be redistributed without written permission.*/ 3 | 4 | //Using SDL and standard IO 5 | #include 6 | #include 7 | 8 | //Screen dimension constants 9 | const int SCREEN_WIDTH = 640; 10 | const int SCREEN_HEIGHT = 480; 11 | 12 | //Starts up SDL and creates window 13 | bool init(); 14 | 15 | //Loads media 16 | bool loadMedia(); 17 | 18 | //Frees media and shuts down SDL 19 | void close(); 20 | 21 | //The window we'll be rendering to 22 | SDL_Window* gWindow = NULL; 23 | 24 | //The surface contained by the window 25 | SDL_Surface* gScreenSurface = NULL; 26 | 27 | //The image we will load and show on the screen 28 | SDL_Surface* gHelloWorld = NULL; 29 | 30 | bool init() 31 | { 32 | //Initialization flag 33 | bool success = true; 34 | 35 | //Initialize SDL 36 | if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) 37 | { 38 | printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() ); 39 | success = false; 40 | } 41 | else 42 | { 43 | //Create window 44 | gWindow = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN ); 45 | if( gWindow == NULL ) 46 | { 47 | printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() ); 48 | success = false; 49 | } 50 | else 51 | { 52 | //Get window surface 53 | gScreenSurface = SDL_GetWindowSurface( gWindow ); 54 | } 55 | } 56 | 57 | return success; 58 | } 59 | 60 | bool loadMedia() 61 | { 62 | //Loading success flag 63 | bool success = true; 64 | 65 | //Load splash image 66 | gHelloWorld = SDL_LoadBMP( "assets/hello_world.bmp" ); 67 | if( gHelloWorld == NULL ) 68 | { 69 | printf( "Unable to load image %s! SDL Error: %s\n", "assets/hello_world.bmp", SDL_GetError() ); 70 | success = false; 71 | } 72 | 73 | return success; 74 | } 75 | 76 | void close() 77 | { 78 | //Deallocate surface 79 | SDL_FreeSurface( gHelloWorld ); 80 | gHelloWorld = NULL; 81 | 82 | //Destroy window 83 | SDL_DestroyWindow( gWindow ); 84 | gWindow = NULL; 85 | 86 | //Quit SDL subsystems 87 | SDL_Quit(); 88 | } 89 | 90 | int main( int argc, char* args[] ) 91 | { 92 | //Start up SDL and create window 93 | if( !init() ) 94 | { 95 | printf( "Failed to initialize!\n" ); 96 | } 97 | else 98 | { 99 | //Load media 100 | if( !loadMedia() ) 101 | { 102 | printf( "Failed to load media!\n" ); 103 | } 104 | else 105 | { 106 | //Apply the image 107 | SDL_BlitSurface( gHelloWorld, NULL, gScreenSurface, NULL ); 108 | 109 | //Update the surface 110 | SDL_UpdateWindowSurface( gWindow ); 111 | 112 | //Wait two seconds 113 | SDL_Delay( 2000 ); 114 | } 115 | } 116 | 117 | //Free resources and close SDL 118 | close(); 119 | 120 | return 0; 121 | } 122 | -------------------------------------------------------------------------------- /02_getting_an_image_on_the_screen/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /02_getting_an_image_on_the_screen/assets/hello_world.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/02_getting_an_image_on_the_screen/assets/hello_world.bmp -------------------------------------------------------------------------------- /02_getting_an_image_on_the_screen/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | 12 | *nix: 13 | SDL2 14 | -------------------------------------------------------------------------------- /03_event_driven_programming/03_event_driven_programming.cpp: -------------------------------------------------------------------------------- 1 | /*This source code copyrighted by Lazy Foo' Productions (2004-2015) 2 | and may not be redistributed without written permission.*/ 3 | 4 | //Using SDL and standard IO 5 | #include 6 | #include 7 | #ifdef _JS 8 | #include 9 | #endif 10 | //Screen dimension constants 11 | const int SCREEN_WIDTH = 640; 12 | const int SCREEN_HEIGHT = 480; 13 | 14 | //Starts up SDL and creates window 15 | bool init(); 16 | 17 | //Loads media 18 | bool loadMedia(); 19 | 20 | //Frees media and shuts down SDL 21 | void close(); 22 | 23 | //The window we'll be rendering to 24 | SDL_Window* gWindow = NULL; 25 | 26 | //The surface contained by the window 27 | SDL_Surface* gScreenSurface = NULL; 28 | 29 | //The image we will load and show on the screen 30 | SDL_Surface* gXOut = NULL; 31 | 32 | bool init() 33 | { 34 | //Initialization flag 35 | bool success = true; 36 | 37 | //Initialize SDL 38 | if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) 39 | { 40 | printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() ); 41 | success = false; 42 | } 43 | else 44 | { 45 | //Create window 46 | gWindow = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN ); 47 | if( gWindow == NULL ) 48 | { 49 | printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() ); 50 | success = false; 51 | } 52 | else 53 | { 54 | //Get window surface 55 | gScreenSurface = SDL_GetWindowSurface( gWindow ); 56 | } 57 | } 58 | 59 | return success; 60 | } 61 | 62 | bool loadMedia() 63 | { 64 | //Loading success flag 65 | bool success = true; 66 | 67 | //Load splash image 68 | gXOut = SDL_LoadBMP( "assets/x.bmp" ); 69 | if( gXOut == NULL ) 70 | { 71 | printf( "Unable to load image %s! SDL Error: %s\n", "assets/x.bmp", SDL_GetError() ); 72 | success = false; 73 | } 74 | 75 | return success; 76 | } 77 | 78 | void close() 79 | { 80 | //Deallocate surface 81 | SDL_FreeSurface( gXOut ); 82 | gXOut = NULL; 83 | 84 | //Destroy window 85 | SDL_DestroyWindow( gWindow ); 86 | gWindow = NULL; 87 | 88 | //Quit SDL subsystems 89 | SDL_Quit(); 90 | } 91 | 92 | //Main loop flag 93 | bool quit = false; 94 | 95 | void loop_handler(void*) 96 | { 97 | //Event handler 98 | SDL_Event e; 99 | //Handle events on queue 100 | while( SDL_PollEvent( &e ) != 0 ) 101 | { 102 | //User requests quit 103 | if( e.type == SDL_QUIT ) 104 | { 105 | quit = true; 106 | } 107 | } 108 | 109 | //Apply the image 110 | SDL_BlitSurface( gXOut, NULL, gScreenSurface, NULL ); 111 | 112 | //Update the surface 113 | SDL_UpdateWindowSurface( gWindow ); 114 | } 115 | 116 | 117 | int main( int argc, char* args[] ) 118 | { 119 | //Start up SDL and create window 120 | if( !init() ) 121 | { 122 | printf( "Failed to initialize!\n" ); 123 | } 124 | else 125 | { 126 | //Load media 127 | if( !loadMedia() ) 128 | { 129 | printf( "Failed to load media!\n" ); 130 | } 131 | else 132 | { 133 | 134 | #ifdef _JS 135 | 136 | emscripten_set_main_loop_arg(loop_handler, NULL, -1, 1); 137 | #else 138 | //While application is running 139 | while( !quit ) 140 | { 141 | loop_handler(NULL); 142 | } 143 | #endif 144 | 145 | 146 | } 147 | } 148 | 149 | //Free resources and close SDL 150 | close(); 151 | 152 | return 0; 153 | } 154 | 155 | 156 | 157 | 158 | -------------------------------------------------------------------------------- /03_event_driven_programming/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /03_event_driven_programming/assets/x.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/03_event_driven_programming/assets/x.bmp -------------------------------------------------------------------------------- /03_event_driven_programming/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | 12 | *nix: 13 | SDL2 14 | -------------------------------------------------------------------------------- /04_key_presses/04_key_presses.cpp: -------------------------------------------------------------------------------- 1 | /*This source code copyrighted by Lazy Foo' Productions (2004-2015) 2 | and may not be redistributed without written permission.*/ 3 | 4 | //Using SDL, standard IO, and strings 5 | #include 6 | #include 7 | #include 8 | #ifdef _JS 9 | #include 10 | #endif 11 | //Screen dimension constants 12 | const int SCREEN_WIDTH = 640; 13 | const int SCREEN_HEIGHT = 480; 14 | 15 | //Key press surfaces constants 16 | enum KeyPressSurfaces 17 | { 18 | KEY_PRESS_SURFACE_DEFAULT, 19 | KEY_PRESS_SURFACE_UP, 20 | KEY_PRESS_SURFACE_DOWN, 21 | KEY_PRESS_SURFACE_LEFT, 22 | KEY_PRESS_SURFACE_RIGHT, 23 | KEY_PRESS_SURFACE_TOTAL 24 | }; 25 | 26 | //Starts up SDL and creates window 27 | bool init(); 28 | 29 | //Loads media 30 | bool loadMedia(); 31 | 32 | //Frees media and shuts down SDL 33 | void close(); 34 | 35 | //Loads individual image 36 | SDL_Surface* loadSurface( std::string path ); 37 | 38 | //The window we'll be rendering to 39 | SDL_Window* gWindow = NULL; 40 | 41 | //The surface contained by the window 42 | SDL_Surface* gScreenSurface = NULL; 43 | 44 | //The images that correspond to a keypress 45 | SDL_Surface* gKeyPressSurfaces[ KEY_PRESS_SURFACE_TOTAL ]; 46 | 47 | //Current displayed image 48 | SDL_Surface* gCurrentSurface = NULL; 49 | 50 | bool init() 51 | { 52 | //Initialization flag 53 | bool success = true; 54 | 55 | //Initialize SDL 56 | if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) 57 | { 58 | printf( "SDL could not initialize! SDL Error: %s\n", SDL_GetError() ); 59 | success = false; 60 | } 61 | else 62 | { 63 | //Create window 64 | gWindow = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN ); 65 | if( gWindow == NULL ) 66 | { 67 | printf( "Window could not be created! SDL Error: %s\n", SDL_GetError() ); 68 | success = false; 69 | } 70 | else 71 | { 72 | //Get window surface 73 | gScreenSurface = SDL_GetWindowSurface( gWindow ); 74 | } 75 | } 76 | 77 | return success; 78 | } 79 | 80 | bool loadMedia() 81 | { 82 | //Loading success flag 83 | bool success = true; 84 | 85 | //Load default surface 86 | gKeyPressSurfaces[ KEY_PRESS_SURFACE_DEFAULT ] = loadSurface( "assets/press.bmp" ); 87 | if( gKeyPressSurfaces[ KEY_PRESS_SURFACE_DEFAULT ] == NULL ) 88 | { 89 | printf( "Failed to load default image!\n" ); 90 | success = false; 91 | } 92 | 93 | //Load up surface 94 | gKeyPressSurfaces[ KEY_PRESS_SURFACE_UP ] = loadSurface( "assets/up.bmp" ); 95 | if( gKeyPressSurfaces[ KEY_PRESS_SURFACE_UP ] == NULL ) 96 | { 97 | printf( "Failed to load up image!\n" ); 98 | success = false; 99 | } 100 | 101 | //Load down surface 102 | gKeyPressSurfaces[ KEY_PRESS_SURFACE_DOWN ] = loadSurface( "assets/down.bmp" ); 103 | if( gKeyPressSurfaces[ KEY_PRESS_SURFACE_DOWN ] == NULL ) 104 | { 105 | printf( "Failed to load down image!\n" ); 106 | success = false; 107 | } 108 | 109 | //Load left surface 110 | gKeyPressSurfaces[ KEY_PRESS_SURFACE_LEFT ] = loadSurface( "assets/left.bmp" ); 111 | if( gKeyPressSurfaces[ KEY_PRESS_SURFACE_LEFT ] == NULL ) 112 | { 113 | printf( "Failed to load left image!\n" ); 114 | success = false; 115 | } 116 | 117 | //Load right surface 118 | gKeyPressSurfaces[ KEY_PRESS_SURFACE_RIGHT ] = loadSurface( "assets/right.bmp" ); 119 | if( gKeyPressSurfaces[ KEY_PRESS_SURFACE_RIGHT ] == NULL ) 120 | { 121 | printf( "Failed to load right image!\n" ); 122 | success = false; 123 | } 124 | 125 | return success; 126 | } 127 | 128 | void close() 129 | { 130 | //Deallocate surfaces 131 | for( int i = 0; i < KEY_PRESS_SURFACE_TOTAL; ++i ) 132 | { 133 | SDL_FreeSurface( gKeyPressSurfaces[ i ] ); 134 | gKeyPressSurfaces[ i ] = NULL; 135 | } 136 | 137 | //Destroy window 138 | SDL_DestroyWindow( gWindow ); 139 | gWindow = NULL; 140 | 141 | //Quit SDL subsystems 142 | SDL_Quit(); 143 | } 144 | 145 | SDL_Surface* loadSurface( std::string path ) 146 | { 147 | //Load image at specified path 148 | SDL_Surface* loadedSurface = SDL_LoadBMP( path.c_str() ); 149 | if( loadedSurface == NULL ) 150 | { 151 | printf( "Unable to load image %s! SDL Error: %s\n", path.c_str(), SDL_GetError() ); 152 | } 153 | 154 | return loadedSurface; 155 | } 156 | 157 | 158 | //Main loop flag 159 | bool quit = false; 160 | 161 | void loop_handler(void*) 162 | { 163 | //Event handler 164 | SDL_Event e; 165 | //Handle events on queue 166 | while( SDL_PollEvent( &e ) != 0 ) 167 | { 168 | //User requests quit 169 | if( e.type == SDL_QUIT ) 170 | { 171 | quit = true; 172 | } 173 | //User presses a key 174 | else if( e.type == SDL_KEYDOWN ) 175 | { 176 | //Select surfaces based on key press 177 | switch( e.key.keysym.sym ) 178 | { 179 | case SDLK_UP: 180 | gCurrentSurface = gKeyPressSurfaces[ KEY_PRESS_SURFACE_UP ]; 181 | break; 182 | case SDLK_DOWN: 183 | gCurrentSurface = gKeyPressSurfaces[ KEY_PRESS_SURFACE_DOWN ]; 184 | break; 185 | case SDLK_LEFT: 186 | gCurrentSurface = gKeyPressSurfaces[ KEY_PRESS_SURFACE_LEFT ]; 187 | break; 188 | case SDLK_RIGHT: 189 | gCurrentSurface = gKeyPressSurfaces[ KEY_PRESS_SURFACE_RIGHT ]; 190 | break; 191 | default: 192 | gCurrentSurface = gKeyPressSurfaces[ KEY_PRESS_SURFACE_DEFAULT ]; 193 | break; 194 | } 195 | } 196 | } 197 | 198 | //Apply the image 199 | SDL_BlitSurface( gCurrentSurface , NULL, gScreenSurface, NULL ); 200 | 201 | //Update the surface 202 | SDL_UpdateWindowSurface( gWindow ); 203 | } 204 | 205 | int main( int argc, char* args[] ) 206 | { 207 | //Start up SDL and create window 208 | if( !init() ) 209 | { 210 | printf( "Failed to initialize!\n" ); 211 | } 212 | else 213 | { 214 | //Load media 215 | if( !loadMedia() ) 216 | { 217 | printf( "Failed to load media!\n" ); 218 | } 219 | else 220 | { 221 | 222 | //Set default current surface 223 | gCurrentSurface = gKeyPressSurfaces[ KEY_PRESS_SURFACE_DEFAULT ]; 224 | 225 | #ifdef _JS 226 | 227 | emscripten_set_main_loop_arg(loop_handler, NULL, -1, 1); 228 | #else 229 | //While application is running 230 | while( !quit ) 231 | { 232 | loop_handler(NULL); 233 | } 234 | #endif 235 | 236 | } 237 | } 238 | 239 | //Free resources and close SDL 240 | close(); 241 | 242 | return 0; 243 | } 244 | -------------------------------------------------------------------------------- /04_key_presses/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /04_key_presses/assets/down.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/04_key_presses/assets/down.bmp -------------------------------------------------------------------------------- /04_key_presses/assets/left.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/04_key_presses/assets/left.bmp -------------------------------------------------------------------------------- /04_key_presses/assets/press.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/04_key_presses/assets/press.bmp -------------------------------------------------------------------------------- /04_key_presses/assets/right.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/04_key_presses/assets/right.bmp -------------------------------------------------------------------------------- /04_key_presses/assets/up.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/04_key_presses/assets/up.bmp -------------------------------------------------------------------------------- /04_key_presses/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | 12 | *nix: 13 | SDL2 14 | -------------------------------------------------------------------------------- /05_optimized_surface_loading_and_soft_stretching/05_optimized_surface_loading_and_soft_stretching.cpp: -------------------------------------------------------------------------------- 1 | /*This source code copyrighted by Lazy Foo' Productions (2004-2015) 2 | and may not be redistributed without written permission.*/ 3 | 4 | //Using SDL, standard IO, and strings 5 | #include 6 | #include 7 | #include 8 | #ifdef _JS 9 | #include 10 | #endif 11 | //Screen dimension constants 12 | const int SCREEN_WIDTH = 640; 13 | const int SCREEN_HEIGHT = 480; 14 | 15 | //Starts up SDL and creates window 16 | bool init(); 17 | 18 | //Loads media 19 | bool loadMedia(); 20 | 21 | //Frees media and shuts down SDL 22 | void close(); 23 | 24 | //Loads individual image 25 | SDL_Surface* loadSurface( std::string path ); 26 | 27 | //The window we'll be rendering to 28 | SDL_Window* gWindow = NULL; 29 | 30 | //The surface contained by the window 31 | SDL_Surface* gScreenSurface = NULL; 32 | 33 | //Current displayed image 34 | SDL_Surface* gStretchedSurface = NULL; 35 | 36 | bool init() 37 | { 38 | //Initialization flag 39 | bool success = true; 40 | 41 | //Initialize SDL 42 | if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) 43 | { 44 | printf( "SDL could not initialize! SDL Error: %s\n", SDL_GetError() ); 45 | success = false; 46 | } 47 | else 48 | { 49 | //Create window 50 | gWindow = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN ); 51 | if( gWindow == NULL ) 52 | { 53 | printf( "Window could not be created! SDL Error: %s\n", SDL_GetError() ); 54 | success = false; 55 | } 56 | else 57 | { 58 | //Get window surface 59 | gScreenSurface = SDL_GetWindowSurface( gWindow ); 60 | } 61 | } 62 | 63 | return success; 64 | } 65 | 66 | bool loadMedia() 67 | { 68 | //Loading success flag 69 | bool success = true; 70 | 71 | //Load stretching surface 72 | gStretchedSurface = loadSurface( "assets/stretch.bmp" ); 73 | if( gStretchedSurface == NULL ) 74 | { 75 | printf( "Failed to load stretching image!\n" ); 76 | success = false; 77 | } 78 | 79 | return success; 80 | } 81 | 82 | void close() 83 | { 84 | //Free loaded image 85 | SDL_FreeSurface( gStretchedSurface ); 86 | gStretchedSurface = NULL; 87 | 88 | //Destroy window 89 | SDL_DestroyWindow( gWindow ); 90 | gWindow = NULL; 91 | 92 | //Quit SDL subsystems 93 | SDL_Quit(); 94 | } 95 | 96 | SDL_Surface* loadSurface( std::string path ) 97 | { 98 | //The final optimized image 99 | SDL_Surface* optimizedSurface = NULL; 100 | 101 | //Load image at specified path 102 | SDL_Surface* loadedSurface = SDL_LoadBMP( path.c_str() ); 103 | if( loadedSurface == NULL ) 104 | { 105 | printf( "Unable to load image %s! SDL Error: %s\n", path.c_str(), SDL_GetError() ); 106 | } 107 | else 108 | { 109 | //Convert surface to screen format 110 | optimizedSurface = SDL_ConvertSurface( loadedSurface, gScreenSurface->format, 0 ); 111 | if( optimizedSurface == NULL ) 112 | { 113 | printf( "Unable to optimize image %s! SDL Error: %s\n", path.c_str(), SDL_GetError() ); 114 | } 115 | 116 | //Get rid of old loaded surface 117 | SDL_FreeSurface( loadedSurface ); 118 | } 119 | 120 | return optimizedSurface; 121 | } 122 | 123 | 124 | //Main loop flag 125 | bool quit = false; 126 | 127 | void loop_handler(void*) 128 | { 129 | //Event handler 130 | SDL_Event e; 131 | //Handle events on queue 132 | while( SDL_PollEvent( &e ) != 0 ) 133 | { 134 | //User requests quit 135 | if( e.type == SDL_QUIT ) 136 | { 137 | quit = true; 138 | } 139 | } 140 | 141 | //Apply the image stretched 142 | SDL_Rect stretchRect; 143 | stretchRect.x = 0; 144 | stretchRect.y = 0; 145 | stretchRect.w = SCREEN_WIDTH; 146 | stretchRect.h = SCREEN_HEIGHT; 147 | SDL_BlitScaled( gStretchedSurface, NULL, gScreenSurface, &stretchRect ); 148 | 149 | //Update the surface 150 | SDL_UpdateWindowSurface( gWindow ); 151 | } 152 | 153 | int main( int argc, char* args[] ) 154 | { 155 | //Start up SDL and create window 156 | if( !init() ) 157 | { 158 | printf( "Failed to initialize!\n" ); 159 | } 160 | else 161 | { 162 | //Load media 163 | if( !loadMedia() ) 164 | { 165 | printf( "Failed to load media!\n" ); 166 | } 167 | else 168 | { 169 | #ifdef _JS 170 | 171 | emscripten_set_main_loop_arg(loop_handler, NULL, -1, 1); 172 | #else 173 | //While application is running 174 | while( !quit ) 175 | { 176 | loop_handler(NULL); 177 | } 178 | #endif 179 | //While application is running 180 | 181 | } 182 | } 183 | 184 | //Free resources and close SDL 185 | close(); 186 | 187 | return 0; 188 | } 189 | -------------------------------------------------------------------------------- /05_optimized_surface_loading_and_soft_stretching/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /05_optimized_surface_loading_and_soft_stretching/assets/stretch.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/05_optimized_surface_loading_and_soft_stretching/assets/stretch.bmp -------------------------------------------------------------------------------- /05_optimized_surface_loading_and_soft_stretching/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | 12 | *nix: 13 | SDL2 14 | -------------------------------------------------------------------------------- /06_extension_libraries_and_loading_other_image_formats/06_extension_libraries_and_loading_other_image_formats.cpp: -------------------------------------------------------------------------------- 1 | /*This source code copyrighted by Lazy Foo' Productions (2004-2015) 2 | and may not be redistributed without written permission.*/ 3 | 4 | //Using SDL, SDL_image, standard IO, and strings 5 | #include 6 | #include 7 | #include 8 | #include 9 | #ifdef _JS 10 | #include 11 | #endif 12 | 13 | //Screen dimension constants 14 | const int SCREEN_WIDTH = 640; 15 | const int SCREEN_HEIGHT = 480; 16 | 17 | //Starts up SDL and creates window 18 | bool init(); 19 | 20 | //Loads media 21 | bool loadMedia(); 22 | 23 | //Frees media and shuts down SDL 24 | void close(); 25 | 26 | //Loads individual image 27 | SDL_Surface* loadSurface( std::string path ); 28 | 29 | //The window we'll be rendering to 30 | SDL_Window* gWindow = NULL; 31 | 32 | //The surface contained by the window 33 | SDL_Surface* gScreenSurface = NULL; 34 | 35 | //Current displayed PNG image 36 | SDL_Surface* gPNGSurface = NULL; 37 | 38 | bool init() 39 | { 40 | //Initialization flag 41 | bool success = true; 42 | 43 | //Initialize SDL 44 | if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) 45 | { 46 | printf( "SDL could not initialize! SDL Error: %s\n", SDL_GetError() ); 47 | success = false; 48 | } 49 | else 50 | { 51 | //Create window 52 | gWindow = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN ); 53 | if( gWindow == NULL ) 54 | { 55 | printf( "Window could not be created! SDL Error: %s\n", SDL_GetError() ); 56 | success = false; 57 | } 58 | else 59 | { 60 | //Initialize PNG loading 61 | int imgFlags = IMG_INIT_PNG; 62 | if( !( IMG_Init( imgFlags ) & imgFlags ) ) 63 | { 64 | printf( "SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError() ); 65 | success = false; 66 | } 67 | else 68 | { 69 | //Get window surface 70 | gScreenSurface = SDL_GetWindowSurface( gWindow ); 71 | } 72 | } 73 | } 74 | 75 | return success; 76 | } 77 | 78 | bool loadMedia() 79 | { 80 | //Loading success flag 81 | bool success = true; 82 | 83 | //Load PNG surface 84 | gPNGSurface = loadSurface( "assets/loaded.png" ); 85 | if( gPNGSurface == NULL ) 86 | { 87 | printf( "Failed to load PNG image!\n" ); 88 | success = false; 89 | } 90 | 91 | return success; 92 | } 93 | 94 | void close() 95 | { 96 | //Free loaded image 97 | SDL_FreeSurface( gPNGSurface ); 98 | gPNGSurface = NULL; 99 | 100 | //Destroy window 101 | SDL_DestroyWindow( gWindow ); 102 | gWindow = NULL; 103 | 104 | //Quit SDL subsystems 105 | IMG_Quit(); 106 | SDL_Quit(); 107 | } 108 | 109 | SDL_Surface* loadSurface( std::string path ) 110 | { 111 | //The final optimized image 112 | SDL_Surface* optimizedSurface = NULL; 113 | 114 | //Load image at specified path 115 | SDL_Surface* loadedSurface = IMG_Load( path.c_str() ); 116 | if( loadedSurface == NULL ) 117 | { 118 | printf( "Unable to load image %s! SDL_image Error: %s\n", path.c_str(), IMG_GetError() ); 119 | } 120 | else 121 | { 122 | //Convert surface to screen format 123 | optimizedSurface = SDL_ConvertSurface( loadedSurface, gScreenSurface->format, 0); 124 | if( optimizedSurface == NULL ) 125 | { 126 | printf( "Unable to optimize image %s! SDL Error: %s\n", path.c_str(), SDL_GetError() ); 127 | } 128 | 129 | //Get rid of old loaded surface 130 | SDL_FreeSurface( loadedSurface ); 131 | } 132 | 133 | return optimizedSurface; 134 | } 135 | 136 | //Main loop flag 137 | bool quit = false; 138 | 139 | void loop_handler(void*) 140 | { 141 | //Event handler 142 | SDL_Event e; 143 | //Handle events on queue 144 | while( SDL_PollEvent( &e ) != 0 ) 145 | { 146 | //User requests quit 147 | if( e.type == SDL_QUIT ) 148 | { 149 | quit = true; 150 | } 151 | } 152 | 153 | //Apply the PNG image 154 | SDL_BlitSurface( gPNGSurface, NULL, gScreenSurface, NULL ); 155 | 156 | //Update the surface 157 | SDL_UpdateWindowSurface( gWindow ); 158 | } 159 | 160 | 161 | int main( int argc, char* args[] ) 162 | { 163 | //Start up SDL and create window 164 | if( !init() ) 165 | { 166 | printf( "Failed to initialize!\n" ); 167 | } 168 | else 169 | { 170 | //Load media 171 | if( !loadMedia() ) 172 | { 173 | printf( "Failed to load media!\n" ); 174 | } 175 | else 176 | { 177 | 178 | #ifdef _JS 179 | 180 | emscripten_set_main_loop_arg(loop_handler, NULL, -1, 1); 181 | #else 182 | //While application is running 183 | while( !quit ) 184 | { 185 | loop_handler(NULL); 186 | } 187 | #endif 188 | 189 | } 190 | } 191 | 192 | //Free resources and close SDL 193 | close(); 194 | 195 | return 0; 196 | } 197 | -------------------------------------------------------------------------------- /06_extension_libraries_and_loading_other_image_formats/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /06_extension_libraries_and_loading_other_image_formats/assets/loaded.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/06_extension_libraries_and_loading_other_image_formats/assets/loaded.png -------------------------------------------------------------------------------- /06_extension_libraries_and_loading_other_image_formats/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | 13 | *nix: 14 | SDL2 15 | SDL2_image 16 | -------------------------------------------------------------------------------- /07_texture_loading_and_rendering/07_texture_loading_and_rendering.cpp: -------------------------------------------------------------------------------- 1 | /*This source code copyrighted by Lazy Foo' Productions (2004-2015) 2 | and may not be redistributed without written permission.*/ 3 | 4 | //Using SDL, SDL_image, standard IO, and strings 5 | #include 6 | #include 7 | #include 8 | #include 9 | #ifdef _JS 10 | #include 11 | #endif 12 | 13 | //Screen dimension constants 14 | const int SCREEN_WIDTH = 640; 15 | const int SCREEN_HEIGHT = 480; 16 | 17 | //Starts up SDL and creates window 18 | bool init(); 19 | 20 | //Loads media 21 | bool loadMedia(); 22 | 23 | //Frees media and shuts down SDL 24 | void close(); 25 | 26 | //Loads individual image as texture 27 | SDL_Texture* loadTexture( std::string path ); 28 | 29 | //The window we'll be rendering to 30 | SDL_Window* gWindow = NULL; 31 | 32 | //The window renderer 33 | SDL_Renderer* gRenderer = NULL; 34 | 35 | //Current displayed texture 36 | SDL_Texture* gTexture = NULL; 37 | 38 | bool init() 39 | { 40 | //Initialization flag 41 | bool success = true; 42 | 43 | //Initialize SDL 44 | if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) 45 | { 46 | printf( "SDL could not initialize! SDL Error: %s\n", SDL_GetError() ); 47 | success = false; 48 | } 49 | else 50 | { 51 | //Set texture filtering to linear 52 | if( !SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" ) ) 53 | { 54 | printf( "Warning: Linear texture filtering not enabled!" ); 55 | } 56 | 57 | //Create window 58 | gWindow = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN ); 59 | if( gWindow == NULL ) 60 | { 61 | printf( "Window could not be created! SDL Error: %s\n", SDL_GetError() ); 62 | success = false; 63 | } 64 | else 65 | { 66 | //Create renderer for window 67 | gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_ACCELERATED ); 68 | 69 | //try software render if hardware fails 70 | if( gRenderer == NULL ) 71 | { 72 | SDL_Log( "Accelerated renderer could not be created! SDL Error: %s\nSwitching to software renderer", SDL_GetError() ); 73 | gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_SOFTWARE); 74 | } 75 | 76 | if( gRenderer == NULL ) 77 | { 78 | printf( "Renderer could not be created! SDL Error: %s\n", SDL_GetError() ); 79 | success = false; 80 | } 81 | else 82 | { 83 | //Initialize renderer color 84 | SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF ); 85 | 86 | //Initialize PNG loading 87 | int imgFlags = IMG_INIT_PNG; 88 | if( !( IMG_Init( imgFlags ) & imgFlags ) ) 89 | { 90 | printf( "SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError() ); 91 | success = false; 92 | } 93 | } 94 | } 95 | } 96 | 97 | return success; 98 | } 99 | 100 | bool loadMedia() 101 | { 102 | //Loading success flag 103 | bool success = true; 104 | 105 | //Load PNG texture 106 | gTexture = loadTexture( "assets/texture.png" ); 107 | if( gTexture == NULL ) 108 | { 109 | printf( "Failed to load texture image!\n" ); 110 | success = false; 111 | } 112 | 113 | return success; 114 | } 115 | 116 | void close() 117 | { 118 | //Free loaded image 119 | SDL_DestroyTexture( gTexture ); 120 | gTexture = NULL; 121 | 122 | //Destroy window 123 | SDL_DestroyRenderer( gRenderer ); 124 | SDL_DestroyWindow( gWindow ); 125 | gWindow = NULL; 126 | gRenderer = NULL; 127 | 128 | //Quit SDL subsystems 129 | IMG_Quit(); 130 | SDL_Quit(); 131 | } 132 | 133 | SDL_Texture* loadTexture( std::string path ) 134 | { 135 | //The final texture 136 | SDL_Texture* newTexture = NULL; 137 | 138 | //Load image at specified path 139 | SDL_Surface* loadedSurface = IMG_Load( path.c_str() ); 140 | if( loadedSurface == NULL ) 141 | { 142 | printf( "Unable to load image %s! SDL_image Error: %s\n", path.c_str(), IMG_GetError() ); 143 | } 144 | else 145 | { 146 | //Create texture from surface pixels 147 | newTexture = SDL_CreateTextureFromSurface( gRenderer, loadedSurface ); 148 | if( newTexture == NULL ) 149 | { 150 | printf( "Unable to create texture from %s! SDL Error: %s\n", path.c_str(), SDL_GetError() ); 151 | } 152 | 153 | //Get rid of old loaded surface 154 | SDL_FreeSurface( loadedSurface ); 155 | } 156 | 157 | return newTexture; 158 | } 159 | 160 | //Main loop flag 161 | bool quit = false; 162 | 163 | void loop_handler(void*) 164 | { 165 | //Event handler 166 | SDL_Event e; 167 | //Handle events on queue 168 | while( SDL_PollEvent( &e ) != 0 ) 169 | { 170 | //User requests quit 171 | if( e.type == SDL_QUIT ) 172 | { 173 | quit = true; 174 | } 175 | } 176 | 177 | //Clear screen 178 | SDL_RenderClear( gRenderer ); 179 | 180 | //Render texture to screen 181 | SDL_RenderCopy( gRenderer, gTexture, NULL, NULL ); 182 | 183 | //Update screen 184 | SDL_RenderPresent( gRenderer ); 185 | 186 | } 187 | 188 | int main( int argc, char* args[] ) 189 | { 190 | //Start up SDL and create window 191 | if( !init() ) 192 | { 193 | printf( "Failed to initialize!\n" ); 194 | } 195 | else 196 | { 197 | //Load media 198 | if( !loadMedia() ) 199 | { 200 | printf( "Failed to load media!\n" ); 201 | } 202 | else 203 | { 204 | #ifdef _JS 205 | 206 | emscripten_set_main_loop_arg(loop_handler, NULL, -1, 1); 207 | #else 208 | //While application is running 209 | while( !quit ) 210 | { 211 | loop_handler(NULL); 212 | } 213 | #endif 214 | 215 | } 216 | } 217 | 218 | //Free resources and close SDL 219 | close(); 220 | 221 | return 0; 222 | } 223 | -------------------------------------------------------------------------------- /07_texture_loading_and_rendering/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /07_texture_loading_and_rendering/assets/texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/07_texture_loading_and_rendering/assets/texture.png -------------------------------------------------------------------------------- /07_texture_loading_and_rendering/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | 13 | *nix: 14 | SDL2 15 | SDL2_image 16 | -------------------------------------------------------------------------------- /08_geometry_rendering/08_geometry_rendering.cpp: -------------------------------------------------------------------------------- 1 | /*This source code copyrighted by Lazy Foo' Productions (2004-2015) 2 | and may not be redistributed without written permission.*/ 3 | 4 | //Using SDL, SDL_image, standard IO, math, and strings 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #ifdef _JS 11 | #include 12 | #endif 13 | 14 | //Screen dimension constants 15 | const int SCREEN_WIDTH = 640; 16 | const int SCREEN_HEIGHT = 480; 17 | 18 | //Starts up SDL and creates window 19 | bool init(); 20 | 21 | //Loads media 22 | bool loadMedia(); 23 | 24 | //Frees media and shuts down SDL 25 | void close(); 26 | 27 | //Loads individual image as texture 28 | SDL_Texture* loadTexture( std::string path ); 29 | 30 | //The window we'll be rendering to 31 | SDL_Window* gWindow = NULL; 32 | 33 | //The window renderer 34 | SDL_Renderer* gRenderer = NULL; 35 | 36 | bool init() 37 | { 38 | //Initialization flag 39 | bool success = true; 40 | 41 | //Initialize SDL 42 | if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) 43 | { 44 | printf( "SDL could not initialize! SDL Error: %s\n", SDL_GetError() ); 45 | success = false; 46 | } 47 | else 48 | { 49 | //Set texture filtering to linear 50 | if( !SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" ) ) 51 | { 52 | printf( "Warning: Linear texture filtering not enabled!" ); 53 | } 54 | 55 | //Create window 56 | gWindow = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN ); 57 | if( gWindow == NULL ) 58 | { 59 | printf( "Window could not be created! SDL Error: %s\n", SDL_GetError() ); 60 | success = false; 61 | } 62 | else 63 | { 64 | //Create renderer for window 65 | gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_ACCELERATED ); 66 | 67 | //try software render if hardware fails 68 | if( gRenderer == NULL ) 69 | { 70 | SDL_Log( "Accelerated renderer could not be created! SDL Error: %s\nSwitching to software renderer", SDL_GetError() ); 71 | gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_SOFTWARE); 72 | } 73 | 74 | if( gRenderer == NULL ) 75 | { 76 | printf( "Renderer could not be created! SDL Error: %s\n", SDL_GetError() ); 77 | success = false; 78 | } 79 | else 80 | { 81 | //Initialize renderer color 82 | SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF ); 83 | 84 | //Initialize PNG loading 85 | int imgFlags = IMG_INIT_PNG; 86 | if( !( IMG_Init( imgFlags ) & imgFlags ) ) 87 | { 88 | printf( "SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError() ); 89 | success = false; 90 | } 91 | } 92 | } 93 | } 94 | 95 | return success; 96 | } 97 | 98 | bool loadMedia() 99 | { 100 | //Loading success flag 101 | bool success = true; 102 | 103 | //Nothing to load 104 | return success; 105 | } 106 | 107 | void close() 108 | { 109 | //Destroy window 110 | SDL_DestroyRenderer( gRenderer ); 111 | SDL_DestroyWindow( gWindow ); 112 | gWindow = NULL; 113 | gRenderer = NULL; 114 | 115 | //Quit SDL subsystems 116 | IMG_Quit(); 117 | SDL_Quit(); 118 | } 119 | 120 | SDL_Texture* loadTexture( std::string path ) 121 | { 122 | //The final texture 123 | SDL_Texture* newTexture = NULL; 124 | 125 | //Load image at specified path 126 | SDL_Surface* loadedSurface = IMG_Load( path.c_str() ); 127 | if( loadedSurface == NULL ) 128 | { 129 | printf( "Unable to load image %s! SDL_image Error: %s\n", path.c_str(), IMG_GetError() ); 130 | } 131 | else 132 | { 133 | //Create texture from surface pixels 134 | newTexture = SDL_CreateTextureFromSurface( gRenderer, loadedSurface ); 135 | if( newTexture == NULL ) 136 | { 137 | printf( "Unable to create texture from %s! SDL Error: %s\n", path.c_str(), SDL_GetError() ); 138 | } 139 | 140 | //Get rid of old loaded surface 141 | SDL_FreeSurface( loadedSurface ); 142 | } 143 | 144 | return newTexture; 145 | } 146 | 147 | //Main loop flag 148 | bool quit = false; 149 | 150 | void loop_handler(void*) 151 | { 152 | //Event handler 153 | SDL_Event e; 154 | //Handle events on queue 155 | while( SDL_PollEvent( &e ) != 0 ) 156 | { 157 | //User requests quit 158 | if( e.type == SDL_QUIT ) 159 | { 160 | quit = true; 161 | } 162 | } 163 | 164 | //Clear screen 165 | SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF ); 166 | SDL_RenderClear( gRenderer ); 167 | 168 | //Render red filled quad 169 | SDL_Rect fillRect = { SCREEN_WIDTH / 4, SCREEN_HEIGHT / 4, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 }; 170 | SDL_SetRenderDrawColor( gRenderer, 0xFF, 0x00, 0x00, 0xFF ); 171 | SDL_RenderFillRect( gRenderer, &fillRect ); 172 | 173 | //Render green outlined quad 174 | SDL_Rect outlineRect = { SCREEN_WIDTH / 6, SCREEN_HEIGHT / 6, SCREEN_WIDTH * 2 / 3, SCREEN_HEIGHT * 2 / 3 }; 175 | SDL_SetRenderDrawColor( gRenderer, 0x00, 0xFF, 0x00, 0xFF ); 176 | SDL_RenderDrawRect( gRenderer, &outlineRect ); 177 | 178 | //Draw blue horizontal line 179 | SDL_SetRenderDrawColor( gRenderer, 0x00, 0x00, 0xFF, 0xFF ); 180 | SDL_RenderDrawLine( gRenderer, 0, SCREEN_HEIGHT / 2, SCREEN_WIDTH, SCREEN_HEIGHT / 2 ); 181 | 182 | //Draw vertical line of yellow dots 183 | SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0x00, 0xFF ); 184 | for( int i = 0; i < SCREEN_HEIGHT; i += 4 ) 185 | { 186 | SDL_RenderDrawPoint( gRenderer, SCREEN_WIDTH / 2, i ); 187 | } 188 | 189 | //Update screen 190 | SDL_RenderPresent( gRenderer ); 191 | 192 | } 193 | 194 | int main( int argc, char* args[] ) 195 | { 196 | //Start up SDL and create window 197 | if( !init() ) 198 | { 199 | printf( "Failed to initialize!\n" ); 200 | } 201 | else 202 | { 203 | //Load media 204 | if( !loadMedia() ) 205 | { 206 | printf( "Failed to load media!\n" ); 207 | } 208 | else 209 | { 210 | #ifdef _JS 211 | 212 | emscripten_set_main_loop_arg(loop_handler, NULL, -1, 1); 213 | #else 214 | //While application is running 215 | while( !quit ) 216 | { 217 | loop_handler(NULL); 218 | } 219 | #endif 220 | 221 | 222 | } 223 | } 224 | 225 | //Free resources and close SDL 226 | close(); 227 | 228 | return 0; 229 | } 230 | -------------------------------------------------------------------------------- /08_geometry_rendering/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /08_geometry_rendering/assets/place_holder.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/08_geometry_rendering/assets/place_holder.txt -------------------------------------------------------------------------------- /08_geometry_rendering/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | 13 | *nix: 14 | SDL2 15 | SDL2_image 16 | -------------------------------------------------------------------------------- /09_the_viewport/09_the_viewport.cpp: -------------------------------------------------------------------------------- 1 | /*This source code copyrighted by Lazy Foo' Productions (2004-2015) 2 | and may not be redistributed without written permission.*/ 3 | 4 | //Using SDL, SDL_image, standard IO, and strings 5 | #include 6 | #include 7 | #include 8 | #include 9 | #ifdef _JS 10 | #include 11 | #endif 12 | 13 | //Screen dimension constants 14 | const int SCREEN_WIDTH = 640; 15 | const int SCREEN_HEIGHT = 480; 16 | 17 | //Starts up SDL and creates window 18 | bool init(); 19 | 20 | //Loads media 21 | bool loadMedia(); 22 | 23 | //Frees media and shuts down SDL 24 | void close(); 25 | 26 | //Loads individual image as texture 27 | SDL_Texture* loadTexture( std::string path ); 28 | 29 | //The window we'll be rendering to 30 | SDL_Window* gWindow = NULL; 31 | 32 | //The window renderer 33 | SDL_Renderer* gRenderer = NULL; 34 | 35 | //Current displayed texture 36 | SDL_Texture* gTexture = NULL; 37 | 38 | bool init() 39 | { 40 | //Initialization flag 41 | bool success = true; 42 | 43 | //Initialize SDL 44 | if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) 45 | { 46 | printf( "SDL could not initialize! SDL Error: %s\n", SDL_GetError() ); 47 | success = false; 48 | } 49 | else 50 | { 51 | //Set texture filtering to linear 52 | if( !SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" ) ) 53 | { 54 | printf( "Warning: Linear texture filtering not enabled!" ); 55 | } 56 | 57 | //Create window 58 | gWindow = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN ); 59 | if( gWindow == NULL ) 60 | { 61 | printf( "Window could not be created! SDL Error: %s\n", SDL_GetError() ); 62 | success = false; 63 | } 64 | else 65 | { 66 | //Create renderer for window 67 | gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_ACCELERATED ); 68 | 69 | //try software render if hardware fails 70 | if( gRenderer == NULL ) 71 | { 72 | SDL_Log( "Accelerated renderer could not be created! SDL Error: %s\nSwitching to software renderer", SDL_GetError() ); 73 | gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_SOFTWARE); 74 | } 75 | 76 | if( gRenderer == NULL ) 77 | { 78 | printf( "Renderer could not be created! SDL Error: %s\n", SDL_GetError() ); 79 | success = false; 80 | } 81 | else 82 | { 83 | //Initialize renderer color 84 | SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF ); 85 | 86 | //Initialize PNG loading 87 | int imgFlags = IMG_INIT_PNG; 88 | if( !( IMG_Init( imgFlags ) & imgFlags ) ) 89 | { 90 | printf( "SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError() ); 91 | success = false; 92 | } 93 | } 94 | } 95 | } 96 | 97 | return success; 98 | } 99 | 100 | bool loadMedia() 101 | { 102 | //Loading success flag 103 | bool success = true; 104 | 105 | //Load texture 106 | gTexture = loadTexture( "assets/viewport.png" ); 107 | if( gTexture == NULL ) 108 | { 109 | printf( "Failed to load texture image!\n" ); 110 | success = false; 111 | } 112 | 113 | //Nothing to load 114 | return success; 115 | } 116 | 117 | void close() 118 | { 119 | //Free loaded image 120 | SDL_DestroyTexture( gTexture ); 121 | gTexture = NULL; 122 | 123 | //Destroy window 124 | SDL_DestroyRenderer( gRenderer ); 125 | SDL_DestroyWindow( gWindow ); 126 | gWindow = NULL; 127 | gRenderer = NULL; 128 | 129 | //Quit SDL subsystems 130 | IMG_Quit(); 131 | SDL_Quit(); 132 | } 133 | 134 | SDL_Texture* loadTexture( std::string path ) 135 | { 136 | //The final texture 137 | SDL_Texture* newTexture = NULL; 138 | 139 | //Load image at specified path 140 | SDL_Surface* loadedSurface = IMG_Load( path.c_str() ); 141 | if( loadedSurface == NULL ) 142 | { 143 | printf( "Unable to load image %s! SDL_image Error: %s\n", path.c_str(), IMG_GetError() ); 144 | } 145 | else 146 | { 147 | //Create texture from surface pixels 148 | newTexture = SDL_CreateTextureFromSurface( gRenderer, loadedSurface ); 149 | if( newTexture == NULL ) 150 | { 151 | printf( "Unable to create texture from %s! SDL Error: %s\n", path.c_str(), SDL_GetError() ); 152 | } 153 | 154 | //Get rid of old loaded surface 155 | SDL_FreeSurface( loadedSurface ); 156 | } 157 | 158 | return newTexture; 159 | } 160 | 161 | //Main loop flag 162 | bool quit = false; 163 | 164 | void loop_handler(void*) 165 | { 166 | //Event handler 167 | SDL_Event e; 168 | //Handle events on queue 169 | while( SDL_PollEvent( &e ) != 0 ) 170 | { 171 | //User requests quit 172 | if( e.type == SDL_QUIT ) 173 | { 174 | quit = true; 175 | } 176 | } 177 | 178 | //Clear screen 179 | SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF ); 180 | SDL_RenderClear( gRenderer ); 181 | 182 | //Top left corner viewport 183 | SDL_Rect topLeftViewport; 184 | topLeftViewport.x = 0; 185 | topLeftViewport.y = 0; 186 | topLeftViewport.w = SCREEN_WIDTH / 2; 187 | topLeftViewport.h = SCREEN_HEIGHT / 2; 188 | SDL_RenderSetViewport( gRenderer, &topLeftViewport ); 189 | 190 | //Render texture to screen 191 | SDL_RenderCopy( gRenderer, gTexture, NULL, NULL ); 192 | 193 | 194 | //Top right viewport 195 | SDL_Rect topRightViewport; 196 | topRightViewport.x = SCREEN_WIDTH / 2; 197 | topRightViewport.y = 0; 198 | topRightViewport.w = SCREEN_WIDTH / 2; 199 | topRightViewport.h = SCREEN_HEIGHT / 2; 200 | SDL_RenderSetViewport( gRenderer, &topRightViewport ); 201 | 202 | //Render texture to screen 203 | SDL_RenderCopy( gRenderer, gTexture, NULL, NULL ); 204 | 205 | 206 | //Bottom viewport 207 | SDL_Rect bottomViewport; 208 | bottomViewport.x = 0; 209 | bottomViewport.y = SCREEN_HEIGHT / 2; 210 | bottomViewport.w = SCREEN_WIDTH; 211 | bottomViewport.h = SCREEN_HEIGHT / 2; 212 | SDL_RenderSetViewport( gRenderer, &bottomViewport ); 213 | 214 | 215 | //Render texture to screen 216 | SDL_RenderCopy( gRenderer, gTexture, NULL, NULL ); 217 | 218 | 219 | //Update screen 220 | SDL_RenderPresent( gRenderer ); 221 | 222 | } 223 | 224 | int main( int argc, char* args[] ) 225 | { 226 | //Start up SDL and create window 227 | if( !init() ) 228 | { 229 | printf( "Failed to initialize!\n" ); 230 | } 231 | else 232 | { 233 | //Load media 234 | if( !loadMedia() ) 235 | { 236 | printf( "Failed to load media!\n" ); 237 | } 238 | else 239 | { 240 | #ifdef _JS 241 | 242 | emscripten_set_main_loop_arg(loop_handler, NULL, -1, 1); 243 | #else 244 | //While application is running 245 | while( !quit ) 246 | { 247 | loop_handler(NULL); 248 | } 249 | #endif 250 | 251 | } 252 | } 253 | 254 | //Free resources and close SDL 255 | close(); 256 | 257 | return 0; 258 | } 259 | -------------------------------------------------------------------------------- /09_the_viewport/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /09_the_viewport/assets/viewport.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/09_the_viewport/assets/viewport.png -------------------------------------------------------------------------------- /09_the_viewport/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | 13 | *nix: 14 | SDL2 15 | SDL2_image 16 | -------------------------------------------------------------------------------- /10_color_keying/10_color_keying.cpp: -------------------------------------------------------------------------------- 1 | /*This source code copyrighted by Lazy Foo' Productions (2004-2015) 2 | and may not be redistributed without written permission.*/ 3 | 4 | //Using SDL, SDL_image, standard IO, and strings 5 | #include 6 | #include 7 | #include 8 | #include 9 | #ifdef _JS 10 | #include 11 | #endif 12 | 13 | //Screen dimension constants 14 | const int SCREEN_WIDTH = 640; 15 | const int SCREEN_HEIGHT = 480; 16 | 17 | //Texture wrapper class 18 | class LTexture 19 | { 20 | public: 21 | //Initializes variables 22 | LTexture(); 23 | 24 | //Deallocates memory 25 | ~LTexture(); 26 | 27 | //Loads image at specified path 28 | bool loadFromFile( std::string path ); 29 | 30 | //Deallocates texture 31 | void free(); 32 | 33 | //Renders texture at given point 34 | void render( int x, int y ); 35 | 36 | //Gets image dimensions 37 | int getWidth(); 38 | int getHeight(); 39 | 40 | private: 41 | //The actual hardware texture 42 | SDL_Texture* mTexture; 43 | 44 | //Image dimensions 45 | int mWidth; 46 | int mHeight; 47 | }; 48 | 49 | //Starts up SDL and creates window 50 | bool init(); 51 | 52 | //Loads media 53 | bool loadMedia(); 54 | 55 | //Frees media and shuts down SDL 56 | void close(); 57 | 58 | //The window we'll be rendering to 59 | SDL_Window* gWindow = NULL; 60 | 61 | //The window renderer 62 | SDL_Renderer* gRenderer = NULL; 63 | 64 | //Scene textures 65 | LTexture gFooTexture; 66 | LTexture gBackgroundTexture; 67 | 68 | 69 | LTexture::LTexture() 70 | { 71 | //Initialize 72 | mTexture = NULL; 73 | mWidth = 0; 74 | mHeight = 0; 75 | } 76 | 77 | LTexture::~LTexture() 78 | { 79 | //Deallocate 80 | free(); 81 | } 82 | 83 | bool LTexture::loadFromFile( std::string path ) 84 | { 85 | //Get rid of preexisting texture 86 | free(); 87 | 88 | //The final texture 89 | SDL_Texture* newTexture = NULL; 90 | 91 | //Load image at specified path 92 | SDL_Surface* loadedSurface = IMG_Load( path.c_str() ); 93 | if( loadedSurface == NULL ) 94 | { 95 | printf( "Unable to load image %s! SDL_image Error: %s\n", path.c_str(), IMG_GetError() ); 96 | } 97 | else 98 | { 99 | //Color key image 100 | SDL_SetColorKey( loadedSurface, SDL_TRUE, SDL_MapRGB( loadedSurface->format, 0, 0xFF, 0xFF ) ); 101 | 102 | //Create texture from surface pixels 103 | newTexture = SDL_CreateTextureFromSurface( gRenderer, loadedSurface ); 104 | if( newTexture == NULL ) 105 | { 106 | printf( "Unable to create texture from %s! SDL Error: %s\n", path.c_str(), SDL_GetError() ); 107 | } 108 | else 109 | { 110 | //Get image dimensions 111 | mWidth = loadedSurface->w; 112 | mHeight = loadedSurface->h; 113 | } 114 | 115 | //Get rid of old loaded surface 116 | SDL_FreeSurface( loadedSurface ); 117 | } 118 | 119 | //Return success 120 | mTexture = newTexture; 121 | return mTexture != NULL; 122 | } 123 | 124 | void LTexture::free() 125 | { 126 | //Free texture if it exists 127 | if( mTexture != NULL ) 128 | { 129 | SDL_DestroyTexture( mTexture ); 130 | mTexture = NULL; 131 | mWidth = 0; 132 | mHeight = 0; 133 | } 134 | } 135 | 136 | void LTexture::render( int x, int y ) 137 | { 138 | //Set rendering space and render to screen 139 | SDL_Rect renderQuad = { x, y, mWidth, mHeight }; 140 | SDL_RenderCopy( gRenderer, mTexture, NULL, &renderQuad ); 141 | } 142 | 143 | int LTexture::getWidth() 144 | { 145 | return mWidth; 146 | } 147 | 148 | int LTexture::getHeight() 149 | { 150 | return mHeight; 151 | } 152 | 153 | bool init() 154 | { 155 | //Initialization flag 156 | bool success = true; 157 | 158 | //Initialize SDL 159 | if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) 160 | { 161 | printf( "SDL could not initialize! SDL Error: %s\n", SDL_GetError() ); 162 | success = false; 163 | } 164 | else 165 | { 166 | //Set texture filtering to linear 167 | if( !SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" ) ) 168 | { 169 | printf( "Warning: Linear texture filtering not enabled!" ); 170 | } 171 | 172 | //Create window 173 | gWindow = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN ); 174 | if( gWindow == NULL ) 175 | { 176 | printf( "Window could not be created! SDL Error: %s\n", SDL_GetError() ); 177 | success = false; 178 | } 179 | else 180 | { 181 | //Create renderer for window 182 | gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_ACCELERATED ); 183 | 184 | //try software render if hardware fails 185 | if( gRenderer == NULL ) 186 | { 187 | SDL_Log( "Accelerated renderer could not be created! SDL Error: %s\nSwitching to software renderer", SDL_GetError() ); 188 | gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_SOFTWARE); 189 | } 190 | 191 | if( gRenderer == NULL ) 192 | { 193 | printf( "Renderer could not be created! SDL Error: %s\n", SDL_GetError() ); 194 | success = false; 195 | } 196 | else 197 | { 198 | //Initialize renderer color 199 | SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF ); 200 | 201 | //Initialize PNG loading 202 | int imgFlags = IMG_INIT_PNG; 203 | if( !( IMG_Init( imgFlags ) & imgFlags ) ) 204 | { 205 | printf( "SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError() ); 206 | success = false; 207 | } 208 | } 209 | } 210 | } 211 | 212 | return success; 213 | } 214 | 215 | bool loadMedia() 216 | { 217 | //Loading success flag 218 | bool success = true; 219 | 220 | //Load Foo' texture 221 | if( !gFooTexture.loadFromFile( "assets/foo.png" ) ) 222 | { 223 | printf( "Failed to load Foo' texture image!\n" ); 224 | success = false; 225 | } 226 | 227 | //Load background texture 228 | if( !gBackgroundTexture.loadFromFile( "assets/background.png" ) ) 229 | { 230 | printf( "Failed to load background texture image!\n" ); 231 | success = false; 232 | } 233 | 234 | return success; 235 | } 236 | 237 | void close() 238 | { 239 | //Free loaded images 240 | gFooTexture.free(); 241 | gBackgroundTexture.free(); 242 | 243 | //Destroy window 244 | SDL_DestroyRenderer( gRenderer ); 245 | SDL_DestroyWindow( gWindow ); 246 | gWindow = NULL; 247 | gRenderer = NULL; 248 | 249 | //Quit SDL subsystems 250 | IMG_Quit(); 251 | SDL_Quit(); 252 | } 253 | 254 | //Main loop flag 255 | bool quit = false; 256 | 257 | void loop_handler(void*) 258 | { 259 | //Event handler 260 | SDL_Event e; 261 | //Handle events on queue 262 | while( SDL_PollEvent( &e ) != 0 ) 263 | { 264 | //User requests quit 265 | if( e.type == SDL_QUIT ) 266 | { 267 | quit = true; 268 | } 269 | } 270 | 271 | //Clear screen 272 | SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF ); 273 | SDL_RenderClear( gRenderer ); 274 | 275 | //Render background texture to screen 276 | gBackgroundTexture.render( 0, 0 ); 277 | 278 | //Render Foo' to the screen 279 | gFooTexture.render( 240, 190 ); 280 | 281 | //Update screen 282 | SDL_RenderPresent( gRenderer ); 283 | 284 | } 285 | 286 | int main( int argc, char* args[] ) 287 | { 288 | //Start up SDL and create window 289 | if( !init() ) 290 | { 291 | printf( "Failed to initialize!\n" ); 292 | } 293 | else 294 | { 295 | //Load media 296 | if( !loadMedia() ) 297 | { 298 | printf( "Failed to load media!\n" ); 299 | } 300 | else 301 | { 302 | #ifdef _JS 303 | 304 | emscripten_set_main_loop_arg(loop_handler, NULL, -1, 1); 305 | #else 306 | //While application is running 307 | while( !quit ) 308 | { 309 | loop_handler(NULL); 310 | } 311 | #endif 312 | 313 | } 314 | } 315 | 316 | //Free resources and close SDL 317 | close(); 318 | 319 | return 0; 320 | } 321 | -------------------------------------------------------------------------------- /10_color_keying/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /10_color_keying/assets/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/10_color_keying/assets/background.png -------------------------------------------------------------------------------- /10_color_keying/assets/foo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/10_color_keying/assets/foo.png -------------------------------------------------------------------------------- /10_color_keying/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | 13 | *nix: 14 | SDL2 15 | SDL2_image 16 | -------------------------------------------------------------------------------- /11_clip_rendering_and_sprite_sheets/11_clip_rendering_and_sprite_sheets.cpp: -------------------------------------------------------------------------------- 1 | /*This source code copyrighted by Lazy Foo' Productions (2004-2015) 2 | and may not be redistributed without written permission.*/ 3 | 4 | //Using SDL, SDL_image, standard math, and strings 5 | #include 6 | #include 7 | #include 8 | #include 9 | #ifdef _JS 10 | #include 11 | #endif 12 | 13 | //Screen dimension constants 14 | const int SCREEN_WIDTH = 640; 15 | const int SCREEN_HEIGHT = 480; 16 | 17 | //Texture wrapper class 18 | class LTexture 19 | { 20 | public: 21 | //Initializes variables 22 | LTexture(); 23 | 24 | //Deallocates memory 25 | ~LTexture(); 26 | 27 | //Loads image at specified path 28 | bool loadFromFile( std::string path ); 29 | 30 | //Deallocates texture 31 | void free(); 32 | 33 | //Renders texture at given point 34 | void render( int x, int y, SDL_Rect* clip = NULL ); 35 | 36 | //Gets image dimensions 37 | int getWidth(); 38 | int getHeight(); 39 | 40 | private: 41 | //The actual hardware texture 42 | SDL_Texture* mTexture; 43 | 44 | //Image dimensions 45 | int mWidth; 46 | int mHeight; 47 | }; 48 | 49 | //Starts up SDL and creates window 50 | bool init(); 51 | 52 | //Loads media 53 | bool loadMedia(); 54 | 55 | //Frees media and shuts down SDL 56 | void close(); 57 | 58 | //The window we'll be rendering to 59 | SDL_Window* gWindow = NULL; 60 | 61 | //The window renderer 62 | SDL_Renderer* gRenderer = NULL; 63 | 64 | //Scene sprites 65 | SDL_Rect gSpriteClips[ 4 ]; 66 | LTexture gSpriteSheetTexture; 67 | 68 | 69 | LTexture::LTexture() 70 | { 71 | //Initialize 72 | mTexture = NULL; 73 | mWidth = 0; 74 | mHeight = 0; 75 | } 76 | 77 | LTexture::~LTexture() 78 | { 79 | //Deallocate 80 | free(); 81 | } 82 | 83 | bool LTexture::loadFromFile( std::string path ) 84 | { 85 | //Get rid of preexisting texture 86 | free(); 87 | 88 | //The final texture 89 | SDL_Texture* newTexture = NULL; 90 | 91 | //Load image at specified path 92 | SDL_Surface* loadedSurface = IMG_Load( path.c_str() ); 93 | if( loadedSurface == NULL ) 94 | { 95 | printf( "Unable to load image %s! SDL_image Error: %s\n", path.c_str(), IMG_GetError() ); 96 | } 97 | else 98 | { 99 | //Color key image 100 | SDL_SetColorKey( loadedSurface, SDL_TRUE, SDL_MapRGB( loadedSurface->format, 0, 0xFF, 0xFF ) ); 101 | 102 | //Create texture from surface pixels 103 | newTexture = SDL_CreateTextureFromSurface( gRenderer, loadedSurface ); 104 | if( newTexture == NULL ) 105 | { 106 | printf( "Unable to create texture from %s! SDL Error: %s\n", path.c_str(), SDL_GetError() ); 107 | } 108 | else 109 | { 110 | //Get image dimensions 111 | mWidth = loadedSurface->w; 112 | mHeight = loadedSurface->h; 113 | } 114 | 115 | //Get rid of old loaded surface 116 | SDL_FreeSurface( loadedSurface ); 117 | } 118 | 119 | //Return success 120 | mTexture = newTexture; 121 | return mTexture != NULL; 122 | } 123 | 124 | void LTexture::free() 125 | { 126 | //Free texture if it exists 127 | if( mTexture != NULL ) 128 | { 129 | SDL_DestroyTexture( mTexture ); 130 | mTexture = NULL; 131 | mWidth = 0; 132 | mHeight = 0; 133 | } 134 | } 135 | 136 | void LTexture::render( int x, int y, SDL_Rect* clip ) 137 | { 138 | //Set rendering space and render to screen 139 | SDL_Rect renderQuad = { x, y, mWidth, mHeight }; 140 | 141 | //Set clip rendering dimensions 142 | if( clip != NULL ) 143 | { 144 | renderQuad.w = clip->w; 145 | renderQuad.h = clip->h; 146 | } 147 | 148 | //Render to screen 149 | SDL_RenderCopy( gRenderer, mTexture, clip, &renderQuad ); 150 | } 151 | 152 | int LTexture::getWidth() 153 | { 154 | return mWidth; 155 | } 156 | 157 | int LTexture::getHeight() 158 | { 159 | return mHeight; 160 | } 161 | 162 | bool init() 163 | { 164 | //Initialization flag 165 | bool success = true; 166 | 167 | //Initialize SDL 168 | if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) 169 | { 170 | printf( "SDL could not initialize! SDL Error: %s\n", SDL_GetError() ); 171 | success = false; 172 | } 173 | else 174 | { 175 | //Set texture filtering to linear 176 | if( !SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" ) ) 177 | { 178 | printf( "Warning: Linear texture filtering not enabled!" ); 179 | } 180 | 181 | //Create window 182 | gWindow = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN ); 183 | if( gWindow == NULL ) 184 | { 185 | printf( "Window could not be created! SDL Error: %s\n", SDL_GetError() ); 186 | success = false; 187 | } 188 | else 189 | { 190 | //Create renderer for window 191 | gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_ACCELERATED ); 192 | 193 | //try software render if hardware fails 194 | if( gRenderer == NULL ) 195 | { 196 | SDL_Log( "Accelerated renderer could not be created! SDL Error: %s\nSwitching to software renderer", SDL_GetError() ); 197 | gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_SOFTWARE); 198 | } 199 | 200 | if( gRenderer == NULL ) 201 | { 202 | printf( "Renderer could not be created! SDL Error: %s\n", SDL_GetError() ); 203 | success = false; 204 | } 205 | else 206 | { 207 | //Initialize renderer color 208 | SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF ); 209 | 210 | //Initialize PNG loading 211 | int imgFlags = IMG_INIT_PNG; 212 | if( !( IMG_Init( imgFlags ) & imgFlags ) ) 213 | { 214 | printf( "SDL_image could not initialize! SDL_mage Error: %s\n", IMG_GetError() ); 215 | success = false; 216 | } 217 | } 218 | } 219 | } 220 | 221 | return success; 222 | } 223 | 224 | bool loadMedia() 225 | { 226 | //Loading success flag 227 | bool success = true; 228 | 229 | //Load sprite sheet texture 230 | if( !gSpriteSheetTexture.loadFromFile( "assets/dots.png" ) ) 231 | { 232 | printf( "Failed to load sprite sheet texture!\n" ); 233 | success = false; 234 | } 235 | else 236 | { 237 | //Set top left sprite 238 | gSpriteClips[ 0 ].x = 0; 239 | gSpriteClips[ 0 ].y = 0; 240 | gSpriteClips[ 0 ].w = 100; 241 | gSpriteClips[ 0 ].h = 100; 242 | 243 | //Set top right sprite 244 | gSpriteClips[ 1 ].x = 100; 245 | gSpriteClips[ 1 ].y = 0; 246 | gSpriteClips[ 1 ].w = 100; 247 | gSpriteClips[ 1 ].h = 100; 248 | 249 | //Set bottom left sprite 250 | gSpriteClips[ 2 ].x = 0; 251 | gSpriteClips[ 2 ].y = 100; 252 | gSpriteClips[ 2 ].w = 100; 253 | gSpriteClips[ 2 ].h = 100; 254 | 255 | //Set bottom right sprite 256 | gSpriteClips[ 3 ].x = 100; 257 | gSpriteClips[ 3 ].y = 100; 258 | gSpriteClips[ 3 ].w = 100; 259 | gSpriteClips[ 3 ].h = 100; 260 | } 261 | 262 | return success; 263 | } 264 | 265 | void close() 266 | { 267 | //Free loaded images 268 | gSpriteSheetTexture.free(); 269 | 270 | //Destroy window 271 | SDL_DestroyRenderer( gRenderer ); 272 | SDL_DestroyWindow( gWindow ); 273 | gWindow = NULL; 274 | gRenderer = NULL; 275 | 276 | //Quit SDL subsystems 277 | IMG_Quit(); 278 | SDL_Quit(); 279 | } 280 | 281 | //Main loop flag 282 | bool quit = false; 283 | 284 | void loop_handler(void*) 285 | { 286 | //Event handler 287 | SDL_Event e; 288 | //Handle events on queue 289 | while( SDL_PollEvent( &e ) != 0 ) 290 | { 291 | //User requests quit 292 | if( e.type == SDL_QUIT ) 293 | { 294 | quit = true; 295 | } 296 | } 297 | 298 | //Clear screen 299 | SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF ); 300 | SDL_RenderClear( gRenderer ); 301 | 302 | //Render top left sprite 303 | gSpriteSheetTexture.render( 0, 0, &gSpriteClips[ 0 ] ); 304 | 305 | //Render top right sprite 306 | gSpriteSheetTexture.render( SCREEN_WIDTH - gSpriteClips[ 1 ].w, 0, &gSpriteClips[ 1 ] ); 307 | 308 | //Render bottom left sprite 309 | gSpriteSheetTexture.render( 0, SCREEN_HEIGHT - gSpriteClips[ 2 ].h, &gSpriteClips[ 2 ] ); 310 | 311 | //Render bottom right sprite 312 | gSpriteSheetTexture.render( SCREEN_WIDTH - gSpriteClips[ 3 ].w, SCREEN_HEIGHT - gSpriteClips[ 3 ].h, &gSpriteClips[ 3 ] ); 313 | 314 | //Update screen 315 | SDL_RenderPresent( gRenderer ); 316 | 317 | } 318 | 319 | 320 | int main( int argc, char* args[] ) 321 | { 322 | //Start up SDL and create window 323 | if( !init() ) 324 | { 325 | printf( "Failed to initialize!\n" ); 326 | } 327 | else 328 | { 329 | //Load media 330 | if( !loadMedia() ) 331 | { 332 | printf( "Failed to load media!\n" ); 333 | } 334 | else 335 | { 336 | #ifdef _JS 337 | 338 | emscripten_set_main_loop_arg(loop_handler, NULL, -1, 1); 339 | #else 340 | //While application is running 341 | while( !quit ) 342 | { 343 | loop_handler(NULL); 344 | } 345 | #endif 346 | 347 | 348 | } 349 | } 350 | 351 | //Free resources and close SDL 352 | close(); 353 | 354 | return 0; 355 | } 356 | -------------------------------------------------------------------------------- /11_clip_rendering_and_sprite_sheets/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /11_clip_rendering_and_sprite_sheets/assets/dots.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/11_clip_rendering_and_sprite_sheets/assets/dots.png -------------------------------------------------------------------------------- /11_clip_rendering_and_sprite_sheets/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | 13 | *nix: 14 | SDL2 15 | SDL2_image 16 | -------------------------------------------------------------------------------- /12_color_modulation/12_color_modulation.cpp: -------------------------------------------------------------------------------- 1 | /*This source code copyrighted by Lazy Foo' Productions (2004-2015) 2 | and may not be redistributed without written permission.*/ 3 | 4 | //Using SDL, SDL_image, standard IO, and strings 5 | #include 6 | #include 7 | #include 8 | #include 9 | #ifdef _JS 10 | #include 11 | #endif 12 | 13 | //Screen dimension constants 14 | const int SCREEN_WIDTH = 640; 15 | const int SCREEN_HEIGHT = 480; 16 | 17 | //Texture wrapper class 18 | class LTexture 19 | { 20 | public: 21 | //Initializes variables 22 | LTexture(); 23 | 24 | //Deallocates memory 25 | ~LTexture(); 26 | 27 | //Loads image at specified path 28 | bool loadFromFile( std::string path ); 29 | 30 | //Deallocates texture 31 | void free(); 32 | 33 | //Set color modulation 34 | void setColor( Uint8 red, Uint8 green, Uint8 blue ); 35 | 36 | //Renders texture at given point 37 | void render( int x, int y, SDL_Rect* clip = NULL ); 38 | 39 | //Gets image dimensions 40 | int getWidth(); 41 | int getHeight(); 42 | 43 | private: 44 | //The actual hardware texture 45 | SDL_Texture* mTexture; 46 | 47 | //Image dimensions 48 | int mWidth; 49 | int mHeight; 50 | }; 51 | 52 | //Starts up SDL and creates window 53 | bool init(); 54 | 55 | //Loads media 56 | bool loadMedia(); 57 | 58 | //Frees media and shuts down SDL 59 | void close(); 60 | 61 | //The window we'll be rendering to 62 | SDL_Window* gWindow = NULL; 63 | 64 | //The window renderer 65 | SDL_Renderer* gRenderer = NULL; 66 | 67 | //Scene texture 68 | LTexture gModulatedTexture; 69 | 70 | 71 | LTexture::LTexture() 72 | { 73 | //Initialize 74 | mTexture = NULL; 75 | mWidth = 0; 76 | mHeight = 0; 77 | } 78 | 79 | LTexture::~LTexture() 80 | { 81 | //Deallocate 82 | free(); 83 | } 84 | 85 | bool LTexture::loadFromFile( std::string path ) 86 | { 87 | //Get rid of preexisting texture 88 | free(); 89 | 90 | //The final texture 91 | SDL_Texture* newTexture = NULL; 92 | 93 | //Load image at specified path 94 | SDL_Surface* loadedSurface = IMG_Load( path.c_str() ); 95 | if( loadedSurface == NULL ) 96 | { 97 | printf( "Unable to load image %s! SDL_image Error: %s\n", path.c_str(), IMG_GetError() ); 98 | } 99 | else 100 | { 101 | //Color key image 102 | SDL_SetColorKey( loadedSurface, SDL_TRUE, SDL_MapRGB( loadedSurface->format, 0, 0xFF, 0xFF ) ); 103 | 104 | //Create texture from surface pixels 105 | newTexture = SDL_CreateTextureFromSurface( gRenderer, loadedSurface ); 106 | if( newTexture == NULL ) 107 | { 108 | printf( "Unable to create texture from %s! SDL Error: %s\n", path.c_str(), SDL_GetError() ); 109 | } 110 | else 111 | { 112 | //Get image dimensions 113 | mWidth = loadedSurface->w; 114 | mHeight = loadedSurface->h; 115 | } 116 | 117 | //Get rid of old loaded surface 118 | SDL_FreeSurface( loadedSurface ); 119 | } 120 | 121 | //Return success 122 | mTexture = newTexture; 123 | return mTexture != NULL; 124 | } 125 | 126 | void LTexture::free() 127 | { 128 | //Free texture if it exists 129 | if( mTexture != NULL ) 130 | { 131 | SDL_DestroyTexture( mTexture ); 132 | mTexture = NULL; 133 | mWidth = 0; 134 | mHeight = 0; 135 | } 136 | } 137 | 138 | void LTexture::setColor( Uint8 red, Uint8 green, Uint8 blue ) 139 | { 140 | //Modulate texture 141 | SDL_SetTextureColorMod( mTexture, red, green, blue ); 142 | } 143 | 144 | void LTexture::render( int x, int y, SDL_Rect* clip ) 145 | { 146 | //Set rendering space and render to screen 147 | SDL_Rect renderQuad = { x, y, mWidth, mHeight }; 148 | 149 | //Set clip rendering dimensions 150 | if( clip != NULL ) 151 | { 152 | renderQuad.w = clip->w; 153 | renderQuad.h = clip->h; 154 | } 155 | 156 | //Render to screen 157 | SDL_RenderCopy( gRenderer, mTexture, clip, &renderQuad ); 158 | } 159 | 160 | int LTexture::getWidth() 161 | { 162 | return mWidth; 163 | } 164 | 165 | int LTexture::getHeight() 166 | { 167 | return mHeight; 168 | } 169 | 170 | bool init() 171 | { 172 | //Initialization flag 173 | bool success = true; 174 | 175 | //Initialize SDL 176 | if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) 177 | { 178 | printf( "SDL could not initialize! SDL Error: %s\n", SDL_GetError() ); 179 | success = false; 180 | } 181 | else 182 | { 183 | //Set texture filtering to linear 184 | if( !SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" ) ) 185 | { 186 | printf( "Warning: Linear texture filtering not enabled!" ); 187 | } 188 | 189 | //Create window 190 | gWindow = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN ); 191 | if( gWindow == NULL ) 192 | { 193 | printf( "Window could not be created! %s\n", SDL_GetError() ); 194 | success = false; 195 | } 196 | else 197 | { 198 | //Create renderer for window 199 | gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_ACCELERATED ); 200 | 201 | //try software render if hardware fails 202 | if( gRenderer == NULL ) 203 | { 204 | SDL_Log( "Accelerated renderer could not be created! SDL Error: %s\nSwitching to software renderer", SDL_GetError() ); 205 | gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_SOFTWARE); 206 | } 207 | 208 | if( gRenderer == NULL ) 209 | { 210 | printf( "Renderer could not be created! SDL Error: %s\n", SDL_GetError() ); 211 | success = false; 212 | } 213 | else 214 | { 215 | //Initialize renderer color 216 | SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF ); 217 | 218 | //Initialize PNG loading 219 | int imgFlags = IMG_INIT_PNG; 220 | if( !( IMG_Init( imgFlags ) & imgFlags ) ) 221 | { 222 | printf( "SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError() ); 223 | success = false; 224 | } 225 | } 226 | } 227 | } 228 | 229 | return success; 230 | } 231 | 232 | bool loadMedia() 233 | { 234 | //Loading success flag 235 | bool success = true; 236 | 237 | //Load texture 238 | if( !gModulatedTexture.loadFromFile( "assets/colors.png" ) ) 239 | { 240 | printf( "Failed to load colors texture!\n" ); 241 | success = false; 242 | } 243 | 244 | return success; 245 | } 246 | 247 | void close() 248 | { 249 | //Free loaded images 250 | gModulatedTexture.free(); 251 | 252 | //Destroy window 253 | SDL_DestroyRenderer( gRenderer ); 254 | SDL_DestroyWindow( gWindow ); 255 | gWindow = NULL; 256 | gRenderer = NULL; 257 | 258 | //Quit SDL subsystems 259 | IMG_Quit(); 260 | SDL_Quit(); 261 | } 262 | 263 | //Main loop flag 264 | bool quit = false; 265 | 266 | //Modulation components 267 | Uint8 r = 255; 268 | Uint8 g = 255; 269 | Uint8 b = 255; 270 | 271 | 272 | void loop_handler(void*) 273 | { 274 | //Event handler 275 | SDL_Event e; 276 | //Handle events on queue 277 | while( SDL_PollEvent( &e ) != 0 ) 278 | { 279 | //User requests quit 280 | if( e.type == SDL_QUIT ) 281 | { 282 | quit = true; 283 | } 284 | //On keypress change rgb values 285 | else if( e.type == SDL_KEYDOWN ) 286 | { 287 | switch( e.key.keysym.sym ) 288 | { 289 | //Increase red 290 | case SDLK_q: 291 | r += 32; 292 | break; 293 | 294 | //Increase green 295 | case SDLK_w: 296 | g += 32; 297 | break; 298 | 299 | //Increase blue 300 | case SDLK_e: 301 | b += 32; 302 | break; 303 | 304 | //Decrease red 305 | case SDLK_a: 306 | r -= 32; 307 | break; 308 | 309 | //Decrease green 310 | case SDLK_s: 311 | g -= 32; 312 | break; 313 | 314 | //Decrease blue 315 | case SDLK_d: 316 | b -= 32; 317 | break; 318 | } 319 | } 320 | } 321 | 322 | //Clear screen 323 | SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF ); 324 | SDL_RenderClear( gRenderer ); 325 | 326 | //Modulate and render texture 327 | gModulatedTexture.setColor( r, g, b ); 328 | gModulatedTexture.render( 0, 0 ); 329 | 330 | //Update screen 331 | SDL_RenderPresent( gRenderer ); 332 | 333 | } 334 | 335 | int main( int argc, char* args[] ) 336 | { 337 | //Start up SDL and create window 338 | if( !init() ) 339 | { 340 | printf( "Failed to initialize!\n" ); 341 | } 342 | else 343 | { 344 | //Load media 345 | if( !loadMedia() ) 346 | { 347 | printf( "Failed to load media!\n" ); 348 | } 349 | else 350 | { 351 | #ifdef _JS 352 | 353 | emscripten_set_main_loop_arg(loop_handler, NULL, -1, 1); 354 | #else 355 | //While application is running 356 | while( !quit ) 357 | { 358 | loop_handler(NULL); 359 | } 360 | #endif 361 | 362 | 363 | } 364 | } 365 | 366 | //Free resources and close SDL 367 | close(); 368 | 369 | return 0; 370 | } 371 | -------------------------------------------------------------------------------- /12_color_modulation/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /12_color_modulation/assets/colors.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/12_color_modulation/assets/colors.png -------------------------------------------------------------------------------- /12_color_modulation/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | 13 | *nix: 14 | SDL2 15 | SDL2_image 16 | -------------------------------------------------------------------------------- /13_alpha_blending/13_alpha_blending.cpp: -------------------------------------------------------------------------------- 1 | /*This source code copyrighted by Lazy Foo' Productions (2004-2015) 2 | and may not be redistributed without written permission.*/ 3 | 4 | //Using SDL, SDL_image, standard IO, and strings 5 | #include 6 | #include 7 | #include 8 | #include 9 | #ifdef _JS 10 | #include 11 | #endif 12 | 13 | //Screen dimension constants 14 | const int SCREEN_WIDTH = 640; 15 | const int SCREEN_HEIGHT = 480; 16 | 17 | //Texture wrapper class 18 | class LTexture 19 | { 20 | public: 21 | //Initializes variables 22 | LTexture(); 23 | 24 | //Deallocates memory 25 | ~LTexture(); 26 | 27 | //Loads image at specified path 28 | bool loadFromFile( std::string path ); 29 | 30 | //Deallocates texture 31 | void free(); 32 | 33 | //Set color modulation 34 | void setColor( Uint8 red, Uint8 green, Uint8 blue ); 35 | 36 | //Set blending 37 | void setBlendMode( SDL_BlendMode blending ); 38 | 39 | //Set alpha modulation 40 | void setAlpha( Uint8 alpha ); 41 | 42 | //Renders texture at given point 43 | void render( int x, int y, SDL_Rect* clip = NULL ); 44 | 45 | //Gets image dimensions 46 | int getWidth(); 47 | int getHeight(); 48 | 49 | private: 50 | //The actual hardware texture 51 | SDL_Texture* mTexture; 52 | 53 | //Image dimensions 54 | int mWidth; 55 | int mHeight; 56 | }; 57 | 58 | //Starts up SDL and creates window 59 | bool init(); 60 | 61 | //Loads media 62 | bool loadMedia(); 63 | 64 | //Frees media and shuts down SDL 65 | void close(); 66 | 67 | //The window we'll be rendering to 68 | SDL_Window* gWindow = NULL; 69 | 70 | //The window renderer 71 | SDL_Renderer* gRenderer = NULL; 72 | 73 | //Scene textures 74 | LTexture gModulatedTexture; 75 | LTexture gBackgroundTexture; 76 | 77 | 78 | LTexture::LTexture() 79 | { 80 | //Initialize 81 | mTexture = NULL; 82 | mWidth = 0; 83 | mHeight = 0; 84 | } 85 | 86 | LTexture::~LTexture() 87 | { 88 | //Deallocate 89 | free(); 90 | } 91 | 92 | bool LTexture::loadFromFile( std::string path ) 93 | { 94 | //Get rid of preexisting texture 95 | free(); 96 | 97 | //The final texture 98 | SDL_Texture* newTexture = NULL; 99 | 100 | //Load image at specified path 101 | SDL_Surface* loadedSurface = IMG_Load( path.c_str() ); 102 | if( loadedSurface == NULL ) 103 | { 104 | printf( "Unable to load image %s! SDL_image Error: %s\n", path.c_str(), IMG_GetError() ); 105 | } 106 | else 107 | { 108 | //Color key image 109 | SDL_SetColorKey( loadedSurface, SDL_TRUE, SDL_MapRGB( loadedSurface->format, 0, 0xFF, 0xFF ) ); 110 | 111 | //Create texture from surface pixels 112 | newTexture = SDL_CreateTextureFromSurface( gRenderer, loadedSurface ); 113 | if( newTexture == NULL ) 114 | { 115 | printf( "Unable to create texture from %s! SDL Error: %s\n", path.c_str(), SDL_GetError() ); 116 | } 117 | else 118 | { 119 | //Get image dimensions 120 | mWidth = loadedSurface->w; 121 | mHeight = loadedSurface->h; 122 | } 123 | 124 | //Get rid of old loaded surface 125 | SDL_FreeSurface( loadedSurface ); 126 | } 127 | 128 | //Return success 129 | mTexture = newTexture; 130 | return mTexture != NULL; 131 | } 132 | 133 | void LTexture::free() 134 | { 135 | //Free texture if it exists 136 | if( mTexture != NULL ) 137 | { 138 | SDL_DestroyTexture( mTexture ); 139 | mTexture = NULL; 140 | mWidth = 0; 141 | mHeight = 0; 142 | } 143 | } 144 | 145 | void LTexture::setColor( Uint8 red, Uint8 green, Uint8 blue ) 146 | { 147 | //Modulate texture rgb 148 | SDL_SetTextureColorMod( mTexture, red, green, blue ); 149 | } 150 | 151 | void LTexture::setBlendMode( SDL_BlendMode blending ) 152 | { 153 | //Set blending function 154 | SDL_SetTextureBlendMode( mTexture, blending ); 155 | } 156 | 157 | void LTexture::setAlpha( Uint8 alpha ) 158 | { 159 | //Modulate texture alpha 160 | SDL_SetTextureAlphaMod( mTexture, alpha ); 161 | } 162 | 163 | void LTexture::render( int x, int y, SDL_Rect* clip ) 164 | { 165 | //Set rendering space and render to screen 166 | SDL_Rect renderQuad = { x, y, mWidth, mHeight }; 167 | 168 | //Set clip rendering dimensions 169 | if( clip != NULL ) 170 | { 171 | renderQuad.w = clip->w; 172 | renderQuad.h = clip->h; 173 | } 174 | 175 | //Render to screen 176 | SDL_RenderCopy( gRenderer, mTexture, clip, &renderQuad ); 177 | } 178 | 179 | int LTexture::getWidth() 180 | { 181 | return mWidth; 182 | } 183 | 184 | int LTexture::getHeight() 185 | { 186 | return mHeight; 187 | } 188 | 189 | bool init() 190 | { 191 | //Initialization flag 192 | bool success = true; 193 | 194 | //Initialize SDL 195 | if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) 196 | { 197 | printf( "SDL could not initialize! SDL Error: %s\n", SDL_GetError() ); 198 | success = false; 199 | } 200 | else 201 | { 202 | //Set texture filtering to linear 203 | if( !SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" ) ) 204 | { 205 | printf( "Warning: Linear texture filtering not enabled!" ); 206 | } 207 | 208 | //Create window 209 | gWindow = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN ); 210 | if( gWindow == NULL ) 211 | { 212 | printf( "Window could not be created! SDL Error: %s\n", SDL_GetError() ); 213 | success = false; 214 | } 215 | else 216 | { 217 | //Create renderer for window 218 | gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_ACCELERATED ); 219 | 220 | //try software render if hardware fails 221 | if( gRenderer == NULL ) 222 | { 223 | SDL_Log( "Accelerated renderer could not be created! SDL Error: %s\nSwitching to software renderer", SDL_GetError() ); 224 | gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_SOFTWARE); 225 | } 226 | 227 | if( gRenderer == NULL ) 228 | { 229 | printf( "Renderer could not be created! SDL Error: %s\n", SDL_GetError() ); 230 | success = false; 231 | } 232 | else 233 | { 234 | //Initialize renderer color 235 | SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF ); 236 | 237 | //Initialize PNG loading 238 | int imgFlags = IMG_INIT_PNG; 239 | if( !( IMG_Init( imgFlags ) & imgFlags ) ) 240 | { 241 | printf( "SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError() ); 242 | success = false; 243 | } 244 | } 245 | } 246 | } 247 | 248 | return success; 249 | } 250 | 251 | bool loadMedia() 252 | { 253 | //Loading success flag 254 | bool success = true; 255 | 256 | //Load front alpha texture 257 | if( !gModulatedTexture.loadFromFile( "assets/fadeout.png" ) ) 258 | { 259 | printf( "Failed to load front texture!\n" ); 260 | success = false; 261 | } 262 | else 263 | { 264 | //Set standard alpha blending 265 | gModulatedTexture.setBlendMode( SDL_BLENDMODE_BLEND ); 266 | } 267 | 268 | //Load background texture 269 | if( !gBackgroundTexture.loadFromFile( "assets/fadein.png" ) ) 270 | { 271 | printf( "Failed to load background texture!\n" ); 272 | success = false; 273 | } 274 | 275 | return success; 276 | } 277 | 278 | void close() 279 | { 280 | //Free loaded images 281 | gModulatedTexture.free(); 282 | gBackgroundTexture.free(); 283 | 284 | //Destroy window 285 | SDL_DestroyRenderer( gRenderer ); 286 | SDL_DestroyWindow( gWindow ); 287 | gWindow = NULL; 288 | gRenderer = NULL; 289 | 290 | //Quit SDL subsystems 291 | IMG_Quit(); 292 | SDL_Quit(); 293 | } 294 | 295 | //Main loop flag 296 | bool quit = false; 297 | 298 | 299 | //Modulation component 300 | Uint8 a = 255; 301 | 302 | void loop_handler(void*) 303 | { 304 | //Event handler 305 | SDL_Event e; 306 | //Handle events on queue 307 | while( SDL_PollEvent( &e ) != 0 ) 308 | { 309 | //User requests quit 310 | if( e.type == SDL_QUIT ) 311 | { 312 | quit = true; 313 | } 314 | //Handle key presses 315 | else if( e.type == SDL_KEYDOWN ) 316 | { 317 | //Increase alpha on w 318 | if( e.key.keysym.sym == SDLK_w ) 319 | { 320 | //Cap if over 255 321 | if( a + 32 > 255 ) 322 | { 323 | a = 255; 324 | } 325 | //Increment otherwise 326 | else 327 | { 328 | a += 32; 329 | } 330 | } 331 | //Decrease alpha on s 332 | else if( e.key.keysym.sym == SDLK_s ) 333 | { 334 | //Cap if below 0 335 | if( a - 32 < 0 ) 336 | { 337 | a = 0; 338 | } 339 | //Decrement otherwise 340 | else 341 | { 342 | a -= 32; 343 | } 344 | } 345 | } 346 | } 347 | 348 | //Clear screen 349 | SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF ); 350 | SDL_RenderClear( gRenderer ); 351 | 352 | //Render background 353 | gBackgroundTexture.render( 0, 0 ); 354 | 355 | //Render front blended 356 | gModulatedTexture.setAlpha( a ); 357 | gModulatedTexture.render( 0, 0 ); 358 | 359 | //Update screen 360 | SDL_RenderPresent( gRenderer ); 361 | 362 | } 363 | 364 | int main( int argc, char* args[] ) 365 | { 366 | //Start up SDL and create window 367 | if( !init() ) 368 | { 369 | printf( "Failed to initialize!\n" ); 370 | } 371 | else 372 | { 373 | //Load media 374 | if( !loadMedia() ) 375 | { 376 | printf( "Failed to load media!\n" ); 377 | } 378 | else 379 | { 380 | #ifdef _JS 381 | 382 | emscripten_set_main_loop_arg(loop_handler, NULL, -1, 1); 383 | #else 384 | //While application is running 385 | while( !quit ) 386 | { 387 | loop_handler(NULL); 388 | } 389 | #endif 390 | 391 | 392 | } 393 | } 394 | 395 | //Free resources and close SDL 396 | close(); 397 | 398 | return 0; 399 | } 400 | -------------------------------------------------------------------------------- /13_alpha_blending/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /13_alpha_blending/assets/fadein.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/13_alpha_blending/assets/fadein.png -------------------------------------------------------------------------------- /13_alpha_blending/assets/fadeout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/13_alpha_blending/assets/fadeout.png -------------------------------------------------------------------------------- /13_alpha_blending/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | 13 | *nix: 14 | SDL2 15 | SDL2_image 16 | -------------------------------------------------------------------------------- /14_animated_sprites_and_vsync/14_animated_sprites_and_vsync.cpp: -------------------------------------------------------------------------------- 1 | /*This source code copyrighted by Lazy Foo' Productions (2004-2015) 2 | and may not be redistributed without written permission.*/ 3 | 4 | //Using SDL, SDL_image, standard IO, and strings 5 | #include 6 | #include 7 | #include 8 | #include 9 | #ifdef _JS 10 | #include 11 | #endif 12 | 13 | //Screen dimension constants 14 | const int SCREEN_WIDTH = 640; 15 | const int SCREEN_HEIGHT = 480; 16 | 17 | //Texture wrapper class 18 | class LTexture 19 | { 20 | public: 21 | //Initializes variables 22 | LTexture(); 23 | 24 | //Deallocates memory 25 | ~LTexture(); 26 | 27 | //Loads image at specified path 28 | bool loadFromFile( std::string path ); 29 | 30 | //Deallocates texture 31 | void free(); 32 | 33 | //Set color modulation 34 | void setColor( Uint8 red, Uint8 green, Uint8 blue ); 35 | 36 | //Set blending 37 | void setBlendMode( SDL_BlendMode blending ); 38 | 39 | //Set alpha modulation 40 | void setAlpha( Uint8 alpha ); 41 | 42 | //Renders texture at given point 43 | void render( int x, int y, SDL_Rect* clip = NULL ); 44 | 45 | //Gets image dimensions 46 | int getWidth(); 47 | int getHeight(); 48 | 49 | private: 50 | //The actual hardware texture 51 | SDL_Texture* mTexture; 52 | 53 | //Image dimensions 54 | int mWidth; 55 | int mHeight; 56 | }; 57 | 58 | //Starts up SDL and creates window 59 | bool init(); 60 | 61 | //Loads media 62 | bool loadMedia(); 63 | 64 | //Frees media and shuts down SDL 65 | void close(); 66 | 67 | //The window we'll be rendering to 68 | SDL_Window* gWindow = NULL; 69 | 70 | //The window renderer 71 | SDL_Renderer* gRenderer = NULL; 72 | 73 | //Walking animation 74 | const int WALKING_ANIMATION_FRAMES = 4; 75 | SDL_Rect gSpriteClips[ WALKING_ANIMATION_FRAMES ]; 76 | LTexture gSpriteSheetTexture; 77 | 78 | 79 | LTexture::LTexture() 80 | { 81 | //Initialize 82 | mTexture = NULL; 83 | mWidth = 0; 84 | mHeight = 0; 85 | } 86 | 87 | LTexture::~LTexture() 88 | { 89 | //Deallocate 90 | free(); 91 | } 92 | 93 | bool LTexture::loadFromFile( std::string path ) 94 | { 95 | //Get rid of preexisting texture 96 | free(); 97 | 98 | //The final texture 99 | SDL_Texture* newTexture = NULL; 100 | 101 | //Load image at specified path 102 | SDL_Surface* loadedSurface = IMG_Load( path.c_str() ); 103 | if( loadedSurface == NULL ) 104 | { 105 | printf( "Unable to load image %s! SDL_image Error: %s\n", path.c_str(), IMG_GetError() ); 106 | } 107 | else 108 | { 109 | //Color key image 110 | SDL_SetColorKey( loadedSurface, SDL_TRUE, SDL_MapRGB( loadedSurface->format, 0, 0xFF, 0xFF ) ); 111 | 112 | //Create texture from surface pixels 113 | newTexture = SDL_CreateTextureFromSurface( gRenderer, loadedSurface ); 114 | if( newTexture == NULL ) 115 | { 116 | printf( "Unable to create texture from %s! SDL Error: %s\n", path.c_str(), SDL_GetError() ); 117 | } 118 | else 119 | { 120 | //Get image dimensions 121 | mWidth = loadedSurface->w; 122 | mHeight = loadedSurface->h; 123 | } 124 | 125 | //Get rid of old loaded surface 126 | SDL_FreeSurface( loadedSurface ); 127 | } 128 | 129 | //Return success 130 | mTexture = newTexture; 131 | return mTexture != NULL; 132 | } 133 | 134 | void LTexture::free() 135 | { 136 | //Free texture if it exists 137 | if( mTexture != NULL ) 138 | { 139 | SDL_DestroyTexture( mTexture ); 140 | mTexture = NULL; 141 | mWidth = 0; 142 | mHeight = 0; 143 | } 144 | } 145 | 146 | void LTexture::setColor( Uint8 red, Uint8 green, Uint8 blue ) 147 | { 148 | //Modulate texture rgb 149 | SDL_SetTextureColorMod( mTexture, red, green, blue ); 150 | } 151 | 152 | void LTexture::setBlendMode( SDL_BlendMode blending ) 153 | { 154 | //Set blending function 155 | SDL_SetTextureBlendMode( mTexture, blending ); 156 | } 157 | 158 | void LTexture::setAlpha( Uint8 alpha ) 159 | { 160 | //Modulate texture alpha 161 | SDL_SetTextureAlphaMod( mTexture, alpha ); 162 | } 163 | 164 | void LTexture::render( int x, int y, SDL_Rect* clip ) 165 | { 166 | //Set rendering space and render to screen 167 | SDL_Rect renderQuad = { x, y, mWidth, mHeight }; 168 | 169 | //Set clip rendering dimensions 170 | if( clip != NULL ) 171 | { 172 | renderQuad.w = clip->w; 173 | renderQuad.h = clip->h; 174 | } 175 | 176 | //Render to screen 177 | SDL_RenderCopy( gRenderer, mTexture, clip, &renderQuad ); 178 | } 179 | 180 | int LTexture::getWidth() 181 | { 182 | return mWidth; 183 | } 184 | 185 | int LTexture::getHeight() 186 | { 187 | return mHeight; 188 | } 189 | 190 | bool init() 191 | { 192 | //Initialization flag 193 | bool success = true; 194 | 195 | //Initialize SDL 196 | if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) 197 | { 198 | printf( "SDL could not initialize! SDL Error: %s\n", SDL_GetError() ); 199 | success = false; 200 | } 201 | else 202 | { 203 | //Set texture filtering to linear 204 | if( !SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" ) ) 205 | { 206 | printf( "Warning: Linear texture filtering not enabled!" ); 207 | } 208 | 209 | //Create window 210 | gWindow = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN ); 211 | if( gWindow == NULL ) 212 | { 213 | printf( "Window could not be created! SDL Error: %s\n", SDL_GetError() ); 214 | success = false; 215 | } 216 | else 217 | { 218 | //Create vsynced renderer for window 219 | gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC ); 220 | 221 | //try software render if hardware fails 222 | if( gRenderer == NULL ) 223 | { 224 | SDL_Log( "Accelerated renderer could not be created! SDL Error: %s\nSwitching to software renderer", SDL_GetError() ); 225 | gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_SOFTWARE); 226 | } 227 | 228 | if( gRenderer == NULL ) 229 | { 230 | printf( "Renderer could not be created! SDL Error: %s\n", SDL_GetError() ); 231 | success = false; 232 | } 233 | else 234 | { 235 | //Initialize renderer color 236 | SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF ); 237 | 238 | //Initialize PNG loading 239 | int imgFlags = IMG_INIT_PNG; 240 | if( !( IMG_Init( imgFlags ) & imgFlags ) ) 241 | { 242 | printf( "SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError() ); 243 | success = false; 244 | } 245 | } 246 | } 247 | } 248 | 249 | return success; 250 | } 251 | 252 | bool loadMedia() 253 | { 254 | //Loading success flag 255 | bool success = true; 256 | 257 | //Load sprite sheet texture 258 | if( !gSpriteSheetTexture.loadFromFile( "assets/foo.png" ) ) 259 | { 260 | printf( "Failed to load walking animation texture!\n" ); 261 | success = false; 262 | } 263 | else 264 | { 265 | //Set sprite clips 266 | gSpriteClips[ 0 ].x = 0; 267 | gSpriteClips[ 0 ].y = 0; 268 | gSpriteClips[ 0 ].w = 64; 269 | gSpriteClips[ 0 ].h = 205; 270 | 271 | gSpriteClips[ 1 ].x = 64; 272 | gSpriteClips[ 1 ].y = 0; 273 | gSpriteClips[ 1 ].w = 64; 274 | gSpriteClips[ 1 ].h = 205; 275 | 276 | gSpriteClips[ 2 ].x = 128; 277 | gSpriteClips[ 2 ].y = 0; 278 | gSpriteClips[ 2 ].w = 64; 279 | gSpriteClips[ 2 ].h = 205; 280 | 281 | gSpriteClips[ 3 ].x = 196; 282 | gSpriteClips[ 3 ].y = 0; 283 | gSpriteClips[ 3 ].w = 64; 284 | gSpriteClips[ 3 ].h = 205; 285 | } 286 | 287 | return success; 288 | } 289 | 290 | void close() 291 | { 292 | //Free loaded images 293 | gSpriteSheetTexture.free(); 294 | 295 | //Destroy window 296 | SDL_DestroyRenderer( gRenderer ); 297 | SDL_DestroyWindow( gWindow ); 298 | gWindow = NULL; 299 | gRenderer = NULL; 300 | 301 | //Quit SDL subsystems 302 | IMG_Quit(); 303 | SDL_Quit(); 304 | } 305 | 306 | //Main loop flag 307 | bool quit = false; 308 | //Current animation frame 309 | int frame = 0; 310 | 311 | void loop_handler(void*) 312 | { 313 | //Event handler 314 | SDL_Event e; 315 | //Handle events on queue 316 | while( SDL_PollEvent( &e ) != 0 ) 317 | { 318 | //User requests quit 319 | if( e.type == SDL_QUIT ) 320 | { 321 | quit = true; 322 | } 323 | } 324 | 325 | //Clear screen 326 | SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF ); 327 | SDL_RenderClear( gRenderer ); 328 | 329 | //Render current frame 330 | SDL_Rect* currentClip = &gSpriteClips[ frame / 4 ]; 331 | gSpriteSheetTexture.render( ( SCREEN_WIDTH - currentClip->w ) / 2, ( SCREEN_HEIGHT - currentClip->h ) / 2, currentClip ); 332 | 333 | //Update screen 334 | SDL_RenderPresent( gRenderer ); 335 | 336 | //Go to next frame 337 | ++frame; 338 | 339 | //Cycle animation 340 | if( frame / 4 >= WALKING_ANIMATION_FRAMES ) 341 | { 342 | frame = 0; 343 | } 344 | 345 | } 346 | 347 | int main( int argc, char* args[] ) 348 | { 349 | //Start up SDL and create window 350 | if( !init() ) 351 | { 352 | printf( "Failed to initialize!\n" ); 353 | } 354 | else 355 | { 356 | //Load media 357 | if( !loadMedia() ) 358 | { 359 | printf( "Failed to load media!\n" ); 360 | } 361 | else 362 | { 363 | #ifdef _JS 364 | 365 | emscripten_set_main_loop_arg(loop_handler, NULL, -1, 1); 366 | #else 367 | //While application is running 368 | while( !quit ) 369 | { 370 | loop_handler(NULL); 371 | } 372 | #endif 373 | 374 | 375 | } 376 | } 377 | 378 | //Free resources and close SDL 379 | close(); 380 | 381 | return 0; 382 | } 383 | -------------------------------------------------------------------------------- /14_animated_sprites_and_vsync/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /14_animated_sprites_and_vsync/assets/foo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/14_animated_sprites_and_vsync/assets/foo.png -------------------------------------------------------------------------------- /14_animated_sprites_and_vsync/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | 13 | *nix: 14 | SDL2 15 | SDL2_image 16 | -------------------------------------------------------------------------------- /15_rotation_and_flipping/15_rotation_and_flipping.cpp: -------------------------------------------------------------------------------- 1 | /*This source code copyrighted by Lazy Foo' Productions (2004-2015) 2 | and may not be redistributed without written permission.*/ 3 | 4 | //Using SDL, SDL_image, standard IO, math, and strings 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #ifdef _JS 11 | #include 12 | #endif 13 | 14 | //Screen dimension constants 15 | const int SCREEN_WIDTH = 640; 16 | const int SCREEN_HEIGHT = 480; 17 | 18 | //Texture wrapper class 19 | class LTexture 20 | { 21 | public: 22 | //Initializes variables 23 | LTexture(); 24 | 25 | //Deallocates memory 26 | ~LTexture(); 27 | 28 | //Loads image at specified path 29 | bool loadFromFile( std::string path ); 30 | 31 | //Deallocates texture 32 | void free(); 33 | 34 | //Set color modulation 35 | void setColor( Uint8 red, Uint8 green, Uint8 blue ); 36 | 37 | //Set blending 38 | void setBlendMode( SDL_BlendMode blending ); 39 | 40 | //Set alpha modulation 41 | void setAlpha( Uint8 alpha ); 42 | 43 | //Renders texture at given point 44 | void render( int x, int y, SDL_Rect* clip = NULL, double angle = 0.0, SDL_Point* center = NULL, SDL_RendererFlip flip = SDL_FLIP_NONE ); 45 | 46 | //Gets image dimensions 47 | int getWidth(); 48 | int getHeight(); 49 | 50 | private: 51 | //The actual hardware texture 52 | SDL_Texture* mTexture; 53 | 54 | //Image dimensions 55 | int mWidth; 56 | int mHeight; 57 | }; 58 | 59 | //Starts up SDL and creates window 60 | bool init(); 61 | 62 | //Loads media 63 | bool loadMedia(); 64 | 65 | //Frees media and shuts down SDL 66 | void close(); 67 | 68 | //The window we'll be rendering to 69 | SDL_Window* gWindow = NULL; 70 | 71 | //The window renderer 72 | SDL_Renderer* gRenderer = NULL; 73 | 74 | //Scene texture 75 | LTexture gArrowTexture; 76 | 77 | 78 | LTexture::LTexture() 79 | { 80 | //Initialize 81 | mTexture = NULL; 82 | mWidth = 0; 83 | mHeight = 0; 84 | } 85 | 86 | LTexture::~LTexture() 87 | { 88 | //Deallocate 89 | free(); 90 | } 91 | 92 | bool LTexture::loadFromFile( std::string path ) 93 | { 94 | //Get rid of preexisting texture 95 | free(); 96 | 97 | //The final texture 98 | SDL_Texture* newTexture = NULL; 99 | 100 | //Load image at specified path 101 | SDL_Surface* loadedSurface = IMG_Load( path.c_str() ); 102 | if( loadedSurface == NULL ) 103 | { 104 | printf( "Unable to load image %s! SDL_image Error: %s\n", path.c_str(), IMG_GetError() ); 105 | } 106 | else 107 | { 108 | //Color key image 109 | SDL_SetColorKey( loadedSurface, SDL_TRUE, SDL_MapRGB( loadedSurface->format, 0, 0xFF, 0xFF ) ); 110 | 111 | //Create texture from surface pixels 112 | newTexture = SDL_CreateTextureFromSurface( gRenderer, loadedSurface ); 113 | if( newTexture == NULL ) 114 | { 115 | printf( "Unable to create texture from %s! SDL Error: %s\n", path.c_str(), SDL_GetError() ); 116 | } 117 | else 118 | { 119 | //Get image dimensions 120 | mWidth = loadedSurface->w; 121 | mHeight = loadedSurface->h; 122 | } 123 | 124 | //Get rid of old loaded surface 125 | SDL_FreeSurface( loadedSurface ); 126 | } 127 | 128 | //Return success 129 | mTexture = newTexture; 130 | return mTexture != NULL; 131 | } 132 | 133 | void LTexture::free() 134 | { 135 | //Free texture if it exists 136 | if( mTexture != NULL ) 137 | { 138 | SDL_DestroyTexture( mTexture ); 139 | mTexture = NULL; 140 | mWidth = 0; 141 | mHeight = 0; 142 | } 143 | } 144 | 145 | void LTexture::setColor( Uint8 red, Uint8 green, Uint8 blue ) 146 | { 147 | //Modulate texture rgb 148 | SDL_SetTextureColorMod( mTexture, red, green, blue ); 149 | } 150 | 151 | void LTexture::setBlendMode( SDL_BlendMode blending ) 152 | { 153 | //Set blending function 154 | SDL_SetTextureBlendMode( mTexture, blending ); 155 | } 156 | 157 | void LTexture::setAlpha( Uint8 alpha ) 158 | { 159 | //Modulate texture alpha 160 | SDL_SetTextureAlphaMod( mTexture, alpha ); 161 | } 162 | 163 | void LTexture::render( int x, int y, SDL_Rect* clip, double angle, SDL_Point* center, SDL_RendererFlip flip ) 164 | { 165 | //Set rendering space and render to screen 166 | SDL_Rect renderQuad = { x, y, mWidth, mHeight }; 167 | 168 | //Set clip rendering dimensions 169 | if( clip != NULL ) 170 | { 171 | renderQuad.w = clip->w; 172 | renderQuad.h = clip->h; 173 | } 174 | 175 | //Render to screen 176 | SDL_RenderCopyEx( gRenderer, mTexture, clip, &renderQuad, angle, center, flip ); 177 | } 178 | 179 | int LTexture::getWidth() 180 | { 181 | return mWidth; 182 | } 183 | 184 | int LTexture::getHeight() 185 | { 186 | return mHeight; 187 | } 188 | 189 | bool init() 190 | { 191 | //Initialization flag 192 | bool success = true; 193 | 194 | //Initialize SDL 195 | if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) 196 | { 197 | printf( "SDL could not initialize! SDL Error: %s\n", SDL_GetError() ); 198 | success = false; 199 | } 200 | else 201 | { 202 | //Set texture filtering to linear 203 | if( !SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" ) ) 204 | { 205 | printf( "Warning: Linear texture filtering not enabled!" ); 206 | } 207 | 208 | //Create window 209 | gWindow = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN ); 210 | if( gWindow == NULL ) 211 | { 212 | printf( "Window could not be created! SDL Error: %s\n", SDL_GetError() ); 213 | success = false; 214 | } 215 | else 216 | { 217 | //Create vsynced renderer for window 218 | gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC ); 219 | 220 | //try software render if hardware fails 221 | if( gRenderer == NULL ) 222 | { 223 | SDL_Log( "Accelerated renderer could not be created! SDL Error: %s\nSwitching to software renderer", SDL_GetError() ); 224 | gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_SOFTWARE); 225 | } 226 | 227 | if( gRenderer == NULL ) 228 | { 229 | printf( "Renderer could not be created! SDL Error: %s\n", SDL_GetError() ); 230 | success = false; 231 | } 232 | else 233 | { 234 | //Initialize renderer color 235 | SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF ); 236 | 237 | //Initialize PNG loading 238 | int imgFlags = IMG_INIT_PNG; 239 | if( !( IMG_Init( imgFlags ) & imgFlags ) ) 240 | { 241 | printf( "SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError() ); 242 | success = false; 243 | } 244 | } 245 | } 246 | } 247 | 248 | return success; 249 | } 250 | 251 | bool loadMedia() 252 | { 253 | //Loading success flag 254 | bool success = true; 255 | 256 | //Load arrow 257 | if( !gArrowTexture.loadFromFile( "assets/arrow.png" ) ) 258 | { 259 | printf( "Failed to load arrow texture!\n" ); 260 | success = false; 261 | } 262 | 263 | return success; 264 | } 265 | 266 | void close() 267 | { 268 | //Free loaded images 269 | gArrowTexture.free(); 270 | 271 | //Destroy window 272 | SDL_DestroyRenderer( gRenderer ); 273 | SDL_DestroyWindow( gWindow ); 274 | gWindow = NULL; 275 | gRenderer = NULL; 276 | 277 | //Quit SDL subsystems 278 | IMG_Quit(); 279 | SDL_Quit(); 280 | } 281 | 282 | //Main loop flag 283 | bool quit = false; 284 | 285 | //Angle of rotation 286 | double degrees = 0; 287 | 288 | //Flip type 289 | SDL_RendererFlip flipType = SDL_FLIP_NONE; 290 | 291 | void loop_handler(void*) 292 | { 293 | //Event handler 294 | SDL_Event e; 295 | //Handle events on queue 296 | while( SDL_PollEvent( &e ) != 0 ) 297 | { 298 | //User requests quit 299 | if( e.type == SDL_QUIT ) 300 | { 301 | quit = true; 302 | } 303 | else if( e.type == SDL_KEYDOWN ) 304 | { 305 | switch( e.key.keysym.sym ) 306 | { 307 | case SDLK_a: 308 | degrees -= 60; 309 | break; 310 | 311 | case SDLK_d: 312 | degrees += 60; 313 | break; 314 | 315 | case SDLK_q: 316 | flipType = SDL_FLIP_HORIZONTAL; 317 | break; 318 | 319 | case SDLK_w: 320 | flipType = SDL_FLIP_NONE; 321 | break; 322 | 323 | case SDLK_e: 324 | flipType = SDL_FLIP_VERTICAL; 325 | break; 326 | } 327 | } 328 | } 329 | 330 | //Clear screen 331 | SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF ); 332 | SDL_RenderClear( gRenderer ); 333 | 334 | //Render arrow 335 | gArrowTexture.render( ( SCREEN_WIDTH - gArrowTexture.getWidth() ) / 2, ( SCREEN_HEIGHT - gArrowTexture.getHeight() ) / 2, NULL, degrees, NULL, flipType ); 336 | 337 | //Update screen 338 | SDL_RenderPresent( gRenderer ); 339 | 340 | } 341 | 342 | int main( int argc, char* args[] ) 343 | { 344 | //Start up SDL and create window 345 | if( !init() ) 346 | { 347 | printf( "Failed to initialize!\n" ); 348 | } 349 | else 350 | { 351 | //Load media 352 | if( !loadMedia() ) 353 | { 354 | printf( "Failed to load media!\n" ); 355 | } 356 | else 357 | { 358 | #ifdef _JS 359 | 360 | emscripten_set_main_loop_arg(loop_handler, NULL, -1, 1); 361 | #else 362 | //While application is running 363 | while( !quit ) 364 | { 365 | loop_handler(NULL); 366 | } 367 | #endif 368 | 369 | } 370 | } 371 | 372 | //Free resources and close SDL 373 | close(); 374 | 375 | return 0; 376 | } 377 | -------------------------------------------------------------------------------- /15_rotation_and_flipping/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /15_rotation_and_flipping/assets/arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/15_rotation_and_flipping/assets/arrow.png -------------------------------------------------------------------------------- /15_rotation_and_flipping/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | 13 | *nix: 14 | SDL2 15 | SDL2_image 16 | -------------------------------------------------------------------------------- /16_true_type_fonts/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /16_true_type_fonts/assets/lazy.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/16_true_type_fonts/assets/lazy.ttf -------------------------------------------------------------------------------- /16_true_type_fonts/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | SDL2_ttf 13 | 14 | *nix: 15 | SDL2 16 | SDL2_image 17 | SDL2_ttf 18 | -------------------------------------------------------------------------------- /17_mouse_events/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /17_mouse_events/assets/button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/17_mouse_events/assets/button.png -------------------------------------------------------------------------------- /17_mouse_events/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | SDL2_ttf 13 | 14 | *nix: 15 | SDL2 16 | SDL2_image 17 | SDL2_ttf 18 | -------------------------------------------------------------------------------- /18_key_states/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /18_key_states/assets/down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/18_key_states/assets/down.png -------------------------------------------------------------------------------- /18_key_states/assets/left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/18_key_states/assets/left.png -------------------------------------------------------------------------------- /18_key_states/assets/press.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/18_key_states/assets/press.png -------------------------------------------------------------------------------- /18_key_states/assets/right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/18_key_states/assets/right.png -------------------------------------------------------------------------------- /18_key_states/assets/up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/18_key_states/assets/up.png -------------------------------------------------------------------------------- /18_key_states/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | SDL2_ttf 13 | 14 | *nix: 15 | SDL2 16 | SDL2_image 17 | SDL2_ttf 18 | -------------------------------------------------------------------------------- /19_gamepads_and_joysticks/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /19_gamepads_and_joysticks/assets/arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/19_gamepads_and_joysticks/assets/arrow.png -------------------------------------------------------------------------------- /19_gamepads_and_joysticks/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | SDL2_ttf 13 | 14 | *nix: 15 | SDL2 16 | SDL2_image 17 | SDL2_ttf 18 | -------------------------------------------------------------------------------- /20_force_feedback/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /20_force_feedback/assets/splash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/20_force_feedback/assets/splash.png -------------------------------------------------------------------------------- /20_force_feedback/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | SDL2_ttf 13 | 14 | *nix: 15 | SDL2 16 | SDL2_image 17 | SDL2_ttf 18 | -------------------------------------------------------------------------------- /21_sound_effects_and_music/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | # $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /21_sound_effects_and_music/assets/beat.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/21_sound_effects_and_music/assets/beat.wav -------------------------------------------------------------------------------- /21_sound_effects_and_music/assets/high.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/21_sound_effects_and_music/assets/high.wav -------------------------------------------------------------------------------- /21_sound_effects_and_music/assets/low.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/21_sound_effects_and_music/assets/low.wav -------------------------------------------------------------------------------- /21_sound_effects_and_music/assets/medium.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/21_sound_effects_and_music/assets/medium.wav -------------------------------------------------------------------------------- /21_sound_effects_and_music/assets/prompt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/21_sound_effects_and_music/assets/prompt.png -------------------------------------------------------------------------------- /21_sound_effects_and_music/assets/scratch.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/21_sound_effects_and_music/assets/scratch.wav -------------------------------------------------------------------------------- /21_sound_effects_and_music/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | SDL2_ttf 13 | SDL2_mixer 14 | 15 | *nix: 16 | SDL2 17 | SDL2_image 18 | SDL2_ttf 19 | SDL2_mixer -------------------------------------------------------------------------------- /22_timing/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /22_timing/assets/lazy.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/22_timing/assets/lazy.ttf -------------------------------------------------------------------------------- /22_timing/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | SDL2_ttf 13 | 14 | *nix: 15 | SDL2 16 | SDL2_image 17 | SDL2_ttf 18 | -------------------------------------------------------------------------------- /23_advanced_timers/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /23_advanced_timers/assets/lazy.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/23_advanced_timers/assets/lazy.ttf -------------------------------------------------------------------------------- /23_advanced_timers/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | SDL2_ttf 13 | 14 | *nix: 15 | SDL2 16 | SDL2_image 17 | SDL2_ttf 18 | -------------------------------------------------------------------------------- /24_calculating_frame_rate/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /24_calculating_frame_rate/assets/lazy.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/24_calculating_frame_rate/assets/lazy.ttf -------------------------------------------------------------------------------- /24_calculating_frame_rate/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | SDL2_ttf 13 | 14 | *nix: 15 | SDL2 16 | SDL2_image 17 | SDL2_ttf 18 | -------------------------------------------------------------------------------- /25_capping_frame_rate/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /25_capping_frame_rate/assets/lazy.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/25_capping_frame_rate/assets/lazy.ttf -------------------------------------------------------------------------------- /25_capping_frame_rate/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | SDL2_ttf 13 | 14 | *nix: 15 | SDL2 16 | SDL2_image 17 | SDL2_ttf 18 | -------------------------------------------------------------------------------- /26_motion/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /26_motion/assets/dot.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/26_motion/assets/dot.bmp -------------------------------------------------------------------------------- /26_motion/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | SDL2_ttf 13 | 14 | *nix: 15 | SDL2 16 | SDL2_image 17 | SDL2_ttf 18 | -------------------------------------------------------------------------------- /27_collision_detection/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /27_collision_detection/assets/dot.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/27_collision_detection/assets/dot.bmp -------------------------------------------------------------------------------- /27_collision_detection/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | SDL2_ttf 13 | 14 | *nix: 15 | SDL2 16 | SDL2_image 17 | SDL2_ttf 18 | -------------------------------------------------------------------------------- /28_per-pixel_collision_detection/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /28_per-pixel_collision_detection/assets/dot.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/28_per-pixel_collision_detection/assets/dot.bmp -------------------------------------------------------------------------------- /28_per-pixel_collision_detection/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | SDL2_ttf 13 | 14 | *nix: 15 | SDL2 16 | SDL2_image 17 | SDL2_ttf 18 | -------------------------------------------------------------------------------- /29_circular_collision_detection/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /29_circular_collision_detection/assets/dot.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/29_circular_collision_detection/assets/dot.bmp -------------------------------------------------------------------------------- /29_circular_collision_detection/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | SDL2_ttf 13 | 14 | *nix: 15 | SDL2 16 | SDL2_image 17 | SDL2_ttf 18 | -------------------------------------------------------------------------------- /30_scrolling/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /30_scrolling/assets/bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/30_scrolling/assets/bg.png -------------------------------------------------------------------------------- /30_scrolling/assets/dot.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/30_scrolling/assets/dot.bmp -------------------------------------------------------------------------------- /30_scrolling/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | SDL2_ttf 13 | 14 | *nix: 15 | SDL2 16 | SDL2_image 17 | SDL2_ttf 18 | -------------------------------------------------------------------------------- /31_scrolling_backgrounds/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /31_scrolling_backgrounds/assets/bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/31_scrolling_backgrounds/assets/bg.png -------------------------------------------------------------------------------- /31_scrolling_backgrounds/assets/dot.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/31_scrolling_backgrounds/assets/dot.bmp -------------------------------------------------------------------------------- /31_scrolling_backgrounds/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | SDL2_ttf 13 | 14 | *nix: 15 | SDL2 16 | SDL2_image 17 | SDL2_ttf 18 | -------------------------------------------------------------------------------- /32_text_input_and_clipboard_handling/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /32_text_input_and_clipboard_handling/assets/lazy.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/32_text_input_and_clipboard_handling/assets/lazy.ttf -------------------------------------------------------------------------------- /32_text_input_and_clipboard_handling/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | SDL2_ttf 13 | 14 | *nix: 15 | SDL2 16 | SDL2_image 17 | SDL2_ttf 18 | -------------------------------------------------------------------------------- /33_file_reading_and_writing/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /33_file_reading_and_writing/assets/lazy.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/33_file_reading_and_writing/assets/lazy.ttf -------------------------------------------------------------------------------- /33_file_reading_and_writing/assets/nums.bin: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /33_file_reading_and_writing/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | SDL2_ttf 13 | 14 | *nix: 15 | SDL2 16 | SDL2_image 17 | SDL2_ttf 18 | -------------------------------------------------------------------------------- /35_window_events/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /35_window_events/assets/window.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/35_window_events/assets/window.png -------------------------------------------------------------------------------- /35_window_events/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | SDL2_ttf 13 | 14 | *nix: 15 | SDL2 16 | SDL2_image 17 | SDL2_ttf 18 | -------------------------------------------------------------------------------- /36_multiple_windows/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /36_multiple_windows/assets/place_holder.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/36_multiple_windows/assets/place_holder.txt -------------------------------------------------------------------------------- /36_multiple_windows/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | SDL2_ttf 13 | 14 | *nix: 15 | SDL2 16 | SDL2_image 17 | SDL2_ttf 18 | -------------------------------------------------------------------------------- /37_multiple_displays/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /37_multiple_displays/assets/place_holder.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/37_multiple_displays/assets/place_holder.txt -------------------------------------------------------------------------------- /37_multiple_displays/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | SDL2_ttf 13 | 14 | *nix: 15 | SDL2 16 | SDL2_image 17 | SDL2_ttf 18 | -------------------------------------------------------------------------------- /38_particle_engines/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /38_particle_engines/assets/blue.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/38_particle_engines/assets/blue.bmp -------------------------------------------------------------------------------- /38_particle_engines/assets/dot.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/38_particle_engines/assets/dot.bmp -------------------------------------------------------------------------------- /38_particle_engines/assets/green.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/38_particle_engines/assets/green.bmp -------------------------------------------------------------------------------- /38_particle_engines/assets/red.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/38_particle_engines/assets/red.bmp -------------------------------------------------------------------------------- /38_particle_engines/assets/shimmer.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/38_particle_engines/assets/shimmer.bmp -------------------------------------------------------------------------------- /38_particle_engines/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | SDL2_ttf 13 | 14 | *nix: 15 | SDL2 16 | SDL2_image 17 | SDL2_ttf 18 | -------------------------------------------------------------------------------- /39_tiling/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /39_tiling/assets/dot.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/39_tiling/assets/dot.bmp -------------------------------------------------------------------------------- /39_tiling/assets/lazy.map: -------------------------------------------------------------------------------- 1 | 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02 00 2 | 01 02 00 01 02 00 01 02 00 01 02 00 01 02 00 01 3 | 02 00 11 04 04 04 04 04 04 04 04 04 04 05 01 02 4 | 00 01 10 03 03 03 03 03 03 03 03 03 03 06 02 00 5 | 01 02 10 03 08 08 08 08 08 08 08 03 03 06 00 01 6 | 02 00 10 06 00 01 02 00 01 02 00 10 03 06 01 02 7 | 00 01 10 06 01 11 05 01 02 00 01 10 03 06 02 00 8 | 01 02 10 06 02 09 07 02 00 01 02 10 03 06 00 01 9 | 02 00 10 06 00 01 02 00 01 02 00 10 03 06 01 02 10 | 00 01 10 03 04 04 04 05 02 00 01 09 08 07 02 00 11 | 01 02 09 08 08 08 08 07 00 01 02 00 01 02 00 01 12 | 02 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02 -------------------------------------------------------------------------------- /39_tiling/assets/tiles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/39_tiling/assets/tiles.png -------------------------------------------------------------------------------- /39_tiling/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | SDL2_ttf 13 | 14 | *nix: 15 | SDL2 16 | SDL2_image 17 | SDL2_ttf 18 | -------------------------------------------------------------------------------- /40_texture_manipulation/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /40_texture_manipulation/assets/foo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/40_texture_manipulation/assets/foo.png -------------------------------------------------------------------------------- /40_texture_manipulation/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2017) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | SDL2_ttf 13 | 14 | *nix: 15 | SDL2 16 | SDL2_image 17 | SDL2_ttf 18 | -------------------------------------------------------------------------------- /41_bitmap_fonts/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /41_bitmap_fonts/assets/lazyfont.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/41_bitmap_fonts/assets/lazyfont.png -------------------------------------------------------------------------------- /41_bitmap_fonts/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | SDL2_ttf 13 | 14 | *nix: 15 | SDL2 16 | SDL2_image 17 | SDL2_ttf 18 | -------------------------------------------------------------------------------- /42_texture_streaming/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /42_texture_streaming/assets/foo_walk_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/42_texture_streaming/assets/foo_walk_0.png -------------------------------------------------------------------------------- /42_texture_streaming/assets/foo_walk_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/42_texture_streaming/assets/foo_walk_1.png -------------------------------------------------------------------------------- /42_texture_streaming/assets/foo_walk_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/42_texture_streaming/assets/foo_walk_2.png -------------------------------------------------------------------------------- /42_texture_streaming/assets/foo_walk_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/42_texture_streaming/assets/foo_walk_3.png -------------------------------------------------------------------------------- /42_texture_streaming/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | SDL2_ttf 13 | 14 | *nix: 15 | SDL2 16 | SDL2_image 17 | SDL2_ttf 18 | -------------------------------------------------------------------------------- /43_render_to_texture/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /43_render_to_texture/assets/place_holder.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/43_render_to_texture/assets/place_holder.txt -------------------------------------------------------------------------------- /43_render_to_texture/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | SDL2_ttf 13 | 14 | *nix: 15 | SDL2 16 | SDL2_image 17 | SDL2_ttf 18 | -------------------------------------------------------------------------------- /44_frame_independent_movement/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /44_frame_independent_movement/assets/dot.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/44_frame_independent_movement/assets/dot.bmp -------------------------------------------------------------------------------- /44_frame_independent_movement/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | SDL2_ttf 13 | 14 | *nix: 15 | SDL2 16 | SDL2_image 17 | SDL2_ttf 18 | -------------------------------------------------------------------------------- /45_timer_callbacks/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /45_timer_callbacks/assets/splash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/45_timer_callbacks/assets/splash.png -------------------------------------------------------------------------------- /45_timer_callbacks/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | SDL2_ttf 13 | 14 | *nix: 15 | SDL2 16 | SDL2_image 17 | SDL2_ttf 18 | -------------------------------------------------------------------------------- /46_multithreading/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /46_multithreading/assets/splash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/46_multithreading/assets/splash.png -------------------------------------------------------------------------------- /46_multithreading/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | SDL2_ttf 13 | 14 | *nix: 15 | SDL2 16 | SDL2_image 17 | SDL2_ttf 18 | -------------------------------------------------------------------------------- /47_semaphores/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /47_semaphores/assets/splash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/47_semaphores/assets/splash.png -------------------------------------------------------------------------------- /47_semaphores/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | SDL2_ttf 13 | 14 | *nix: 15 | SDL2 16 | SDL2_image 17 | SDL2_ttf 18 | -------------------------------------------------------------------------------- /48_atomic_operations/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /48_atomic_operations/assets/splash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/48_atomic_operations/assets/splash.png -------------------------------------------------------------------------------- /48_atomic_operations/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | SDL2_ttf 13 | 14 | *nix: 15 | SDL2 16 | SDL2_image 17 | SDL2_ttf 18 | -------------------------------------------------------------------------------- /49_mutexes_and_conditions/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /49_mutexes_and_conditions/assets/splash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/49_mutexes_and_conditions/assets/splash.png -------------------------------------------------------------------------------- /49_mutexes_and_conditions/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | SDL2_ttf 13 | 14 | *nix: 15 | SDL2 16 | SDL2_image 17 | SDL2_ttf 18 | -------------------------------------------------------------------------------- /50_SDL_and_opengl_2/50_SDL_and_opengl_2.cpp: -------------------------------------------------------------------------------- 1 | /*This source code copyrighted by Lazy Foo' Productions (2004-2015) 2 | and may not be redistributed without written permission.*/ 3 | 4 | //Using SDL, SDL OpenGL, standard IO, and, strings 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #ifdef _JS 11 | #include 12 | #endif 13 | 14 | //Screen dimension constants 15 | const int SCREEN_WIDTH = 640; 16 | const int SCREEN_HEIGHT = 480; 17 | 18 | //Starts up SDL, creates window, and initializes OpenGL 19 | bool init(); 20 | 21 | //Initializes matrices and clear color 22 | bool initGL(); 23 | 24 | //Input handler 25 | void handleKeys( unsigned char key, int x, int y ); 26 | 27 | //Per frame update 28 | void update(); 29 | 30 | //Renders quad to the screen 31 | void render(); 32 | 33 | //Frees media and shuts down SDL 34 | void close(); 35 | 36 | //The window we'll be rendering to 37 | SDL_Window* gWindow = NULL; 38 | 39 | //OpenGL context 40 | SDL_GLContext gContext; 41 | 42 | //Render flag 43 | bool gRenderQuad = true; 44 | 45 | bool init() 46 | { 47 | //Initialization flag 48 | bool success = true; 49 | 50 | //Initialize SDL 51 | if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) 52 | { 53 | printf( "SDL could not initialize! SDL Error: %s\n", SDL_GetError() ); 54 | success = false; 55 | } 56 | else 57 | { 58 | //Use OpenGL 2.1 59 | SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 2 ); 60 | SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 1 ); 61 | 62 | //Create window 63 | gWindow = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN ); 64 | if( gWindow == NULL ) 65 | { 66 | printf( "Window could not be created! SDL Error: %s\n", SDL_GetError() ); 67 | success = false; 68 | } 69 | else 70 | { 71 | //Create context 72 | gContext = SDL_GL_CreateContext( gWindow ); 73 | if( gContext == NULL ) 74 | { 75 | printf( "OpenGL context could not be created! SDL Error: %s\n", SDL_GetError() ); 76 | success = false; 77 | } 78 | else 79 | { 80 | //Use Vsync 81 | if( SDL_GL_SetSwapInterval( 1 ) < 0 ) 82 | { 83 | printf( "Warning: Unable to set VSync! SDL Error: %s\n", SDL_GetError() ); 84 | } 85 | 86 | //Initialize OpenGL 87 | if( !initGL() ) 88 | { 89 | printf( "Unable to initialize OpenGL!\n" ); 90 | success = false; 91 | } 92 | } 93 | } 94 | } 95 | 96 | return success; 97 | } 98 | 99 | bool initGL() 100 | { 101 | bool success = true; 102 | GLenum error = GL_NO_ERROR; 103 | 104 | //Initialize Projection Matrix 105 | glMatrixMode( GL_PROJECTION ); 106 | glLoadIdentity(); 107 | 108 | //Check for error 109 | error = glGetError(); 110 | if( error != GL_NO_ERROR ) 111 | { 112 | printf( "Error initializing OpenGL! %s\n", gluErrorString( error ) ); 113 | success = false; 114 | } 115 | 116 | //Initialize Modelview Matrix 117 | glMatrixMode( GL_MODELVIEW ); 118 | glLoadIdentity(); 119 | 120 | //Check for error 121 | error = glGetError(); 122 | if( error != GL_NO_ERROR ) 123 | { 124 | printf( "Error initializing OpenGL! %s\n", gluErrorString( error ) ); 125 | success = false; 126 | } 127 | 128 | //Initialize clear color 129 | glClearColor( 0.f, 0.f, 0.f, 1.f ); 130 | 131 | //Check for error 132 | error = glGetError(); 133 | if( error != GL_NO_ERROR ) 134 | { 135 | printf( "Error initializing OpenGL! %s\n", gluErrorString( error ) ); 136 | success = false; 137 | } 138 | 139 | return success; 140 | } 141 | 142 | void handleKeys( unsigned char key, int x, int y ) 143 | { 144 | //Toggle quad 145 | if( key == 'q' ) 146 | { 147 | gRenderQuad = !gRenderQuad; 148 | } 149 | } 150 | 151 | void update() 152 | { 153 | //No per frame update needed 154 | } 155 | 156 | void render() 157 | { 158 | //Clear color buffer 159 | glClear( GL_COLOR_BUFFER_BIT ); 160 | 161 | //Render quad 162 | if( gRenderQuad ) 163 | { 164 | glBegin( GL_QUADS ); 165 | glVertex2f( -0.5f, -0.5f ); 166 | glVertex2f( 0.5f, -0.5f ); 167 | glVertex2f( 0.5f, 0.5f ); 168 | glVertex2f( -0.5f, 0.5f ); 169 | glEnd(); 170 | } 171 | } 172 | 173 | void close() 174 | { 175 | //Destroy window 176 | SDL_DestroyWindow( gWindow ); 177 | gWindow = NULL; 178 | 179 | //Quit SDL subsystems 180 | SDL_Quit(); 181 | } 182 | 183 | //Main loop flag 184 | bool quit = false; 185 | 186 | void loop_handler(void*) 187 | { 188 | //Event handler 189 | SDL_Event e; 190 | 191 | //Handle events on queue 192 | while( SDL_PollEvent( &e ) != 0 ) 193 | { 194 | //User requests quit 195 | if( e.type == SDL_QUIT ) 196 | { 197 | quit = true; 198 | } 199 | //Handle keypress with current mouse position 200 | else if( e.type == SDL_TEXTINPUT ) 201 | { 202 | int x = 0, y = 0; 203 | SDL_GetMouseState( &x, &y ); 204 | handleKeys( e.text.text[ 0 ], x, y ); 205 | } 206 | } 207 | 208 | //Render quad 209 | render(); 210 | 211 | //Update screen 212 | SDL_GL_SwapWindow( gWindow ); 213 | 214 | } 215 | 216 | int main( int argc, char* args[] ) 217 | { 218 | //Start up SDL and create window 219 | if( !init() ) 220 | { 221 | printf( "Failed to initialize!\n" ); 222 | } 223 | else 224 | { 225 | 226 | //Enable text input 227 | SDL_StartTextInput(); 228 | #ifdef _JS 229 | 230 | emscripten_set_main_loop_arg(loop_handler, NULL, -1, 1); 231 | #else 232 | //While application is running 233 | while( !quit ) 234 | { 235 | loop_handler(NULL); 236 | } 237 | #endif 238 | 239 | //Disable text input 240 | SDL_StopTextInput(); 241 | } 242 | 243 | //Free resources and close SDL 244 | close(); 245 | 246 | return 0; 247 | } 248 | -------------------------------------------------------------------------------- /50_SDL_and_opengl_2/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) -lGL -lGLU 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /50_SDL_and_opengl_2/assets/place_holder.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/50_SDL_and_opengl_2/assets/place_holder.txt -------------------------------------------------------------------------------- /50_SDL_and_opengl_2/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | SDL2_ttf 13 | 14 | *nix: 15 | SDL2 16 | SDL2_image 17 | SDL2_ttf 18 | -------------------------------------------------------------------------------- /51_SDL_and_modern_opengl/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) -lGL -lGLU -lGLEW 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /51_SDL_and_modern_opengl/assets/place_holder.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/51_SDL_and_modern_opengl/assets/place_holder.txt -------------------------------------------------------------------------------- /51_SDL_and_modern_opengl/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | SDL2_ttf 13 | 14 | *nix: 15 | SDL2 16 | SDL2_image 17 | SDL2_ttf 18 | -------------------------------------------------------------------------------- /52_hello_mobile/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /52_hello_mobile/assets/hello.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/52_hello_mobile/assets/hello.bmp -------------------------------------------------------------------------------- /52_hello_mobile/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | SDL2_ttf 13 | 14 | *nix: 15 | SDL2 16 | SDL2_image 17 | SDL2_ttf 18 | -------------------------------------------------------------------------------- /53_extensions_and_changing_orientation/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /53_extensions_and_changing_orientation/assets/landscape.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/53_extensions_and_changing_orientation/assets/landscape.png -------------------------------------------------------------------------------- /53_extensions_and_changing_orientation/assets/portrait.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/53_extensions_and_changing_orientation/assets/portrait.png -------------------------------------------------------------------------------- /53_extensions_and_changing_orientation/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2017) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | SDL2_ttf 13 | 14 | *nix: 15 | SDL2 16 | SDL2_image 17 | SDL2_ttf 18 | -------------------------------------------------------------------------------- /54_touches/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /54_touches/assets/touch_down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/54_touches/assets/touch_down.png -------------------------------------------------------------------------------- /54_touches/assets/touch_motion.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/54_touches/assets/touch_motion.png -------------------------------------------------------------------------------- /54_touches/assets/touch_up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/54_touches/assets/touch_up.png -------------------------------------------------------------------------------- /54_touches/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | SDL2_ttf 13 | 14 | *nix: 15 | SDL2 16 | SDL2_image 17 | SDL2_ttf 18 | -------------------------------------------------------------------------------- /55_multitouch/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.Conf 2 | 3 | FILE= $(wildcard *.cpp) 4 | TARGET= $(basename $(FILE)) 5 | 6 | all: $(TARGET) 7 | 8 | %:%.cpp 9 | $(CC) $(FLAGS) $(FILE) -o $(TARGET) $(LIBS) 10 | 11 | js: 12 | $(CCE) $(FILE) $(FLAGSE) -o $(TARGET).html 13 | 14 | clean: 15 | rm -rf $(TARGET) *.js *.data *.wasm *.html *.mem 16 | -------------------------------------------------------------------------------- /55_multitouch/assets/pinch_close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/55_multitouch/assets/pinch_close.png -------------------------------------------------------------------------------- /55_multitouch/assets/pinch_open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/55_multitouch/assets/pinch_open.png -------------------------------------------------------------------------------- /55_multitouch/assets/rotate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/55_multitouch/assets/rotate.png -------------------------------------------------------------------------------- /55_multitouch/readme.txt: -------------------------------------------------------------------------------- 1 | Copyright Notice: 2 | ----------------- 3 | The files within this zip file are copyrighted by Lazy Foo' Productions (2004-2015) 4 | and may not be redistributed without written permission. 5 | 6 | This project is linked against: 7 | ---------------------------------------- 8 | Windows: 9 | SDL2 10 | SDL2main 11 | SDL2_image 12 | SDL2_ttf 13 | 14 | *nix: 15 | SDL2 16 | SDL2_image 17 | SDL2_ttf 18 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | FILE=Makefile 3 | 4 | SUBDIRS = $(sort $(wildcard */)) 5 | 6 | .PHONY: $(SUBDIRS) 7 | 8 | all:$(SUBDIRS) 9 | 10 | js:$(SUBDIRS) 11 | 12 | clean:$(SUBDIRS) 13 | 14 | $(SUBDIRS): 15 | $(MAKE) -f $(FILE) -C $@ $(MAKECMDGOALS) 16 | 17 | test: 18 | ip addr show 19 | python -m SimpleHTTPServer 20 | -------------------------------------------------------------------------------- /Makefile.Conf: -------------------------------------------------------------------------------- 1 | CC= g++ 2 | FLAGS= -O2 -I/usr/include/SDL2/ -I/usr/include/ -D_Longlong="long long" -fpermissive 3 | LIBS= -lSDL2 -lSDL2_image -lSDL2_ttf -lSDL2_mixer 4 | 5 | CCE=em++ 6 | FLAGSE= -D_JS -s WASM=0 -O2 -D_Longlong="long long" -s TOTAL_MEMORY=32MB -s USE_SDL=2 -s USE_SDL_IMAGE=2 -s SDL2_IMAGE_FORMATS='["png","bmp"]' -s USE_SDL_TTF=2 --preload-file assets 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Lazy Foo' Productions - Beginning Game Programming v2.0 3 | 4 | 5 | All SDL2 code examples from http://lazyfoo.net/tutorials/SDL/ with Makefile and compatible with emscripten (http://kripken.github.io/emscripten-site/) 6 | 7 | 8 | ## Before run make: 9 | 10 | 11 | ``` 12 | sudo apt-get install libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev libsdl2-mixer-dev 13 | sudo apt-get install libglu1-mesa-dev libglew-dev 14 | ``` 15 | 16 | ## For build native executables 17 | Run: 18 | 19 | ``` 20 | make 21 | ``` 22 | 23 | ### For build javascript version 24 | 25 | Install and configure emscripten, and run: 26 | 27 | ``` 28 | make js 29 | ``` 30 | 31 | ## Docs and online examples 32 | 33 | https://lcgamboa.github.io/LazyFoo-SDL2/ 34 | -------------------------------------------------------------------------------- /docs/01_hello_SDL/01_hello_SDL.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/01_hello_SDL/01_hello_SDL.data -------------------------------------------------------------------------------- /docs/01_hello_SDL/01_hello_SDL.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/01_hello_SDL/01_hello_SDL.html.mem -------------------------------------------------------------------------------- /docs/02_getting_an_image_on_the_screen/02_getting_an_image_on_the_screen.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/02_getting_an_image_on_the_screen/02_getting_an_image_on_the_screen.data -------------------------------------------------------------------------------- /docs/02_getting_an_image_on_the_screen/02_getting_an_image_on_the_screen.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/02_getting_an_image_on_the_screen/02_getting_an_image_on_the_screen.html.mem -------------------------------------------------------------------------------- /docs/03_event_driven_programming/03_event_driven_programming.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/03_event_driven_programming/03_event_driven_programming.data -------------------------------------------------------------------------------- /docs/03_event_driven_programming/03_event_driven_programming.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/03_event_driven_programming/03_event_driven_programming.html.mem -------------------------------------------------------------------------------- /docs/04_key_presses/04_key_presses.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/04_key_presses/04_key_presses.data -------------------------------------------------------------------------------- /docs/04_key_presses/04_key_presses.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/04_key_presses/04_key_presses.html.mem -------------------------------------------------------------------------------- /docs/05_optimized_surface_loading_and_soft_stretching/05_optimized_surface_loading_and_soft_stretching.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/05_optimized_surface_loading_and_soft_stretching/05_optimized_surface_loading_and_soft_stretching.data -------------------------------------------------------------------------------- /docs/05_optimized_surface_loading_and_soft_stretching/05_optimized_surface_loading_and_soft_stretching.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/05_optimized_surface_loading_and_soft_stretching/05_optimized_surface_loading_and_soft_stretching.html.mem -------------------------------------------------------------------------------- /docs/06_extension_libraries_and_loading_other_image_formats/06_extension_libraries_and_loading_other_image_formats.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/06_extension_libraries_and_loading_other_image_formats/06_extension_libraries_and_loading_other_image_formats.data -------------------------------------------------------------------------------- /docs/06_extension_libraries_and_loading_other_image_formats/06_extension_libraries_and_loading_other_image_formats.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/06_extension_libraries_and_loading_other_image_formats/06_extension_libraries_and_loading_other_image_formats.html.mem -------------------------------------------------------------------------------- /docs/07_texture_loading_and_rendering/07_texture_loading_and_rendering.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/07_texture_loading_and_rendering/07_texture_loading_and_rendering.data -------------------------------------------------------------------------------- /docs/07_texture_loading_and_rendering/07_texture_loading_and_rendering.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/07_texture_loading_and_rendering/07_texture_loading_and_rendering.html.mem -------------------------------------------------------------------------------- /docs/08_geometry_rendering/08_geometry_rendering.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/08_geometry_rendering/08_geometry_rendering.data -------------------------------------------------------------------------------- /docs/08_geometry_rendering/08_geometry_rendering.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/08_geometry_rendering/08_geometry_rendering.html.mem -------------------------------------------------------------------------------- /docs/09_the_viewport/09_the_viewport.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/09_the_viewport/09_the_viewport.data -------------------------------------------------------------------------------- /docs/09_the_viewport/09_the_viewport.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/09_the_viewport/09_the_viewport.html.mem -------------------------------------------------------------------------------- /docs/10_color_keying/10_color_keying.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/10_color_keying/10_color_keying.data -------------------------------------------------------------------------------- /docs/10_color_keying/10_color_keying.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/10_color_keying/10_color_keying.html.mem -------------------------------------------------------------------------------- /docs/11_clip_rendering_and_sprite_sheets/11_clip_rendering_and_sprite_sheets.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/11_clip_rendering_and_sprite_sheets/11_clip_rendering_and_sprite_sheets.data -------------------------------------------------------------------------------- /docs/11_clip_rendering_and_sprite_sheets/11_clip_rendering_and_sprite_sheets.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/11_clip_rendering_and_sprite_sheets/11_clip_rendering_and_sprite_sheets.html.mem -------------------------------------------------------------------------------- /docs/12_color_modulation/12_color_modulation.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/12_color_modulation/12_color_modulation.data -------------------------------------------------------------------------------- /docs/12_color_modulation/12_color_modulation.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/12_color_modulation/12_color_modulation.html.mem -------------------------------------------------------------------------------- /docs/13_alpha_blending/13_alpha_blending.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/13_alpha_blending/13_alpha_blending.data -------------------------------------------------------------------------------- /docs/13_alpha_blending/13_alpha_blending.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/13_alpha_blending/13_alpha_blending.html.mem -------------------------------------------------------------------------------- /docs/14_animated_sprites_and_vsync/14_animated_sprites_and_vsync.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/14_animated_sprites_and_vsync/14_animated_sprites_and_vsync.data -------------------------------------------------------------------------------- /docs/14_animated_sprites_and_vsync/14_animated_sprites_and_vsync.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/14_animated_sprites_and_vsync/14_animated_sprites_and_vsync.html.mem -------------------------------------------------------------------------------- /docs/15_rotation_and_flipping/15_rotation_and_flipping.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/15_rotation_and_flipping/15_rotation_and_flipping.data -------------------------------------------------------------------------------- /docs/15_rotation_and_flipping/15_rotation_and_flipping.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/15_rotation_and_flipping/15_rotation_and_flipping.html.mem -------------------------------------------------------------------------------- /docs/16_true_type_fonts/16_true_type_fonts.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/16_true_type_fonts/16_true_type_fonts.data -------------------------------------------------------------------------------- /docs/16_true_type_fonts/16_true_type_fonts.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/16_true_type_fonts/16_true_type_fonts.html.mem -------------------------------------------------------------------------------- /docs/17_mouse_events/17_mouse_events.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/17_mouse_events/17_mouse_events.data -------------------------------------------------------------------------------- /docs/17_mouse_events/17_mouse_events.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/17_mouse_events/17_mouse_events.html.mem -------------------------------------------------------------------------------- /docs/18_key_states/18_key_states.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/18_key_states/18_key_states.data -------------------------------------------------------------------------------- /docs/18_key_states/18_key_states.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/18_key_states/18_key_states.html.mem -------------------------------------------------------------------------------- /docs/19_gamepads_and_joysticks/19_gamepads_and_joysticks.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/19_gamepads_and_joysticks/19_gamepads_and_joysticks.data -------------------------------------------------------------------------------- /docs/19_gamepads_and_joysticks/19_gamepads_and_joysticks.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/19_gamepads_and_joysticks/19_gamepads_and_joysticks.html.mem -------------------------------------------------------------------------------- /docs/20_force_feedback/20_force_feedback.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/20_force_feedback/20_force_feedback.data -------------------------------------------------------------------------------- /docs/20_force_feedback/20_force_feedback.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/20_force_feedback/20_force_feedback.html.mem -------------------------------------------------------------------------------- /docs/22_timing/22_timing.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/22_timing/22_timing.data -------------------------------------------------------------------------------- /docs/22_timing/22_timing.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/22_timing/22_timing.html.mem -------------------------------------------------------------------------------- /docs/23_advanced_timers/23_advanced_timers.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/23_advanced_timers/23_advanced_timers.data -------------------------------------------------------------------------------- /docs/23_advanced_timers/23_advanced_timers.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/23_advanced_timers/23_advanced_timers.html.mem -------------------------------------------------------------------------------- /docs/24_calculating_frame_rate/24_calculating_frame_rate.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/24_calculating_frame_rate/24_calculating_frame_rate.data -------------------------------------------------------------------------------- /docs/24_calculating_frame_rate/24_calculating_frame_rate.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/24_calculating_frame_rate/24_calculating_frame_rate.html.mem -------------------------------------------------------------------------------- /docs/25_capping_frame_rate/25_capping_frame_rate.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/25_capping_frame_rate/25_capping_frame_rate.data -------------------------------------------------------------------------------- /docs/25_capping_frame_rate/25_capping_frame_rate.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/25_capping_frame_rate/25_capping_frame_rate.html.mem -------------------------------------------------------------------------------- /docs/26_motion/26_motion.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/26_motion/26_motion.data -------------------------------------------------------------------------------- /docs/26_motion/26_motion.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/26_motion/26_motion.html.mem -------------------------------------------------------------------------------- /docs/27_collision_detection/27_collision_detection.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/27_collision_detection/27_collision_detection.data -------------------------------------------------------------------------------- /docs/27_collision_detection/27_collision_detection.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/27_collision_detection/27_collision_detection.html.mem -------------------------------------------------------------------------------- /docs/28_per-pixel_collision_detection/28_per-pixel_collision_detection.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/28_per-pixel_collision_detection/28_per-pixel_collision_detection.data -------------------------------------------------------------------------------- /docs/28_per-pixel_collision_detection/28_per-pixel_collision_detection.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/28_per-pixel_collision_detection/28_per-pixel_collision_detection.html.mem -------------------------------------------------------------------------------- /docs/29_circular_collision_detection/29_circular_collision_detection.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/29_circular_collision_detection/29_circular_collision_detection.data -------------------------------------------------------------------------------- /docs/29_circular_collision_detection/29_circular_collision_detection.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/29_circular_collision_detection/29_circular_collision_detection.html.mem -------------------------------------------------------------------------------- /docs/30_scrolling/30_scrolling.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/30_scrolling/30_scrolling.data -------------------------------------------------------------------------------- /docs/30_scrolling/30_scrolling.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/30_scrolling/30_scrolling.html.mem -------------------------------------------------------------------------------- /docs/31_scrolling_backgrounds/31_scrolling_backgrounds.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/31_scrolling_backgrounds/31_scrolling_backgrounds.data -------------------------------------------------------------------------------- /docs/31_scrolling_backgrounds/31_scrolling_backgrounds.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/31_scrolling_backgrounds/31_scrolling_backgrounds.html.mem -------------------------------------------------------------------------------- /docs/32_text_input_and_clipboard_handling/32_text_input_and_clipboard_handling.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/32_text_input_and_clipboard_handling/32_text_input_and_clipboard_handling.data -------------------------------------------------------------------------------- /docs/32_text_input_and_clipboard_handling/32_text_input_and_clipboard_handling.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/32_text_input_and_clipboard_handling/32_text_input_and_clipboard_handling.html.mem -------------------------------------------------------------------------------- /docs/33_file_reading_and_writing/33_file_reading_and_writing.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/33_file_reading_and_writing/33_file_reading_and_writing.data -------------------------------------------------------------------------------- /docs/33_file_reading_and_writing/33_file_reading_and_writing.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/33_file_reading_and_writing/33_file_reading_and_writing.html.mem -------------------------------------------------------------------------------- /docs/35_window_events/35_window_events.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/35_window_events/35_window_events.data -------------------------------------------------------------------------------- /docs/35_window_events/35_window_events.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/35_window_events/35_window_events.html.mem -------------------------------------------------------------------------------- /docs/36_multiple_windows/36_multiple_windows.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/36_multiple_windows/36_multiple_windows.data -------------------------------------------------------------------------------- /docs/36_multiple_windows/36_multiple_windows.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/36_multiple_windows/36_multiple_windows.html.mem -------------------------------------------------------------------------------- /docs/37_multiple_displays/37_multiple_displays.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/37_multiple_displays/37_multiple_displays.data -------------------------------------------------------------------------------- /docs/37_multiple_displays/37_multiple_displays.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/37_multiple_displays/37_multiple_displays.html.mem -------------------------------------------------------------------------------- /docs/38_particle_engines/38_particle_engines.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/38_particle_engines/38_particle_engines.data -------------------------------------------------------------------------------- /docs/38_particle_engines/38_particle_engines.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/38_particle_engines/38_particle_engines.html.mem -------------------------------------------------------------------------------- /docs/39_tiling/39_tiling.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/39_tiling/39_tiling.data -------------------------------------------------------------------------------- /docs/39_tiling/39_tiling.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/39_tiling/39_tiling.html.mem -------------------------------------------------------------------------------- /docs/40_texture_manipulation/40_texture_manipulation.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/40_texture_manipulation/40_texture_manipulation.data -------------------------------------------------------------------------------- /docs/40_texture_manipulation/40_texture_manipulation.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/40_texture_manipulation/40_texture_manipulation.html.mem -------------------------------------------------------------------------------- /docs/41_bitmap_fonts/41_bitmap_fonts.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/41_bitmap_fonts/41_bitmap_fonts.data -------------------------------------------------------------------------------- /docs/41_bitmap_fonts/41_bitmap_fonts.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/41_bitmap_fonts/41_bitmap_fonts.html.mem -------------------------------------------------------------------------------- /docs/42_texture_streaming/42_texture_streaming.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/42_texture_streaming/42_texture_streaming.data -------------------------------------------------------------------------------- /docs/42_texture_streaming/42_texture_streaming.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/42_texture_streaming/42_texture_streaming.html.mem -------------------------------------------------------------------------------- /docs/43_render_to_texture/43_render_to_texture.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/43_render_to_texture/43_render_to_texture.data -------------------------------------------------------------------------------- /docs/43_render_to_texture/43_render_to_texture.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/43_render_to_texture/43_render_to_texture.html.mem -------------------------------------------------------------------------------- /docs/44_frame_independent_movement/44_frame_independent_movement.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/44_frame_independent_movement/44_frame_independent_movement.data -------------------------------------------------------------------------------- /docs/44_frame_independent_movement/44_frame_independent_movement.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/44_frame_independent_movement/44_frame_independent_movement.html.mem -------------------------------------------------------------------------------- /docs/45_timer_callbacks/45_timer_callbacks.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/45_timer_callbacks/45_timer_callbacks.data -------------------------------------------------------------------------------- /docs/45_timer_callbacks/45_timer_callbacks.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/45_timer_callbacks/45_timer_callbacks.html.mem -------------------------------------------------------------------------------- /docs/46_multithreading/46_multithreading.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/46_multithreading/46_multithreading.data -------------------------------------------------------------------------------- /docs/46_multithreading/46_multithreading.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/46_multithreading/46_multithreading.html.mem -------------------------------------------------------------------------------- /docs/47_semaphores/47_semaphores.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/47_semaphores/47_semaphores.data -------------------------------------------------------------------------------- /docs/47_semaphores/47_semaphores.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/47_semaphores/47_semaphores.html.mem -------------------------------------------------------------------------------- /docs/48_atomic_operations/48_atomic_operations.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/48_atomic_operations/48_atomic_operations.data -------------------------------------------------------------------------------- /docs/48_atomic_operations/48_atomic_operations.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/48_atomic_operations/48_atomic_operations.html.mem -------------------------------------------------------------------------------- /docs/49_mutexes_and_conditions/49_mutexes_and_conditions.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/49_mutexes_and_conditions/49_mutexes_and_conditions.data -------------------------------------------------------------------------------- /docs/49_mutexes_and_conditions/49_mutexes_and_conditions.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/49_mutexes_and_conditions/49_mutexes_and_conditions.html.mem -------------------------------------------------------------------------------- /docs/50_SDL_and_opengl_2/50_SDL_and_opengl_2.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/50_SDL_and_opengl_2/50_SDL_and_opengl_2.data -------------------------------------------------------------------------------- /docs/50_SDL_and_opengl_2/50_SDL_and_opengl_2.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/50_SDL_and_opengl_2/50_SDL_and_opengl_2.html.mem -------------------------------------------------------------------------------- /docs/51_SDL_and_modern_opengl/51_SDL_and_modern_opengl.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/51_SDL_and_modern_opengl/51_SDL_and_modern_opengl.data -------------------------------------------------------------------------------- /docs/51_SDL_and_modern_opengl/51_SDL_and_modern_opengl.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/51_SDL_and_modern_opengl/51_SDL_and_modern_opengl.html.mem -------------------------------------------------------------------------------- /docs/52_hello_mobile/52_hello_mobile.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/52_hello_mobile/52_hello_mobile.data -------------------------------------------------------------------------------- /docs/52_hello_mobile/52_hello_mobile.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/52_hello_mobile/52_hello_mobile.html.mem -------------------------------------------------------------------------------- /docs/53_extensions_and_changing_orientation/53_extensions_and_changing_orientation.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/53_extensions_and_changing_orientation/53_extensions_and_changing_orientation.data -------------------------------------------------------------------------------- /docs/53_extensions_and_changing_orientation/53_extensions_and_changing_orientation.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/53_extensions_and_changing_orientation/53_extensions_and_changing_orientation.html.mem -------------------------------------------------------------------------------- /docs/54_touches/54_touches.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/54_touches/54_touches.data -------------------------------------------------------------------------------- /docs/54_touches/54_touches.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/54_touches/54_touches.html.mem -------------------------------------------------------------------------------- /docs/55_multitouch/55_multitouch.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/55_multitouch/55_multitouch.data -------------------------------------------------------------------------------- /docs/55_multitouch/55_multitouch.html.mem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcgamboa/LazyFoo-SDL2/64fe0f6681425adf73dc94e30780c54f414ac58f/docs/55_multitouch/55_multitouch.html.mem -------------------------------------------------------------------------------- /make_help.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | rm -Rf docs 4 | dirs=`find * -maxdepth 0 -type d 2> /dev/null` 5 | mkdir -p "docs" 6 | echo "" >> docs/index.html 7 | echo "
" >> docs/index.html 8 | echo "

Emscripten Lazy Foo' Examples


" >> docs/index.html 9 | echo "" >> docs/index.html 10 | for example in $dirs 11 | do 12 | echo "examples: $example" 13 | mkdir -p "docs/$example/" 14 | echo "" >> docs/index.html 15 | echo "" >> docs/index.html 16 | cd $example 17 | cp *.js *.data *.wasm *.html *.mem ../docs/$example/ 18 | cd .. 19 | done 20 | echo "
Lazy Foo' tutorialEmscripten online version

$example
$example
" >> docs/index.html 21 | echo "
" >> docs/index.html 22 | rm -Rf docs/docs/ 23 | --------------------------------------------------------------------------------