Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon


24. July 2016

 

Traditionally I don’t recommend beginners start with C++.  There are a number of reasons behind this opinion, most of which are explained in this video.  Most of the reasons however have very little to do with the language itself (which does of course have some downsides) and more to do with the build system, linker and limited included libraries.  I recently discovered a library aimed at beginners that alleviates a great deal of the downsides of learning using C++, raylib.  It’s free, open source (available on Github) and provides most of the functionality you require to make a game.  Most importantly, it’s aimed at beginners meaning the library is easy to use and comes with a turn key installer that enables you to hit the ground running.

If you are interested in learning more about raylib, be sure to watch this video (also embedded below).

 

The key features of raylib are:

- Written in plain C code (C99)
- Uses C# PascalCase/camelCase notation
- Hardware accelerated with OpenGL (1.1, 2.1, 3.3 or ES 2.0)
- Unique OpenGL abstraction layer (usable as standalone module): [rlgl]
- Powerful fonts module with SpriteFonts support (XNA fonts, AngelCode fonts, TTF)
- Outstanding texture formats support, including compressed formats (DXT, ETC, ASTC)
- Basic 3d support for Geometrics, Models, Heightmaps and Billboards
- Materials (diffuse, normal, specular) and Lighting (point, directional, spot)
- Shaders support, including Model shaders and Postprocessing shaders
- Powerful math module for Vector and Matrix operations [raymath]
- Audio loading and playing with streaming support (WAV, OGG, XM, MOD)
- VR stereo rendering support with configurable HMD device parameters
- Multiplatform support: Android, Raspberry Pi, HTML5, Oculus Rift CV1
- Custom color palette for fancy visuals on raywhite background
- Minimal external dependencies (GLFW3, OpenGL, OpenAL)

 

The part I found most impressive though is the installer.  It comes with a pre-configured version of the MingW compiler and Notepad++ set up for development right away.  Basically you run the installer, open notepad++, start writing code and hit F6 to run it.  No dealing with setting up a compiler, learning about linkers and all the various things that make the C++ learning curve so painful.  Well, most of the things...

 

I should point out quickly, while I’ve been calling it a C++ library, it’s actually a C library.  This is a minor distinction as it is perfectly usable in C++ and feels like C++.  It comes with a copious amount of examples, with very easy to understand code.  Here for example is an, um, example that illustrates loading and drawing images:

/********************************************************************************
***********
*
*   raylib [textures] example - Image loading and drawing on it
*
*   NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU 
memory (VRAM)
*
*   This example has been created using raylib 1.4 (www.raylib.com)
*   raylib is licensed under an unmodified zlib/libpng license (View raylib.h 
for details)
*
*   Copyright (c) 2016 Ramon Santamaria (@raysan5)
*
*********************************************************************************
***********/

#include "raylib.h"

int main()
{
    // Initialization
    //---------------------------------------------------------------------------
    -----------
    int screenWidth = 800;
    int screenHeight = 450;

    InitWindow(screenWidth, screenHeight, "raylib [textures] example - image 
    drawing");

    // NOTE: Textures MUST be loaded after Window initialization (OpenGL context 
    is required)

    Image cat = LoadImage("resources/cat.png");             // Load image in CPU 
    memory (RAM)
    ImageCrop(&cat, (Rectangle){ 100, 10, 280, 380 });      // Crop an image 
    piece
    ImageFlipHorizontal(&cat);                              // Flip cropped 
    image horizontally
    ImageResize(&cat, 150, 200);                            // Resize flipped-
    cropped image
    
    Image parrots = LoadImage("resources/parrots.png");     // Load image in CPU 
    memory (RAM)
    
    // Draw one image over the other with a scaling of 1.5f
    ImageDraw(&parrots, cat, (Rectangle){ 0, 0, cat.width, cat.height }, (
    Rectangle){ 30, 40, cat.width*1.5f, cat.height*1.5f });
    ImageCrop(&parrots, (Rectangle){ 0, 50, parrots.width, parrots.height - 100 }
    ); // Crop resulting image
    
    UnloadImage(cat);       // Unload image from RAM

    Texture2D texture = LoadTextureFromImage(parrots);      // Image converted 
    to texture, uploaded to GPU memory (VRAM)
    UnloadImage(parrots);   // Once image has been converted to texture and 
    uploaded to VRAM, it can be unloaded from RAM
    
    SetTargetFPS(60);
    //---------------------------------------------------------------------------
    ------------

    // Main game loop
    while (!WindowShouldClose())    // Detect window close button or ESC key
    {
        // Update
        //-----------------------------------------------------------------------
        -----------
        // TODO: Update your variables here
        //-----------------------------------------------------------------------
        -----------

        // Draw
        //-----------------------------------------------------------------------
        -----------
        BeginDrawing();

            ClearBackground(RAYWHITE);

            DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 
            - texture.height/2 - 40, WHITE);
            DrawRectangleLines(screenWidth/2 - texture.width/2, screenHeight/2 - 
            texture.height/2 - 40, texture.width, texture.height, DARKGRAY);

            DrawText("We are drawing only one texture from various images 
            composed!", 240, 350, 10, DARKGRAY);
            DrawText("Source images have been cropped, scaled, flipped and 
            copied one over the other.", 190, 370, 10, DARKGRAY);

        EndDrawing();
        //-----------------------------------------------------------------------
        -----------
    }

    // De-Initialization
    //---------------------------------------------------------------------------
    -----------
    UnloadTexture(texture);       // Texture unloading

    CloseWindow();                // Close window and OpenGL context
    //---------------------------------------------------------------------------
    -----------

    return 0;
}

 

All examples are a single .c file and there are plenty of them.  All you need to do is open them in Notepad++ and hit F6 to run.

 

At the end of the day, I still don’t personally think C++ is the ideal language to learn game programming, or programming in general.  However if you are going to start using C++, raylib is the single best starting point I have ever seen.  In fact, let me know if you would be interested in a beginner C++ tutorial series built around this library, let me know!

 

The Video

Programming

blog comments powered by Disqus

Month List

Popular Comments

Unreal Engine 4.11 Preview Available
Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon


22. December 2015

 

Unreal have just released a preview version of Unreal Engine 4.11 today. 

The following is a list of items updated within this release:

  • Rendering Updates:
    • New physically based shading model for realistic hair based on the latest research from film. It models 2 specular lobes, transmission, and scattering.
    • New physically based shading model for eyes.
    • New physically based shading model for cloth. This combines the standard shading model with a layer of velvet fibers. This layer simulates fuzz and fabrics.
    • Capsule Shadows - We now have support for very soft indirect shadows cast by a capsule representation of the character
    • Lightmass Portals - Skylight quality indoors can be massively improved by setting up Portal actors over openings. Portals tell Lightmass where to look for incoming lighting, they don’t actually emit light themselves. Portals are best used covering small openings that are important to the final lighting. Placing large Portals all over the level will dramatically increase build times.
    • Per-vertex translucency lighting - There are two new translucency lighting modes available in the material editor which compute lighting per-vertex. PerVertex lighting modes use half as many shader instructions and texture lookups.
    • We now have support for 3 lighting channels. You can set which channels a PrimitiveComponent or a LightComponent is in.
    • We’ve integrated Intel's Embree ray tracing library into Lightmass and we got a huge lighting build speedup from it, as the majority of lighting build time goes toward tracing rays to figure out how light is bouncing.
    • We’ve integrated updates to the D3D12 RHI to allow better CPU utilization while generating rendering commands in parallel.
    • Improved quality and performance of the SubsurfaceScatteringProfile shading model.
    • Circle Depth of Field post process - New Material Functions to render small particles with out of focus.
    • Materials using separate translucency can now be rendered at a lower resolution, which can be useful to improve GPU performance for fillrate and overdraw heavy geometry (for example particle effects).
      The resolution is controlled via a console variable, r.SeparateTranslucencyScreenPercentage, which expresses separate translucency as a percentage of current screen resolution.
    • Static mesh LOD transitions now supporting dithering.
  • Core Updates:
    • CrashReporter Server available
    • Improvements
      • Garbage Collection up to 4x faster
      • Dependency preloading - brings us close to seek free loading (90% of the time seek free), faster package loading
      • UnrealHeaderTool makefiles - iterative UHT runs are 5x faster
  • Platform Updates:
    • Metal on Mac
    • AppleTV support
    • Fast Semantics on XboxOne
    • VS2015 on XboxOne
    • Code plugins for PS4
    • Deterministic cooking "bug-finder" commandlet
    • Background content precaching for most-recently-cooked-platform
  • Editor/Tools Updates:
    • Sequencer improvements
      • New tracks: Shot/director, play rate, slomo, fade, material, particle parameter tracks.
      • Improved movie rendering, exr support
      • Improved/consistent keyframing behaviors, copy/paste keyframes, copy keys from matinee, 3d keyframe path display
      • Master sequence workflow
      • Spawnables workflow
      • UI improvements: track coloring, keyframe shapes/coloring, track filtering
  • Framework Updates:
    • Anim Dynamics Skeletal Control for Animation Blueprints - allows dynamic motion to be procedurally added to skeletal meshes without having to use a full physics solution. This is accomplished using the new “Anim Dynamics” node in the Animation Graph of an Animation Blueprint.
  • Networking Updates:
    • Packet handler system
      • Easy interception of packets for things like encryption, compression, etc
      • Added CryptoPP, and packet handler components that support it out of the box
    • Oodle integration (SDK purchase required)
    • Client-side replays
  • Blueprint Updates:
    • The Blueprint search tool has been updated to support more advanced search functionality (to get more targeted results).
    • Native C++ functions marked BlueprintCallable can now also be optionally marked as DevelopmentOnly. This new metadata allows calls to those functions to be disabled (compiled out) of all Blueprint function graphs in cooked/packaged builds without breaking the execution flow.
  • Mobile Rendering Updates:
    • Support for hardware instancing on iOS and many Android devices, reducing draw calls for Foliage and InstancedStaticMeshComponents.
    • Improved reflections on mobile, optionally interpolating between up to 3 reflection captures and performing parallax correction
  • VR Updates:
    • Instanced Stereo Rendering
    • Head Mounted Display Camera Refactor
    • Stereo Layers
    • SDK Updates: Oculus SDK 1.0, SteamVR 1.0, PlayStationVR SDK3 Updates, and Gear VR LibOVRMobile 1.0 (not yet updated for Preview 1, but will be by final release)
  • Landscape/Foliage Updates:
    • Landscape layer whitelisting, allowing you to control which landscape components should accept which layers in the painting tool
    • Landscape layer usage view mode, to quickly see which landscape components are using which layers
    • Support for baking WorldPositionOffset changes into landscape collision

 

Known issues in this release are:

UE-24744 Editor crashes when a Character is selected in Paint Mode.
UE-24721 Hot Reload fails to take effect when compiled from Xcode
UE-24716 Crash occurs selecting to open Session Frontend on Mac
UE-24715 Unplayable GearVR tracking sensitivity in First Person Template
UE-24699 Unable to build Linux editor ConvexHull2D file not found
UE-24650 Materials using separate translucency stop rendering if r.SeparateTranslucency is 0
UE-24590 Crash resetting Bound Bone in Anim Dynamics node
UE-24369 MAC: UI: Top half of the game client is not visible to users when Mac client is launched in fullscreen.
UE-23231 Can't Upload iOS build signed on PC

 

More details of the release are available here.  You can download the preview release using the Epic Game Launcher.

GameDev News

blog comments powered by Disqus

Month List

Popular Comments