Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ol> <li>download SDL2-devel-2.0.1-mingw.tar.gz</li> <li>unpack from SDL2-2.0.1\i686-w64-mingw32 these dirs: \bin, \include, \lib and \share to e.g. X:\CodeBlocks\MinGW\</li> <li>Create directory %APPDATA%\CodeBlocks\UserTemplates\SDL2 and paste files SDL2.cbp, main.cpp, and cb.bmp </li> </ol> <p>SDL2.cbp:</p> <p>Note: Edit the letter of your drive and path X:\CodeBlocks as you need</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes" ?&gt; &lt;CodeBlocks_project_file&gt; &lt;FileVersion major="1" minor="6" /&gt; &lt;Project&gt; &lt;Option title="SDL2" /&gt; &lt;Option pch_mode="2" /&gt; &lt;Option compiler="gcc" /&gt; &lt;Build&gt; &lt;Target title="Debug"&gt; &lt;Option output="bin/Debug/SDL2" prefix_auto="1" extension_auto="1" /&gt; &lt;Option object_output="obj/Debug/" /&gt; &lt;Option type="1" /&gt; &lt;Option compiler="gcc" /&gt; &lt;Compiler&gt; &lt;Add option="-g" /&gt; &lt;/Compiler&gt; &lt;/Target&gt; &lt;Target title="Release"&gt; &lt;Option output="bin/Release/SDL2" prefix_auto="1" extension_auto="1" /&gt; &lt;Option object_output="obj/Release/" /&gt; &lt;Option type="0" /&gt; &lt;Option compiler="gcc" /&gt; &lt;Compiler&gt; &lt;Add option="-O2" /&gt; &lt;/Compiler&gt; &lt;Linker&gt; &lt;Add option="-s" /&gt; &lt;/Linker&gt; &lt;/Target&gt; &lt;/Build&gt; &lt;Compiler&gt; &lt;Add option="-Wall" /&gt; &lt;Add directory="X:/CodeBlocks/MinGW/include" /&gt; &lt;/Compiler&gt; &lt;Linker&gt; &lt;Add library="mingw32" /&gt; &lt;Add library="SDL2main" /&gt; &lt;Add library="SDL2.dll" /&gt; &lt;Add library="user32" /&gt; &lt;Add library="gdi32" /&gt; &lt;Add library="winmm" /&gt; &lt;Add library="dxguid" /&gt; &lt;Add directory="X:/CodeBlocks/MinGW/lib" /&gt; &lt;/Linker&gt; &lt;Unit filename="cb.bmp" /&gt; &lt;Unit filename="main.cpp" /&gt; &lt;Extensions&gt; &lt;code_completion /&gt; &lt;envvars /&gt; &lt;debugger /&gt; &lt;lib_finder disable_auto="1" /&gt; &lt;/Extensions&gt; &lt;/Project&gt; &lt;/CodeBlocks_project_file&gt; </code></pre> <p>main.cpp</p> <pre><code>#include &lt;iostream&gt; #include &lt;SDL2/SDL.h&gt; int main ( int argc, char** argv ) { // initialize SDL video if (SDL_Init(SDL_INIT_VIDEO) == -1) { std::cout &lt;&lt; "Unable to init SDL video: "&lt;&lt; SDL_GetError() &lt;&lt; std::endl; return 1; } // make sure SDL cleans up before exit atexit(SDL_Quit); // create a new window SDL_Window* screen = NULL; screen = SDL_CreateWindow("CodeBlocs Logo Window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 150,120, /* SDL_WINDOW_FULLSCREEN | */ SDL_WINDOW_OPENGL); if ( NULL == screen ) { std::cout &lt;&lt; "Unable to create window: "&lt;&lt; SDL_GetError() &lt;&lt; std::endl; return 1; } // Create a new renderer SDL_Renderer* renderer = NULL; renderer = SDL_CreateRenderer(screen, -1, 0); if ( NULL == renderer ) { std::cout &lt;&lt; "Unable to create renderer: "&lt;&lt; SDL_GetError() &lt;&lt; std::endl; return 1; } // load an image SDL_Surface* bitmap = NULL; bitmap = SDL_LoadBMP("cb.bmp"); if ( NULL == bitmap ) { std::cout &lt;&lt; "Unable to load bitmap: "&lt;&lt; SDL_GetError() &lt;&lt; std::endl; return 1; } SDL_Texture* texture = NULL; texture = SDL_CreateTextureFromSurface(renderer, bitmap); SDL_FreeSurface(bitmap); // program main loop bool done = false; while (!done) { // drawing SDL_RenderClear(renderer); SDL_RenderCopy(renderer, texture, NULL, NULL); SDL_RenderPresent(renderer); // message processing loop SDL_Event event; while (SDL_PollEvent(&amp;event)) { // check for messages switch (event.type) { // exit if the window is closed case SDL_QUIT: done = true; break; // check for keypresses case SDL_KEYDOWN: { // exit if ESCAPE is pressed if (event.key.keysym.sym == SDLK_ESCAPE) done = true; break; } } // end switch } // end of message processing } // end main loop SDL_DestroyTexture(texture); SDL_DestroyRenderer(renderer); SDL_DestroyWindow(screen); SDL_Quit(); return 0; } </code></pre> <p>cb.bmp any bitmap file 150x120</p> <p>Run CodeBlocks and File->New->From templates...->User Templates->SDL2</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload