diff --git a/Game.cpp b/Game.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0822ff2e51131d77cf4afbd05f24d0047a2fd7bc --- /dev/null +++ b/Game.cpp @@ -0,0 +1,46 @@ +#include "Game.h" + +bool Game::init(const char* title, int xpos, int ypos, int width, int height, int flags) +{ + // attempt to initialize SDL + if(SDL_Init(SDL_INIT_EVERYTHING) == 0) + { + std::cout << "SDL init success\n"; + // init the window + m_pWindow = SDL_CreateWindow(title, xpos, ypos, width, height, flags); + if(m_pWindow != 0) // window init success + { + std::cout << "window creation success\n"; + m_pRenderer = SDL_CreateRenderer(m_pWindow, -1, 0); + if(m_pRenderer != 0) // renderer init success + { + std::cout << "renderer creation success\n"; + SDL_SetRenderDrawColor(m_pRenderer,255,255,255,255); + } + else + { + std::cout << "renderer init fail\n"; + return false; // renderer init fail + } + } + else + { + std::cout << "window init fail\n"; + return false; // window init fail + } + } + else + { + std::cout << "SDL init fail\n"; + return false; // SDL init fail + } + std::cout << "init success\n"; + m_bRunning = true; // everything inited successfully, start the main loop + return true; +} + +void Game::render() +{ + SDL_RenderClear(m_pRenderer); // clear the renderer to the draw color + SDL_RenderPresent(m_pRenderer); // draw to the screen +} diff --git a/Game.h b/Game.h new file mode 100644 index 0000000000000000000000000000000000000000..68666f133d63967eaa51ec791c520be8d982d757 --- /dev/null +++ b/Game.h @@ -0,0 +1,22 @@ +#ifndef __Game__ +#define __Game__ +#include "SDL.h" + +class Game +{ +public: + Game(); + ~Game(); + bool init(const char* title, int xpos, int ypos, int width, int height, int flags); + void render(); + void update(); + void handleEvents(); + void clean(); + bool running() { return m_bRunning; } +private: + SDL_Window* m_pWindow; + SDL_Renderer* m_pRenderer; + + bool m_bRunning; +}; +#endif /* defined(__Game__) */ diff --git a/SDLGFW.cbp b/SDLGFW.cbp index 3d00712768aab7f396da00bcfc7f544f5fec7965..2e9f6a383c80ff188d9a007e5f663dd2d4a54f44 100644 --- a/SDLGFW.cbp +++ b/SDLGFW.cbp @@ -1,41 +1,54 @@ <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <CodeBlocks_project_file> - <FileVersion major="1" minor="6" /> - <Project> - <Option title="SDLGFW" /> - <Option pch_mode="2" /> - <Option compiler="gcc" /> - <Build> - <Target title="Debug"> - <Option output="bin/Debug/SDLGFW" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj/Debug/" /> - <Option type="1" /> - <Option compiler="gcc" /> - <Compiler> - <Add option="-g" /> - </Compiler> - </Target> - <Target title="Release"> - <Option output="bin/Release/SDLGFW" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj/Release/" /> - <Option type="1" /> - <Option compiler="gcc" /> - <Compiler> - <Add option="-O2" /> - </Compiler> - <Linker> - <Add option="-s" /> - </Linker> - </Target> - </Build> - <Compiler> - <Add option="-Wall" /> - </Compiler> - <Extensions> - <code_completion /> - <envvars /> - <debugger /> - <lib_finder disable_auto="1" /> - </Extensions> - </Project> -</CodeBlocks_project_file> + <FileVersion major="1" minor="6" /> + <Project> + <Option title="SDLGFW" /> + <Option pch_mode="2" /> + <Option compiler="gcc" /> + <Build> + <Target title="Debug"> + <Option output="bin/Debug/SDL2" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Debug/" /> + <Option type="1" /> + <Option compiler="gcc" /> + <Compiler> + <Add option="-g" /> + </Compiler> + </Target> + <Target title="Release"> + <Option output="bin/Release/SDL2" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Release/" /> + <Option type="0" /> + <Option compiler="gcc" /> + <Compiler> + <Add option="-O2" /> + </Compiler> + <Linker> + <Add option="-s" /> + </Linker> + </Target> + </Build> + <Compiler> + <Add option="-Wall" /> + <Add directory="C:/Program Files (x86)/CodeBlocks/MinGW/include" /> + </Compiler> + <Linker> + <Add library="mingw32" /> + <Add library="SDL2main" /> + <Add library="SDL2.dll" /> + <Add library="user32" /> + <Add library="gdi32" /> + <Add library="winmm" /> + <Add library="dxguid" /> + <Add directory="C:/Program Files (x86)/CodeBlocks/MinGW/lib" /> + </Linker> + <Unit filename="cb.bmp" /> + <Unit filename="main.cpp" /> + <Extensions> + <code_completion /> + <envvars /> + <debugger /> + <lib_finder disable_auto="1" /> + </Extensions> + </Project> +</CodeBlocks_project_file> \ No newline at end of file diff --git a/SDLGFW.depend b/SDLGFW.depend new file mode 100644 index 0000000000000000000000000000000000000000..a21c8f8e7571a51decad3ddc547309d93eab9482 --- /dev/null +++ b/SDLGFW.depend @@ -0,0 +1,377 @@ +# depslib dependency file v1.0 +1397854663 source:c:\users\benjamin\documents\dev\c++\sdlgfw\main.cpp + <SDL.h> + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl.h + "SDL_main.h" + "SDL_stdinc.h" + "SDL_assert.h" + "SDL_atomic.h" + "SDL_audio.h" + "SDL_clipboard.h" + "SDL_cpuinfo.h" + "SDL_endian.h" + "SDL_error.h" + "SDL_events.h" + "SDL_filesystem.h" + "SDL_joystick.h" + "SDL_gamecontroller.h" + "SDL_haptic.h" + "SDL_hints.h" + "SDL_loadso.h" + "SDL_log.h" + "SDL_messagebox.h" + "SDL_mutex.h" + "SDL_power.h" + "SDL_render.h" + "SDL_rwops.h" + "SDL_system.h" + "SDL_thread.h" + "SDL_timer.h" + "SDL_version.h" + "SDL_video.h" + "begin_code.h" + "close_code.h" + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl_main.h + "SDL_stdinc.h" + "begin_code.h" + "close_code.h" + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl_stdinc.h + "SDL_config.h" + <sys/types.h> + <stdio.h> + <stdlib.h> + <stddef.h> + <stdarg.h> + <stdlib.h> + <malloc.h> + <stddef.h> + <stdarg.h> + <memory.h> + <string.h> + <strings.h> + <inttypes.h> + <stdint.h> + <ctype.h> + <math.h> + <float.h> + <iconv.h> + "begin_code.h" + <alloca.h> + <malloc.h> + <malloc.h> + <malloc.h> + <stdlib.h> + "close_code.h" + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl_config.h + "SDL_platform.h" + +1397854737 c:\program files (x86)\codeblocks\mingw\include\sdl_platform.h + "AvailabilityMacros.h" + "TargetConditionals.h" + <winapifamily.h> + "begin_code.h" + "close_code.h" + +1394940881 c:\program files (x86)\codeblocks\mingw\include\begin_code.h + +1394940881 c:\program files (x86)\codeblocks\mingw\include\close_code.h + +1341010380 c:\program files (x86)\codeblocks\mingw\include\sys\types.h + <_mingw.h> + <stddef.h> + +1341010370 c:\program files (x86)\codeblocks\mingw\include\_mingw.h + +1341010376 c:\program files (x86)\codeblocks\mingw\include\stdio.h + <_mingw.h> + <stddef.h> + <stdarg.h> + <sys/types.h> + +1341010376 c:\program files (x86)\codeblocks\mingw\include\stdlib.h + <_mingw.h> + <stddef.h> + +1341010374 c:\program files (x86)\codeblocks\mingw\include\malloc.h + <_mingw.h> + <stdlib.h> + +1341010374 c:\program files (x86)\codeblocks\mingw\include\memory.h + <string.h> + +1341010376 c:\program files (x86)\codeblocks\mingw\include\string.h + <_mingw.h> + <stddef.h> + +1341010376 c:\program files (x86)\codeblocks\mingw\include\strings.h + <string.h> + +1341010372 c:\program files (x86)\codeblocks\mingw\include\inttypes.h + <_mingw.h> + <stdint.h> + <stddef.h> + +1341010376 c:\program files (x86)\codeblocks\mingw\include\stdint.h + <stddef.h> + +1341010370 c:\program files (x86)\codeblocks\mingw\include\ctype.h + <_mingw.h> + <stddef.h> + +1341010374 c:\program files (x86)\codeblocks\mingw\include\math.h + <_mingw.h> + +1341010372 c:\program files (x86)\codeblocks\mingw\include\float.h + <_mingw.h> + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl_assert.h + "SDL_config.h" + "begin_code.h" + <signal.h> + "close_code.h" + +1341010376 c:\program files (x86)\codeblocks\mingw\include\signal.h + <_mingw.h> + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl_atomic.h + "SDL_stdinc.h" + "SDL_platform.h" + "begin_code.h" + "close_code.h" + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl_audio.h + "SDL_stdinc.h" + "SDL_error.h" + "SDL_endian.h" + "SDL_mutex.h" + "SDL_thread.h" + "SDL_rwops.h" + "begin_code.h" + "close_code.h" + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl_error.h + "SDL_stdinc.h" + "begin_code.h" + "close_code.h" + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl_endian.h + "SDL_stdinc.h" + <endian.h> + "begin_code.h" + "close_code.h" + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl_mutex.h + "SDL_stdinc.h" + "SDL_error.h" + "begin_code.h" + "close_code.h" + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl_thread.h + "SDL_stdinc.h" + "SDL_error.h" + "SDL_atomic.h" + "SDL_mutex.h" + "begin_code.h" + <process.h> + "close_code.h" + +1341010374 c:\program files (x86)\codeblocks\mingw\include\process.h + <_mingw.h> + <sys/types.h> + <stdint.h> + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl_rwops.h + "SDL_stdinc.h" + "SDL_error.h" + "begin_code.h" + "close_code.h" + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl_clipboard.h + "SDL_stdinc.h" + "begin_code.h" + "close_code.h" + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl_cpuinfo.h + "SDL_stdinc.h" + <intrin.h> + <intrin.h> + <altivec.h> + <mmintrin.h> + <mm3dnow.h> + <xmmintrin.h> + <emmintrin.h> + "begin_code.h" + "close_code.h" + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl_events.h + "SDL_stdinc.h" + "SDL_error.h" + "SDL_video.h" + "SDL_keyboard.h" + "SDL_mouse.h" + "SDL_joystick.h" + "SDL_gamecontroller.h" + "SDL_quit.h" + "SDL_gesture.h" + "SDL_touch.h" + "begin_code.h" + "close_code.h" + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl_video.h + "SDL_stdinc.h" + "SDL_pixels.h" + "SDL_rect.h" + "SDL_surface.h" + "begin_code.h" + "close_code.h" + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl_pixels.h + "SDL_stdinc.h" + "begin_code.h" + "close_code.h" + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl_rect.h + "SDL_stdinc.h" + "SDL_error.h" + "SDL_pixels.h" + "SDL_rwops.h" + "begin_code.h" + "close_code.h" + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl_surface.h + "SDL_stdinc.h" + "SDL_pixels.h" + "SDL_rect.h" + "SDL_blendmode.h" + "SDL_rwops.h" + "begin_code.h" + "close_code.h" + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl_blendmode.h + "begin_code.h" + "close_code.h" + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl_keyboard.h + "SDL_stdinc.h" + "SDL_error.h" + "SDL_keycode.h" + "SDL_video.h" + "begin_code.h" + "close_code.h" + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl_keycode.h + "SDL_stdinc.h" + "SDL_scancode.h" + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl_scancode.h + "SDL_stdinc.h" + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl_mouse.h + "SDL_stdinc.h" + "SDL_error.h" + "SDL_video.h" + "begin_code.h" + "close_code.h" + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl_joystick.h + "SDL_stdinc.h" + "SDL_error.h" + "begin_code.h" + "close_code.h" + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl_gamecontroller.h + "SDL_stdinc.h" + "SDL_error.h" + "SDL_rwops.h" + "SDL_joystick.h" + "begin_code.h" + "close_code.h" + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl_quit.h + "SDL_stdinc.h" + "SDL_error.h" + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl_gesture.h + "SDL_stdinc.h" + "SDL_error.h" + "SDL_video.h" + "SDL_touch.h" + "begin_code.h" + "close_code.h" + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl_touch.h + "SDL_stdinc.h" + "SDL_error.h" + "SDL_video.h" + "begin_code.h" + "close_code.h" + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl_filesystem.h + "SDL_stdinc.h" + "begin_code.h" + "close_code.h" + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl_haptic.h + "SDL_stdinc.h" + "SDL_error.h" + "SDL_joystick.h" + "begin_code.h" + "close_code.h" + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl_hints.h + "SDL_stdinc.h" + "begin_code.h" + "close_code.h" + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl_loadso.h + "SDL_stdinc.h" + "SDL_error.h" + "begin_code.h" + "close_code.h" + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl_log.h + "SDL_stdinc.h" + "begin_code.h" + "close_code.h" + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl_messagebox.h + "SDL_stdinc.h" + "SDL_video.h" + "begin_code.h" + "close_code.h" + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl_power.h + "SDL_stdinc.h" + "begin_code.h" + "close_code.h" + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl_render.h + "SDL_stdinc.h" + "SDL_rect.h" + "SDL_video.h" + "begin_code.h" + "close_code.h" + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl_system.h + "SDL_stdinc.h" + "SDL_keyboard.h" + "SDL_render.h" + "SDL_video.h" + "begin_code.h" + "close_code.h" + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl_timer.h + "SDL_stdinc.h" + "SDL_error.h" + "begin_code.h" + "close_code.h" + +1394940881 c:\program files (x86)\codeblocks\mingw\include\sdl_version.h + "SDL_stdinc.h" + "begin_code.h" + "close_code.h" + diff --git a/bin/Debug/SDL2.exe b/bin/Debug/SDL2.exe new file mode 100644 index 0000000000000000000000000000000000000000..61f8eccf33366f0b62ec2b3dffdb1550b9b54c72 Binary files /dev/null and b/bin/Debug/SDL2.exe differ diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c644e15f9009340672b8d96c20696b9bd6a9bf35 --- /dev/null +++ b/main.cpp @@ -0,0 +1,37 @@ +#include<SDL.h> +SDL_Window* g_pWindow = 0; +SDL_Renderer* g_pRenderer = 0; +int main(int argc, char* args[]) +{ + // initialize SDL + if(SDL_Init(SDL_INIT_EVERYTHING) >= 0) + { + // if succeeded create our window + g_pWindow = SDL_CreateWindow("Chapter 1: Setting up SDL", + SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, + 640, 480, + SDL_WINDOW_SHOWN); + // if the window creation succeeded create our renderer + if(g_pWindow != 0) + { + g_pRenderer = SDL_CreateRenderer(g_pWindow, -1, 0); + } + } + else + { + return 1; // sdl could not initialize + } + // everything succeeded lets draw the window + // set to black // This function expects Red, Green, Blue and + // Alpha as color values + SDL_SetRenderDrawColor(g_pRenderer, 0, 0, 0, 255); + // clear the window to black + SDL_RenderClear(g_pRenderer); + // show the window + SDL_RenderPresent(g_pRenderer); + // set a delay before quitting + SDL_Delay(5000); + // clean up SDL + SDL_Quit(); + return 0; +} diff --git a/obj/Debug/main.o b/obj/Debug/main.o new file mode 100644 index 0000000000000000000000000000000000000000..aa8c506d53a74d6838ba2dccfe39dc8c2bd74b82 Binary files /dev/null and b/obj/Debug/main.o differ