raylib-cpp
C++ object-oriented wrapper library for raylib.
Material.hpp
1 /*
2 * LICENSE: zlib/libpng
3 *
4 * raylib-cpp is licensed under an unmodified zlib/libpng license, which is an OSI-certified,
5 * BSD-like license that allows static linking with closed source software:
6 *
7 * Copyright (c) 2020 Rob Loach (@RobLoach)
8 *
9 * This software is provided "as-is", without any express or implied warranty. In no event
10 * will the authors be held liable for any damages arising from the use of this software.
11 *
12 * Permission is granted to anyone to use this software for any purpose, including commercial
13 * applications, and to alter it and redistribute it freely, subject to the following restrictions:
14 *
15 * 1. The origin of this software must not be misrepresented; you must not claim that you
16 * wrote the original software. If you use this software in a product, an acknowledgment
17 * in the product documentation would be appreciated but is not required.
18 *
19 * 2. Altered source versions must be plainly marked as such, and must not be misrepresented
20 * as being the original software.
21 *
22 * 3. This notice may not be removed or altered from any source distribution.
23 */
24 
25 #ifndef RAYLIB_CPP_INCLUDE_MATERIAL_HPP_
26 #define RAYLIB_CPP_INCLUDE_MATERIAL_HPP_
27 
28 #include <string>
29 #include <vector>
30 
31 #include "./raylib.hpp"
32 #include "./raylib-cpp-utils.hpp"
33 
34 namespace raylib {
35 class Material : public ::Material {
36  public:
37  Material(const ::Material& material) {
38  set(material);
39  }
40 
45  set(LoadMaterialDefault());
46  }
47 
49  Unload();
50  }
51 
55  static std::vector<Material> Load(const std::string& fileName) {
56  int count = 0;
57  ::Material* materials = ::LoadMaterials(fileName.c_str(), &count);
58  return std::vector<Material>(materials, materials + count);
59  }
60 
61  GETTERSETTER(::Shader, Shader, shader)
62  GETTERSETTER(::MaterialMap*, Maps, maps)
63  GETTERSETTER(float*, Params, params)
64 
65  Material& operator=(const ::Material& material) {
66  set(material);
67  return *this;
68  }
69 
73  inline void Unload() {
74  if (maps != NULL) {
75  ::UnloadMaterial(*this);
76  maps = NULL;
77  }
78  }
79 
83  inline Material& SetTexture(int mapType, const ::Texture2D& texture) {
84  ::SetMaterialTexture(this, mapType, texture);
85  return *this;
86  }
87 
88  protected:
89  inline void set(const ::Material& material) {
90  shader = material.shader;
91  maps = material.maps;
92  params = material.params;
93  }
94 };
95 } // namespace raylib
96 
97 #endif // RAYLIB_CPP_INCLUDE_MATERIAL_HPP_
raylib
Provides all the classes associated with raylib-cpp.
Definition: AudioDevice.hpp:31
raylib::Material::~Material
~Material()
Definition: Material.hpp:48
raylib::Material::Load
static std::vector< Material > Load(const std::string &fileName)
Load materials from model file.
Definition: Material.hpp:55
raylib::Material::SetTexture
Material & SetTexture(int mapType, const ::Texture2D &texture)
Set texture for a material map type (MAP_DIFFUSE, MAP_SPECULAR...)
Definition: Material.hpp:83
raylib::Material::set
void set(const ::Material &material)
Definition: Material.hpp:89
raylib::Material::Material
Material()
Load default material (Supports: DIFFUSE, SPECULAR, NORMAL maps)
Definition: Material.hpp:44
raylib::Shader
Definition: Shader.hpp:35
raylib::Material::Unload
void Unload()
Unload material from memory.
Definition: Material.hpp:73
raylib::Material::Material
Material(const ::Material &material)
Definition: Material.hpp:37
raylib::Material
Definition: Material.hpp:35