Saturday, June 10, 2017

VCPKG

Vcpkg helps you get C and C++ libraries on Windows.
https://github.com/Microsoft/vcpkg

SDL and SFML need manual links
from C:\vcpkg\installed\x86-windows\lib\manual-link
to avoid error
(ERROR: MSVCRT.lib(exe_main.obj) : error LNK2001: unresolved external symbol _main)

Tuesday, May 30, 2017

CLion SDL2 Linux(Manjaro)

cmake_minimum_required(VERSION 3.7)
project(untitled)

set(CMAKE_CXX_STANDARD 11)

set(SOURCE_FILES main.cpp)
add_executable(untitled ${SOURCE_FILES})

INCLUDE(FindPkgConfig)

PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2)
PKG_SEARCH_MODULE(SDL2IMAGE REQUIRED SDL2_image>=2.0.0)

INCLUDE_DIRECTORIES(${SDL2_INCLUDE_DIRS} ${SDL2IMAGE_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${SDL2_LIBRARIES} ${SDL2IMAGE_LIBRARIES})

Monday, February 6, 2017

CLion + Win32

cmake_minimum_required(VERSION 3.6)
project(untitled4)

set(CMAKE_CXX_STANDARD 14)

#include_directories(${PROJECT_SOURCE_DIR}/INC)
#link_directories(${PROJECT_SOURCE_DIR}/LIB)

set(SOURCE_FILES main.cpp defines.h)
add_executable(untitled4 ${SOURCE_FILES})
target_link_libraries(untitled4 winmm.lib)

#target_link_libraries(untitled4 SDL2.lib SDL2main.lib)
 
defines.h

#ifndef DEFINES_H
#define DEFINES_H

#define WINDOW_WIDTH  400
#define WINDOW_HEIGHT 400

#define RADIUS        10
#define NUM_BALLS     15
#define MAX_VELOCITY  3

#define FRAMES_PER_SECOND 60

#endif
 
 
main.cpp
 
#include <windows.h>   
#include "defines.h"

//--------------------------------- Globals ------------------------------   
//   
//------------------------------------------------------------------------   

char* g_szApplicationName = "HelloWorld4";
char*   g_szWindowClassName = "MyWindowClass";

//---------------------------- WindowProc ---------------------------------   
//     
//  This is the callback function which handles all the windows messages   
//-------------------------------------------------------------------------   

LRESULT CALLBACK WindowProc (HWND   hwnd,
                             UINT   msg,
                             WPARAM wParam,
                             LPARAM lParam)
{

    switch (msg)
    {

        //A WM_CREATE msg is sent when your application window is first   
        //created   
        case WM_CREATE:
        {
            PlaySound("window_open.wav", NULL, SND_FILENAME | SND_ASYNC);
        }

            break;

        case WM_KEYUP:
        {
            switch(wParam)
            {
                case VK_ESCAPE:
                {
                    PostQuitMessage(0);
                }
                    break;
            }
        }


        case WM_PAINT:
        {
            PAINTSTRUCT ps;

            BeginPaint (hwnd, &ps);

            //**this is where we do any drawing to the screen**

            EndPaint (hwnd, &ps);
        }

            break;

        case WM_DESTROY:
        {
            // kill the application, this sends a WM_QUIT message
            PostQuitMessage (0);
        }

            break;


    }//end switch

    //this is where all the messages not specifically handled by our
    //winproc are sent to be processed
    return DefWindowProc (hwnd, msg, wParam, lParam);
}

//-------------------------------- WinMain -------------------------------   
//   
//  The entry point of the windows program   
//------------------------------------------------------------------------   
int WINAPI WinMain (HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR     szCmdLine,
                    int       iCmdShow)
{
    //handle to our window
    HWND                       hWnd;

    //our window class structure
    WNDCLASSEX     winclass;

    // first fill in the window class stucture
    winclass.cbSize        = sizeof(WNDCLASSEX);
    winclass.style         = CS_HREDRAW | CS_VREDRAW;
    winclass.lpfnWndProc   = WindowProc;
    winclass.cbClsExtra    = 0;
    winclass.cbWndExtra    = 0;
    winclass.hInstance     = hInstance;
    winclass.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    winclass.hCursor       = LoadCursor(NULL, IDC_ARROW);
    winclass.hbrBackground = (HBRUSH)GetStockObject (WHITE_BRUSH);
    winclass.lpszMenuName  = NULL;
    winclass.lpszClassName = g_szWindowClassName;
    winclass.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

    //register the window class
    if (!RegisterClassEx(&winclass))
    {
        MessageBox(NULL, "Registration Failed!", "Error", 0);

        //exit the application
        return 0;
    }

    //create the window and assign its ID to hwnd
    hWnd = CreateWindowEx (NULL,                 // extended style
                           g_szWindowClassName,  // window class name
                           g_szApplicationName,  // window caption
                           WS_OVERLAPPEDWINDOW,  // window style
                           0,                    // initial x position
                           0,                    // initial y position
                           WINDOW_WIDTH,         // initial x size
                           WINDOW_HEIGHT,        // initial y size
                           NULL,                 // parent window handle
                           NULL,                 // window menu handle
                           hInstance,            // program instance handle
                           NULL);                // creation parameters

    //make sure the window creation has gone OK
    if(!hWnd)
    {
        MessageBox(NULL, "CreateWindowEx Failed!", "Error!", 0);
    }

    //make the window visible
    ShowWindow (hWnd, iCmdShow);
    UpdateWindow (hWnd);

    //this will hold any windows messages
    MSG msg;

    //entry point of our message handler
    while (GetMessage (&msg, NULL, 0, 0))
    {
        TranslateMessage (&msg);
        DispatchMessage (&msg);
    }

    return msg.wParam;
}   
   

Monday, January 23, 2017

SFML 2.4 new cmake

cmake_minimum_required(VERSION 3.6)
project(untitled)

set(CMAKE_CXX_STANDARD 11)

set(SOURCE_FILES main.cpp)
set(EXECUTABLE_NAME "untitled")
add_executable(${EXECUTABLE_NAME} ${SOURCE_FILES})

# Detect and add SFMLset(CMAKE_MODULE_PATH "C:/SFML-2.4.1/cmake/Modules" ${CMAKE_MODULE_PATH})

#set(SFML_STATIC_LIBRARIES TRUE)find_package(SFML 2.4 COMPONENTS system window graphics network audio REQUIRED)

if(SFML_FOUND)
    include_directories(${SFML_INCLUDE_DIR})
    target_link_libraries(${EXECUTABLE_NAME} ${SFML_LIBRARIES})
endif()

Thursday, December 15, 2016

SDL2

cmake_minimum_required(VERSION 3.6)
project(sdl_test)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -lmingw32")
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")

include_directories(${PROJECT_SOURCE_DIR}/include)
link_directories(${PROJECT_SOURCE_DIR}/lib)

set(SOURCE_FILES main.cpp)
add_executable(sdl_test ${SOURCE_FILES})

target_link_libraries(sdl_test SDL2main SDL2)

------------------------------------------------------------------------------------------------------------

#include "include/SDL.h"

int main(int argc, char* argv[]) {
    // Start SDL2
    SDL_Init(SDL_INIT_EVERYTHING);

    // Create a Window in the middle of the screen
    SDL_Window *window = 0;

    window = SDL_CreateWindow("Hello xxxWorld!",
                              SDL_WINDOWPOS_CENTERED,
                              SDL_WINDOWPOS_CENTERED,
                              640, 480,
                              SDL_WINDOW_SHOWN);

    // Delay so that we can see the window appear
    SDL_Delay(2000);

    // Cleanup and Quit
    SDL_DestroyWindow(window);
    SDL_Quit();

    return 0;
}

Clion + SDL2

SDL2
https://www.libsdl.org/

Files:
https://github.com/tcbrindle/sdl2-cmake-scripts

CMakeLists.txt
cmake_minimum_required(VERSION 3.6)
project(sdl_test)

set(CMAKE_CXX_STANDARD 11)

set(SOURCE_FILES main.cpp)
add_executable(sdl_test ${SOURCE_FILES})


# SDL2
set(SDL2_PATH "C:\\SDL2-2.0.5\\x86_64-w64-mingw32")

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${sdl_test_SOURCE_DIR}/cmake")

find_package(SDL2 REQUIRED)
find_package(SDL2_Image REQUIRED)
find_package(SDL2_ttf REQUIRED)

include_directories(${SDL2_INCLUDE_DIR}
                    ${SDL2_IMAGE_INCLUDE_DIR}
                    ${SDL2_TTF_INCLUDE_DIR})

target_link_libraries(sdl_test ${SDL2_LIBRARY}
                             ${SDL2_IMAGE_LIBRARIES}
                             ${SDL2_TTF_LIBRARIES})


main.cpp
#include <SDL.h>

int main(int argc, char* argv[]) {
    // Start SDL2
    SDL_Init(SDL_INIT_EVERYTHING);

    // Create a Window in the middle of the screen
    SDL_Window *window = 0;

    window = SDL_CreateWindow("Hello World!",
                              SDL_WINDOWPOS_CENTERED,
                              SDL_WINDOWPOS_CENTERED,
                              640, 480,
                              SDL_WINDOW_SHOWN);

    // Delay so that we can see the window appear
    SDL_Delay(2000);

    // Cleanup and Quit
    SDL_DestroyWindow(window);
    SDL_Quit();

    return 0;
}

Friday, December 2, 2016