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

Wednesday, November 2, 2016

HUD!




















main.cpp
-----------------------------------------------------------------------------------------------
#include <SFML/Graphics.hpp>
#include "FuelBar.h"


using namespace sf;

int main()
{
    RenderWindow window(VideoMode(270, 480), "HUD!", Style::Close);
   
    //////////////////////////////////////////////
    FuelBar mFuelBar;
    mFuelBar.setPos(20.f, 300.f);
   
    while (window.isOpen())
    {
        Event event;
        while (window.pollEvent(event))
        {
            if (event.type == Event::Closed)
                window.close();
        }

        window.clear();

        /////////////////////////////////////////////
        for (Sprite n : mFuelBar.get()) {
            window.draw(n);
        }

        window.display();
    }

    return 0;
}

BarBackground.cpp
--------------------------------------------------------------------------------------
#include <SFML/Graphics.hpp>
#include <string>
#include "BarBackground.h"


BarBackground::BarBackground(string fileName)
{
    mTex.loadFromFile(fileName);
    mSpr.setTexture(mTex);
    mSpr.setPosition(0, 0);
}


BarBackground::~BarBackground()
{
}

void BarBackground::setPos(float x, float y)
{
    mSpr.setPosition(x, y);
}

Sprite& BarBackground::get()
{
   
    return mSpr;
}

BarBackground.h
-----------------------------------------------------------------------------
#pragma once

using namespace std;
using namespace sf;

class BarBackground
{
public:
    BarBackground(string);
    ~BarBackground();

    void setPos(float, float);
    Sprite& get();

private:
    Texture mTex;
    Sprite mSpr;
};

BarIcon.cpp
-------------------------------------------------------------------------------------
#include <SFML/Graphics.hpp>
#include <string>
#include "BarIcon.h"


BarIcon::BarIcon(string fileName)
{
    mTex.loadFromFile(fileName);
    mSpr.setTexture(mTex);
    mSpr.setPosition(0, 0);
}


BarIcon::~BarIcon()
{
}

void BarIcon::setPos(float x, float y)
{
    mSpr.setPosition(x, y);
}

Sprite& BarIcon::get()
{

    return mSpr;
}








BarIcon.h
-------------------------------------------------------------------
#pragma once

using namespace std;
using namespace sf;

class BarIcon
{
public:
    BarIcon(string);
    ~BarIcon();

    void setPos(float, float);
    Sprite& get();

private:
    Texture mTex;
    Sprite mSpr;
};

BarFuel.cpp
--------------------------------------------------------------------------
#include <SFML/Graphics.hpp>
#include "FuelBar.h"
#include <string>


FuelBar::FuelBar() : mBarBackground("graphics/hud.png"), mBarIcon("graphics/fuel.png")
{
    fuel = 100.f;

}


FuelBar::~FuelBar()
{
}

void FuelBar::setPos(float x, float y)
{
    // Background
    mBarBackground.setPos(x, y);

    // Status


    // lIcon
    mBarIcon.setPos(x + 5, y + 5);
}

vector<Sprite>& FuelBar::get()
{

    mFuelSprites.push_back(mBarBackground.get());
    mFuelSprites.push_back(mBarIcon.get());

    return mFuelSprites;
       
}

void FuelBar::updateFuelBar()
{

}

BarFuel.h
-----------------------------------------------------------------------------
#include "BarBackground.h"
#include "BarIcon.h"
#pragma once


using namespace std;
using namespace sf;

class FuelBar
{
public:
    FuelBar();
    ~FuelBar();

    void setPos(float, float);
    vector<Sprite>& get();

    void updateFuelBar();

private:
    float fuel;
    vector<Sprite> mFuelSprites;

    BarBackground mBarBackground;
    BarIcon mBarIcon;

};



Friday, October 28, 2016

xcars first test


Wednesday, October 12, 2016

VS Code + SFML

VS Code
https://code.visualstudio.com

c_cpp_properties.json
{
    "configurations": [
        {
            "name": "Mac",
            "includePath": ["/usr/include"],
            "browse" : {
                "limitSymbolsToIncludedHeaders" : true,
                "databaseFilename" : ""
            }
        },
        {
            "name": "Linux",
            "includePath": ["/usr/include"],
            "browse" : {
                "limitSymbolsToIncludedHeaders" : true,
                "databaseFilename" : ""
            }
        },
        {
            "name": "Win32",
            "includePath": ["c:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include",
            "C:/SFML-2.4.1/include",
            "C:/mingw32/include"
            ],
            "browse" : {
                "limitSymbolsToIncludedHeaders" : true,
                "databaseFilename" : ""
            }
        }
    ]
}

tasks.json
{
    // 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", "main.exe",
                "-std=c++11",
                "main.cpp",
                "-IC:/SFML-2.4.1/include",
                "-LC:/SFML-2.4.1/lib",
                "-lsfml-graphics-d",
                "-lsfml-window-d",
                "-lsfml-system-d"
            ],
    "showOutput": "always"
}

launch.json
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "C++ Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceRoot}/main.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}",
            "environment": [],
            "externalConsole": true,
            "linux": {
                "MIMode": "gdb"
            },
            "osx": {
                "MIMode": "lldb"
            },
            "windows": {
                "MIMode": "gdb",
                "miDebuggerPath": "c:/mingw32/bin/gdb.exe"
            }
        },
        {
            "name": "C++ Attach",
            "type": "cppdbg",
            "request": "attach",
            "program": "${workspaceRoot}/main.exe",
            "processId": "${command.pickProcess}",
            "linux": {
                "MIMode": "gdb"
            },
            "osx": {
                "MIMode": "lldb"
            },
            "windows": {
                "MIMode": "gdb"
            }
        }
    ]
}


Tuesday, October 11, 2016

Atom + SFML


Atom
https://atom.io/

Packages:
minimap
minimap-hightlight-selected
hightlight-selected
hightlight-line
find-and-replace
file-icons


linter-gcc

GCC Include path: C:/mingw64/include, C:/SFML-2.4.0/include

gpp-compiler
C++ Compiler options: -IC:/SFML-2.4.0/include -LC:/SFML-2.4.0/lib -lsfml-graphics -lsfml-window -lsfml-system


atom-beautify
C,C++: clang-format

(win7x64, x32: mingw64 - 6.1, clang - 3.9, sfml - 2.4).