Simple game engine with complete export to scripting language
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

252 lines
6.4KB

  1. Addons
  2. ------
  3. * load addons in sorted order
  4. Scripting
  5. ---------
  6. * make event based input available
  7. * make ShaderProgram a class
  8. * create RenderSet AND/OR RenderQueue
  9. #if 0
  10. /*
  11. void RenderDevice::renderShadowVolume(Mesh *mesh,
  12. const Vector3Float &direction, const Vector3Float &extrude)
  13. {
  14. // Calculate visibility
  15. unsigned int i, frontface_count = 0;
  16. for (i=0; i < mesh->shadowfaces.count(); i++)
  17. {
  18. if (mesh->shadowfaces[i].plane.distance(extrude) < 0)
  19. {
  20. shadow_faces[i].backFace = false;
  21. frontface_count++;
  22. }
  23. else
  24. {
  25. shadow_faces[i].backFace = true;
  26. }
  27. }
  28. unsigned int max_edges = (frontface_count) * 3;
  29. if (_extrudeVertexBuffer.count() < (max_edges * 4))
  30. {
  31. clog << ">>> increase shadow buffers to "<< max_edges << " Edges"<< endline;
  32. _extrudeVertexBuffer.create( (max_edges + 100) * 4);
  33. }
  34. if (_extrudeIndexBuffer.count() < (max_edges * 6))
  35. _extrudeIndexBuffer.create( (max_edges + 100) * 6);
  36. // fill the buffer
  37. unsigned int j, k;
  38. extrude_quad_count = 0;
  39. Vertex *face_vertices[3];
  40. for (i=0; i<shadow_faces.count(); i++)
  41. {
  42. if (shadow_faces[i].backFace == false)
  43. {
  44. for (j=0; j<3; j++)
  45. {
  46. k = shadow_faces[i].neighbours[j];
  47. if ( (k == 0) || (shadow_faces[k-1].backFace == true))
  48. {
  49. unsigned int src_index_offset = i * 3;
  50. face_vertices[0]
  51. = &mesh->vertex_buffer[ mesh->index_buffer[ src_index_offset ] ];
  52. face_vertices[1]
  53. = &mesh->vertex_buffer[ mesh->index_buffer[ src_index_offset + 1] ];
  54. face_vertices[2]
  55. = &mesh->vertex_buffer[ mesh->index_buffer[ src_index_offset + 2] ];
  56. #ifdef DEBUG_SILHOUETTE
  57. glBegin( GL_LINES );
  58. glVertex3f( face_vertices[j]->point.x, face_vertices[j]->point.y, face_vertices[j]->point.z );
  59. glVertex3f( face_vertices[(j+1)%3]->point.x, face_vertices[(j+1)%3]->point.y, face_vertices[(j+1)%3]->point.z );
  60. glEnd();
  61. #endif
  62. unsigned int vertex_offset = extrude_quad_count*4;
  63. _extrudeVertexBuffer[vertex_offset] = face_vertices[j]->point;
  64. _extrudeVertexBuffer[vertex_offset+1] = face_vertices[(j+1)%3]->point;
  65. _extrudeVertexBuffer[vertex_offset+2] = face_vertices[(j+1)%3]->point + extrude_vector;
  66. _extrudeVertexBuffer[vertex_offset+3] = face_vertices[j]->point
  67. + extrude_vector;
  68. unsigned int index_offset = extrude_quad_count*6;
  69. _extrudeIndexBuffer[index_offset] = vertex_offset;
  70. _extrudeIndexBuffer[index_offset+1] = vertex_offset + 3;
  71. _extrudeIndexBuffer[index_offset+2] = vertex_offset + 1;
  72. _extrudeIndexBuffer[index_offset+3] = vertex_offset + 1;
  73. _extrudeIndexBuffer[index_offset+4] = vertex_offset + 3;
  74. _extrudeIndexBuffer[index_offset+5] = vertex_offset + 2;
  75. extrude_quad_count++;
  76. }
  77. }
  78. }
  79. }
  80. if (_capIndexBuffer.count() < mesh->index_buffer.count() )
  81. _capIndexBuffer.create(mesh->index_buffer.count() );
  82. bf = 0;
  83. ff = 0;
  84. for (i=0; i<shadow_faces.count(); i++)
  85. {
  86. unsigned int dst_offset, src_offset = i*3;
  87. if (shadow_faces[i].backFace == false)
  88. {
  89. dst_offset = ff*3;
  90. ff++;
  91. }
  92. else
  93. {
  94. dst_offset = _capIndexBuffer.count() - (bf + 1)*3;
  95. bf++;
  96. }
  97. _capIndexBuffer[dst_offset] = mesh->index_buffer[src_offset];
  98. _capIndexBuffer[dst_offset+1] = mesh->index_buffer[src_offset+1];
  99. _capIndexBuffer[dst_offset+2] = mesh->index_buffer[src_offset+2];
  100. }
  101. _lastOrientation = _AbsoluteRotation;
  102. }
  103. if (_extrudeVertexBuffer.count() > 0)
  104. {
  105. // draw the volume
  106. glPushAttrib( GL_ALL_ATTRIB_BITS);
  107. glDisable(GL_TEXTURE_2D);
  108. glDisable(GL_LIGHTING);
  109. glEnable( GL_DEPTH_TEST);
  110. glDepthMask(GL_FALSE);
  111. #if defined(DEBUG_SILHOUETTE) || defined(DEBUG_CAPS) || defined(DEBUG_VOLUME)
  112. glColorMask( 1, 1, 1, 1 );
  113. glDepthFunc(GL_LEQUAL);
  114. #else
  115. glColorMask(0, 0, 0, 0);
  116. glDepthFunc(GL_LESS);
  117. #endif
  118. glEnable(GL_STENCIL_TEST);
  119. glStencilFunc(GL_ALWAYS, 0, ~0);
  120. glStencilMask( ~0);
  121. glEnable(GL_CULL_FACE);
  122. glMatrixMode ( GL_MODELVIEW);
  123. glPushMatrix();
  124. Matrix4x4 m(_AbsoluteRotation, _AbsoluteTranslation);
  125. glMultMatrixd ( ( GLdouble * ) &m.m );
  126. glActiveTextureARB ( GL_TEXTURE2_ARB);
  127. glDisable ( GL_TEXTURE_2D);
  128. glActiveTextureARB ( GL_TEXTURE1_ARB);
  129. glDisable ( GL_TEXTURE_2D);
  130. glActiveTextureARB ( GL_TEXTURE0_ARB);
  131. glDisable ( GL_TEXTURE_2D);
  132. ShaderManager::getSingleton()->useShaderProgram( 0);
  133. #ifndef DEBUG_SILHOUETTE
  134. glEnableClientState( GL_VERTEX_ARRAY);
  135. glDisableClientState( GL_TEXTURE_COORD_ARRAY);
  136. glDisableClientState( GL_NORMAL_ARRAY);
  137. glDisableClientState( GL_ARRAY_BUFFER_ARB);
  138. glDisableClientState( GL_ELEMENT_ARRAY_BUFFER_ARB);
  139. for (int p=0; p<2; p++)
  140. {
  141. if (p==0)
  142. {
  143. glStencilOp(GL_KEEP, GL_INCR, GL_KEEP);
  144. glCullFace(GL_FRONT);
  145. //glColorMask(0, 1, 0, 0);
  146. }
  147. else
  148. {
  149. glStencilOp(GL_KEEP, GL_DECR, GL_KEEP);
  150. glCullFace(GL_BACK);
  151. //glColorMask(1, 0, 0, 0);
  152. }
  153. if (GLEW_ARB_vertex_buffer_object )
  154. {
  155. glBindBufferARB ( GL_ARRAY_BUFFER_ARB, 0);
  156. glBindBufferARB ( GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
  157. }
  158. // #if !defined(DEBUG_CAPS) || defined(DEBUG_VOLUME)
  159. glVertexPointer ( 3, GL_FLOAT, 0, _extrudeVertexBuffer.data() );
  160. glDrawElements (
  161. GL_TRIANGLES,
  162. extrude_quad_count * 6,
  163. GL_UNSIGNED_SHORT,
  164. _extrudeIndexBuffer.data());
  165. // #endif
  166. // #if !defined(DEBUG_VOLUME) || defined(DEBUG_CAPS)
  167. // draw caps
  168. mesh->vertex_buffer.bind();
  169. //glVertexPointer ( 3, GL_FLOAT, sizeof(Vertex), mesh->vertex_buffer.data() );
  170. glDrawElements (
  171. GL_TRIANGLES,
  172. ff*3,
  173. GL_UNSIGNED_SHORT,
  174. _capIndexBuffer.data());
  175. //&_capIndexBuffer[_capIndexBuffer.count() - bf*3]);
  176. glPushMatrix();
  177. glTranslatef(extrude_vector.x, extrude_vector.y, extrude_vector.z);
  178. glDrawElements (
  179. GL_TRIANGLES,
  180. bf*3,
  181. GL_UNSIGNED_SHORT,
  182. &_capIndexBuffer[_capIndexBuffer.count() - bf*3]);
  183. //_capIndexBuffer.data() );
  184. glPopMatrix();
  185. // #endif
  186. }
  187. #endif
  188. glPopAttrib();
  189. glPopMatrix();
  190. }
  191. */
  192. Scalar fW, fH;
  193. fH = tan ( (_FoV / 2) / 180* Pi ) * _NearPlane;
  194. fW = fH * _AspectRatio;
  195. // setup projectiom matrix
  196. glMatrixMode (GL_PROJECTION );
  197. glLoadIdentity();
  198. glFrustum ( -fW, fW, -fH, fH, _NearPlane, _FarPlane );
  199. // save variables for frustum culling
  200. /*
  201. _near = nearZ;
  202. _far = farZ;
  203. _hNear = tan ( ( fov / 2 ) / 180 * Pi ) * nearZ;
  204. _wNear = _hNear * aspect;
  205. _hFar = tan ( ( fov / 2 ) / 180 * Pi ) * farZ;
  206. _wFar = _hFar * aspect;
  207. */
  208. }
  209. #endif