-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Using raylib with Cpp
This page will go over some of the common questions new users of raylib have when using C++.
raylib works with C++ in the exact same way it does with the C language. You can use raylib from C++ with no special modifications or build steps. Simply include raylib for your compiler and platform in the exact same way you do for C. raylib is fully compatible with both C and C++.
No, raylib-cpp
is not required to use raylib with C++. raylib-cpp
is an optional wrapper that sits on top of the regular C raylib in order to provide object oriented access to raylib. raylib-cpp
still calls the same C raylib in the end.
How can I fix C compound-literals related errors?
You can get the folllowing error when building raylib examples in C++ in C++:
A parenthesized type followed by an initializer list is a non-standard explicit type conversion syntax
This type of structure initialization (Vector3){ 1.0f, 2.0f, 3.0f }
is called a compound literal and is not supported by C++. Some C++ compilers are strict and will not allow it. This code can be converted to brace initialization in C++ by simply removing the parentheses around the type. Changing the code to Vector3{ 1.0f, 2.0f, 3.0f }
will fix the error.
This change needs to be made for code that is pulled from the raylib C examples.
DrawText()
takes a const char *text
, but I have a std::string
in C++; std::string
has a method named c_str()
, this will return the const char *str
stored in the string, use it as the argument for any C function that takes a const char *text
. Example:
DrawText(my_string.c_str(),0,0,20,RED);
www.raylib.com | itch.io | GitHub | Discord | YouTube
- Architecture
- Syntax analysis
- Data structures
- Enumerated types
- External dependencies
- GLFW dependency
- libc dependency
- Platforms and graphics
- Input system
- Default shader
- Custom shaders
- Coding conventions
- Integration with other libs
- Working on Windows
- Working on macOS
- Working on GNU Linux
- Working on Chrome OS
- Working on FreeBSD
- Working on Raspberry Pi
- Working for Android
- Working for Web (HTML5)
- Creating Discord Activities
- Working anywhere with CMake
- CMake Build Options
- raylib templates: Get started easily
- How To: Quick C/C++ Setup in Visual Studio 2022, GCC or MinGW
- How To: C# Visual Studio Setup
- How To: VSCode
- How To: Eclipse
- How To: Sublime Text
- How To: Code::Blocks