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.
 
 
 

260 lines
6.6 KiB

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