dummy.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. ///////////////////////////////////////////////////////////////////////////////////
  2. /// OpenGL Mathematics (glm.g-truc.net)
  3. ///
  4. /// Copyright (c) 2005 - 2014 G-Truc Creation (www.g-truc.net)
  5. /// Permission is hereby granted, free of charge, to any person obtaining a copy
  6. /// of this software and associated documentation files (the "Software"), to deal
  7. /// in the Software without restriction, including without limitation the rights
  8. /// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. /// copies of the Software, and to permit persons to whom the Software is
  10. /// furnished to do so, subject to the following conditions:
  11. ///
  12. /// The above copyright notice and this permission notice shall be included in
  13. /// all copies or substantial portions of the Software.
  14. ///
  15. /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. /// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. /// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. /// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. /// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. /// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. /// THE SOFTWARE.
  22. ///
  23. /// @ref core
  24. /// @file glm/core/dummy.cpp
  25. /// @date 2011-01-19 / 2011-06-15
  26. /// @author Christophe Riccio
  27. ///
  28. /// GLM is a header only library. There is nothing to compile.
  29. /// dummy.cpp exist only a wordaround for CMake file.
  30. ///////////////////////////////////////////////////////////////////////////////////
  31. #define GLM_FORCE_RADIANS
  32. #define GLM_MESSAGES
  33. #include "../glm.hpp"
  34. #include <limits>
  35. struct material
  36. {
  37. glm::vec4 emission; // Ecm
  38. glm::vec4 ambient; // Acm
  39. glm::vec4 diffuse; // Dcm
  40. glm::vec4 specular; // Scm
  41. float shininess; // Srm
  42. };
  43. struct light
  44. {
  45. glm::vec4 ambient; // Acli
  46. glm::vec4 diffuse; // Dcli
  47. glm::vec4 specular; // Scli
  48. glm::vec4 position; // Ppli
  49. glm::vec4 halfVector; // Derived: Hi
  50. glm::vec3 spotDirection; // Sdli
  51. float spotExponent; // Srli
  52. float spotCutoff; // Crli
  53. // (range: [0.0,90.0], 180.0)
  54. float spotCosCutoff; // Derived: cos(Crli)
  55. // (range: [1.0,0.0],-1.0)
  56. float constantAttenuation; // K0
  57. float linearAttenuation; // K1
  58. float quadraticAttenuation;// K2
  59. };
  60. // Sample 1
  61. #include <glm/vec3.hpp>// glm::vec3
  62. #include <glm/geometric.hpp>// glm::cross, glm::normalize
  63. glm::vec3 computeNormal
  64. (
  65. glm::vec3 const & a,
  66. glm::vec3 const & b,
  67. glm::vec3 const & c
  68. )
  69. {
  70. return glm::normalize(glm::cross(c - a, b - a));
  71. }
  72. typedef unsigned int GLuint;
  73. #define GL_FALSE 0
  74. void glUniformMatrix4fv(GLuint, int, int, float*){}
  75. // Sample 2
  76. #include <glm/vec3.hpp> // glm::vec3
  77. #include <glm/vec4.hpp> // glm::vec4, glm::ivec4
  78. #include <glm/mat4x4.hpp> // glm::mat4
  79. #include <glm/gtc/matrix_transform.hpp> // glm::translate, glm::rotate, glm::scale, glm::perspective
  80. #include <glm/gtc/type_ptr.hpp> // glm::value_ptr
  81. void func(GLuint LocationMVP, float Translate, glm::vec2 const & Rotate)
  82. {
  83. glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.f);
  84. glm::mat4 ViewTranslate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Translate));
  85. glm::mat4 ViewRotateX = glm::rotate(ViewTranslate, Rotate.y, glm::vec3(-1.0f, 0.0f, 0.0f));
  86. glm::mat4 View = glm::rotate(ViewRotateX, Rotate.x, glm::vec3(0.0f, 1.0f, 0.0f));
  87. glm::mat4 Model = glm::scale(glm::mat4(1.0f), glm::vec3(0.5f));
  88. glm::mat4 MVP = Projection * View * Model;
  89. glUniformMatrix4fv(LocationMVP, 1, GL_FALSE, glm::value_ptr(MVP));
  90. }
  91. // Sample 3
  92. #include <glm/vec2.hpp>// glm::vec2
  93. #include <glm/packing.hpp>// glm::packUnorm2x16
  94. #include <glm/integer.hpp>// glm::uint
  95. #include <glm/gtc/type_precision.hpp>// glm::i8vec2, glm::i32vec2
  96. std::size_t const VertexCount = 4;
  97. // Float quad geometry
  98. std::size_t const PositionSizeF32 = VertexCount * sizeof(glm::vec2);
  99. glm::vec2 const PositionDataF32[VertexCount] =
  100. {
  101. glm::vec2(-1.0f,-1.0f),
  102. glm::vec2( 1.0f,-1.0f),
  103. glm::vec2( 1.0f, 1.0f),
  104. glm::vec2(-1.0f, 1.0f)
  105. };
  106. // Half-float quad geometry
  107. std::size_t const PositionSizeF16 = VertexCount * sizeof(glm::uint);
  108. glm::uint const PositionDataF16[VertexCount] =
  109. {
  110. glm::uint(glm::packUnorm2x16(glm::vec2(-1.0f, -1.0f))),
  111. glm::uint(glm::packUnorm2x16(glm::vec2( 1.0f, -1.0f))),
  112. glm::uint(glm::packUnorm2x16(glm::vec2( 1.0f, 1.0f))),
  113. glm::uint(glm::packUnorm2x16(glm::vec2(-1.0f, 1.0f)))
  114. };
  115. // 8 bits signed integer quad geometry
  116. std::size_t const PositionSizeI8 = VertexCount * sizeof(glm::i8vec2);
  117. glm::i8vec2 const PositionDataI8[VertexCount] =
  118. {
  119. glm::i8vec2(-1,-1),
  120. glm::i8vec2( 1,-1),
  121. glm::i8vec2( 1, 1),
  122. glm::i8vec2(-1, 1)
  123. };
  124. // 32 bits signed integer quad geometry
  125. std::size_t const PositionSizeI32 = VertexCount * sizeof(glm::i32vec2);
  126. glm::i32vec2 const PositionDataI32[VertexCount] =
  127. {
  128. glm::i32vec2 (-1,-1),
  129. glm::i32vec2 ( 1,-1),
  130. glm::i32vec2 ( 1, 1),
  131. glm::i32vec2 (-1, 1)
  132. };
  133. struct intersection
  134. {
  135. glm::vec4 position;
  136. glm::vec3 normal;
  137. };
  138. /*
  139. // Sample 4
  140. #include <glm/vec3.hpp>// glm::vec3
  141. #include <glm/geometric.hpp>// glm::normalize, glm::dot, glm::reflect
  142. #include <glm/exponential.hpp>// glm::pow
  143. #include <glm/gtc/random.hpp>// glm::vecRand3
  144. glm::vec3 lighting
  145. (
  146. intersection const & Intersection,
  147. material const & Material,
  148. light const & Light,
  149. glm::vec3 const & View
  150. )
  151. {
  152. glm::vec3 Color(0.0f);
  153. glm::vec3 LightVertor(glm::normalize(
  154. Light.position - Intersection.position +
  155. glm::vecRand3(0.0f, Light.inaccuracy));
  156. if(!shadow(Intersection.position, Light.position, LightVertor))
  157. {
  158. float Diffuse = glm::dot(Intersection.normal, LightVector);
  159. if(Diffuse <= 0.0f)
  160. return Color;
  161. if(Material.isDiffuse())
  162. Color += Light.color() * Material.diffuse * Diffuse;
  163. if(Material.isSpecular())
  164. {
  165. glm::vec3 Reflect(glm::reflect(
  166. glm::normalize(-LightVector),
  167. glm::normalize(Intersection.normal)));
  168. float Dot = glm::dot(Reflect, View);
  169. float Base = Dot > 0.0f ? Dot : 0.0f;
  170. float Specular = glm::pow(Base, Material.exponent);
  171. Color += Material.specular * Specular;
  172. }
  173. }
  174. return Color;
  175. }
  176. */
  177. int main()
  178. {
  179. return 0;
  180. }