Friday, July 21, 2017

VSCode + java

task.json

{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"taskName": "build",
"command": "javac",
"args": [
"-g",
"${file}"
]
}
]
}

Saturday, July 8, 2017

CMake + SDL2

cmake_minimum_required(VERSION 3.8)
project(SDL_test)

set(CMAKE_CXX_STANDARD 11)

include_directories(C:/SDL2mingw64/include)
link_directories(C:/SDL2mingw64/lib)

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

target_link_libraries(SDL_test mingw32 SDL2main SDL2)

Thursday, June 29, 2017

VS Code + SDL2

task


// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "g++",
"isShellCommand": true,
"args": [
"-g",
"-o",
"H:/CPPnew/Game/bin/main.exe",
"-std=c++11",
" main.cpp",
"-IH:/CPPnew/Game/common/include/SDL2",
"-LH:/CPPnew/Game/common/lib",
"-lmingw32",
"-lSDL2main",
"-lSDL2",
"-lSDL2_image",
"-lSDL2_ttf",
"-lSDL2_mixer"
],
"showOutput": "always"
}



cpp


"name": "Win32",
"includePath": [
"${workspaceRoot}",
"H:/CPPnew/Game/common/include/SDL2",
"C:/mingw64/x86_64-w64-mingw32/include",
"C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.10.25017/include/*",
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/um",
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/ucrt",
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/shared",
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/winrt"
],
"defines": [
"_DEBUG",
"UNICODE"
],
"intelliSenseMode": "msvc-x64",
"browse": {
"path": [
"H:/CPPnew/Game/common/include/SDL2",
"C:/mingw64/x86_64-w64-mingw32/include",
"C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.10.25017/include/*",
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/um",
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/ucrt",
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/shared",
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/winrt"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""

Wednesday, June 28, 2017

Eclipse + clang

This is a setup from scratch that worked for me (ubuntu 14.04 + eclipse mars + clang 3.6.2). You will be probably interested in steps 8 and 9.
  1. Install Ubuntu
  2. Install Java 8:
    sudo apt-add-repository ppa:webupd8team/java
    apt-get update
    apt-get install oracle-java8-installer
  3. Install g++:
    apt-get install g++
  4. Install llvm/clang 3.6.2:
    http://llvm.org/releases/download.html
    Download and extract to folder of your choice. I renamed the extracted folder to 'clang+llvm-3.6.2' so it is more convenient during setup. Also I have moved it into /home/[user_name]/Development folder that I created.
  5. Add LLVM/Clang to PATH:
    sudo gedit /etc/environment
    Append the path to point to your llvm/clang bin folder.
    PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/[your_user_name]/Development/clang+llvm-3.6.2/bin"
    Yours might look different, depending on where you placed your llvm/clang.
    Save changes, reboot.
  6. Install build-essential:
    sudo apt-get update
    apt-get install build-essential
  7. Install eclipse:
    Download and extract to a folder of your choice. (I moved it to my Development folder and renamed to eclipse_mars, but it is optional)
  8. Install CDT and LLVM Support:
    • In opened Eclipse, 'Help > Install New Software > Work with: --All available sites--'.
    • Once the list loads, expand Programming Languages, install 'C/C++ Development Tools SDK' and 'C/C++ LLVM-Family Compiler Build Support'.
  9. Configure eclipse:
    • In the top menu bar, select 'Window > Prefences'.
    • Select 'C/C++ > LLVM' in the left menu.
    • In the 'LLVM installation folder:', navigate to your LLVM bin folder (/home/[your_user_name]/Development/clang+llvm-3.6.2/bin) and click Apply and OK.
    • Select 'File > New > C++ Project' in the menu. C++ Project popup window opens.
    • Enter Project name, select Project type in the Executable group and 'LLVM with Clang(Linux)' in Toolchains. Click 'Next > Next'.
    • In the Select Configurations, click 'Advanced settings' button.
    • Select 'C/C++ Build > Settings' in the left menu.
    • In the 'Tool Settings' tab, scroll down and select 'LLVM Clang++ > Dialect'. Change it to 'ISO C++11 (-std=c++0x)' and click 'Apply' button.
    • In the 'Tool Settings' tab, scroll down and select 'LLVM Clang C++ linker > Libraries'. Make sure the 'Libraries(-l)' list contains 'stdc++'. Make sure the 'Library search path(-L) list contains '/usr/lib/gcc/x86_64-linux-gnu/4.8'
    • Click 'Apply' button.
    • In the left menu, select 'C/C++ General > Preprocessor include paths, Macros etc.'
    • Click 'Providers' tab and make sure 'CDT GCC Built-in Compiler Settings [Shared]' is selected. (Should be selected already).
    • Click 'OK' button.
    • Click 'Finish' button.
You should be now able to compile and run your code.

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()