Skip to content
Snippets Groups Projects
Commit f6afe51f authored by Tamási Benjamin's avatar Tamási Benjamin
Browse files

Working on Game Class

parent b6b6e8d8
No related branches found
No related tags found
No related merge requests found
Game.cpp 0 → 100644
#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
}
Game.h 0 → 100644
#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__) */
......@@ -7,7 +7,7 @@
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/SDLGFW" prefix_auto="1" extension_auto="1" />
<Option output="bin/Debug/SDL2" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
......@@ -16,9 +16,9 @@
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/SDLGFW" prefix_auto="1" extension_auto="1" />
<Option output="bin/Release/SDL2" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option type="0" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
......@@ -30,7 +30,20 @@
</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 />
......
# 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"
File added
main.cpp 0 → 100644
#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;
}
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment