Build OpenGL samples

Updated: 12/19/2024

This page describes how to compile the OpenGL sample project included in the Live2D Cubism SDK for Native with Visual Studio in a Windows environment.

Note: The content of this article is based on the Cubism 4 SDK for Native R1.
The method and procedure may differ depending on the Cubism SDK version. 

What You Need

Live2D Cubism SDK for Native

The main body of the SDK. Download from the “official download page.”

Visual Studio

This is the development environment that will be used here. The language will be C++.
Please use Visual Studio 2015 or later.

CMake

Used to generate project files.

GLFW

This is an auxiliary library for OpenGL, with input and window management capabilities.
This can be downloaded using the batch file included in the Cubism SDK sample.

GLEW

This is an extension library for OpenGL, which makes it easy to call OpenGL extensions.
This can be downloaded using the batch file included in the Cubism SDK sample.

In the following instructions, GLFW and GLEW are downloaded from the batch file included in the Cubism SDK sample, so there is no need to download them in advance.

For tools and libraries such as CMake, GLFW, GLEW, etc., please check the procedures and versions described in ‘README.md’ located at “[root]Samples/OpenGL” in the sample SDK ZIP.

Installation process

Visual Studio

Install the integrated development environment.
Set up the system so that C++ can compile.

CMake

Install CMake.
CMake operations are used from a batch file, so the CMake path setting should be set so that it can be referenced by the user who will use it.

Note: Images may differ from the actual screen. 

Development of GLFW and GLEW

For GLFW and GLEW deployment, please refer to the instructions in ‘README.md’ in “Samples/OpenGL.”
In Windows, run “setup.bat” in “Samples/OpenGL/thirdParty” to download GLFW and GLEW.

After batch file deployment, the folder structure will look like the following.

Note: If you downloaded GLFW and GLEW manually, you need to extract them into the “Samples/OpenGL/thirdParty” folder.

Execute CMake

CMake can also be used from the GUI, but at this time use the batch file included in the sample.
In Windows, the batch file can be found in “Samples/OpenGL/Demo/proj.win.cmake/scripts.”
The batch file for Windows has a combination of several settings to choose from.

• NMake or Project

NMake builds from the command prompt and generates an executable file; use a batch file starting with nmake_.
Use batch files starting with proj_ when editing code, etc. from Visual Studio.

• Version of Visual Studio

Please select the version of Visual Studio you have installed.

In this example, the “proj_msvc2015.bat” file is executed to select the project containing the Visual Studio 2015 solution file.

When executed, choices will be displayed as shown in the image below, so enter the corresponding number in single-byte numbers.

• Selecting the architecture

Select x86(Win32) or x64(Win64).
Select as appropriate depending on the environment in which it is used.

• Selecting modules for Cubism Core

Select the Cubism Core runtime library to be used.
See the official Microsoft documentation for the meanings of MD, MT, etc.

• Selecting project content

Select the content of the project to be generated.
If you select Full Demo: A sample project will be generated that utilizes all the features of the Cubism SDK for Native.
If you select Minimum Demo: A minimally configured project is generated that displays a model that repeats a single motion. The following features are used in this project.

  • Load and display Cubism models
  • Ability to loop a single motion
  • Eye tracking using mouse dragging
  • Physics
  • Breath
  • Pose

If the input is successful, CMake generation will begin.
Note: If an error occurs after the generation starts, please check the version of CMake and the version of Visual Studio you are specifying.

Build

When CMake generation is finished, open the solution file from the generated files.
In this example, execute
• proj_msvc2015.bat

and select
• x64(Win64)
• use the multithread-specific and DLL-specific version of the run-time library (MD)
• Full Demo

and then
open the output file “Demo.sln” in “[root]/Samples/OpenGL/Demo/proj.win.cmake/build/proj_msvc2015_x64_md” in Visual Studio and execute the build.

Execute

If the build is successful, let’s run it through debugging.

If a large screen appears and you get a log output from the command prompt, you’ve succeeded.
Note: In the smallest sample, UI such as the background and the gear icon for switching models are not displayed.

To adjust the window size, change the values of the 1st and 2nd arguments of glfwCreateWindow() used in LAppDelegate::Initialize() in “/Sample/OpenGL/Demo/proj.win.cmake/src/LAppDelegate.cpp.”

_window = glfwCreateWindow(RenderTargetWidth, RenderTargetHeight, "SAMPLE", NULL, NULL);

Note: Actual values for RenderTargetWidth and RenderTargetHeight are defined in “/Sample/OpenGL/Demo/proj.win.cmake/src/LAppDefine.cpp.”

Destination Where the Executable File Will Be Output

In this project created from CMake, unlike normal projects, the output destination of the file is created in the same hierarchy as the project folder.

Specifically, when the project folder is “[root]/Samples/OpenGL/Demo/proj.win.cmake/build/proj_msvc2015_x64_md” the executable file is output to the same location as the project folder.

Please note that “[root]/Samples/OpenGL/Demo/proj.win.cmake/build/proj_msvc2015_x64_md/Release” etc. will be generated at build time, but no files will be output here.

Was this article helpful?
YesNo
Please let us know what you think about this article.