Search
 
SCRIPT & CODE EXAMPLE
 

CPP

c++ SDL2 window

// g++ main.cpp `pkg-config --cflags --libs sdl2`
#include <SDL.h>
#include <iostream>

int main( int argc, char** argv )
{
    SDL_Init(SDL_INIT_EVERYTHING);
    SDL_Window* win = SDL_CreateWindow("my window", 100, 100, 640, 480, SDL_WINDOW_SHOWN);

    if (!win)
    {
        std :: cout << "Failed to create a window! Error: " << SDL_GetError() << "
";
    }

    SDL_Surface* winSurface = SDL_GetWindowSurface(win);

    bool running = true;
    while( running )
    {
        SDL_Event ev;
        while( SDL_PollEvent( &ev ) )
        {
            if( ( SDL_QUIT == ev.type ) ||
                ( SDL_KEYDOWN == ev.type && SDL_SCANCODE_ESCAPE == ev.key.keysym.scancode ) )
            {
                running = false;
                break;
            }
        }

        SDL_FillRect(winSurface, NULL, SDL_MapRGB(winSurface->format, 255, 90, 120));
        SDL_UpdateWindowSurface(win);
    }

    SDL_DestroyWindow(win);
    SDL_Quit();
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ get length of array 
Cpp :: check if intent has extras 
Cpp :: string to size_t cpp 
Cpp :: how to find index of a vector in c++ 
Cpp :: how to ensure the user inouts a int and not anything else c++ 
Cpp :: cpp read csv 
Cpp :: eosio check account exist 
Cpp :: how to make string get spaces c++ 
Cpp :: c++ set console title 
Cpp :: ue4 ftext c++ 
Cpp :: c++ pass argument to singleton 
Cpp :: C++ Area of Scalene Triangle 
Cpp :: insert at position in vector c++ 
Cpp :: c++ make constructor fails if bad argument 
Cpp :: non stoichiometric nacl is yellow 
Cpp :: google test assert eq float 
Cpp :: class Solution { public: vector<vector<int threeSum(vector<int& nums) meaning 
Cpp :: c++ rand() 
Cpp :: c++ std::find with lambda 
Cpp :: number to binary string c++ 
Cpp :: convert a int to string c++ 
Cpp :: macro c++ 
Cpp :: separating class into header and cpp file 
Cpp :: C++ mutex lock/unlock 
Cpp :: dynamically generating 2d array in cpp 
Cpp :: Unsorted Linked list in c++ 
Cpp :: counting sort c++ 
Cpp :: adding elements to a vector c++ 
Cpp :: how to use decrement operator in c++ 
Cpp :: string reverse stl 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =