SimpleOpenGL2Renderer.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. #include "SimpleOpenGL2Renderer.h"
  2. #include "OpenGL2Include.h"
  3. #include "Bullet3Common/b3Vector3.h"
  4. SimpleOpenGL2Renderer::SimpleOpenGL2Renderer(int width, int height)
  5. :m_width(width),
  6. m_height(height)
  7. {
  8. }
  9. void SimpleOpenGL2Renderer::init()
  10. {
  11. }
  12. const CommonCameraInterface* SimpleOpenGL2Renderer::getActiveCamera() const
  13. {
  14. return &m_camera;
  15. }
  16. CommonCameraInterface* SimpleOpenGL2Renderer::getActiveCamera()
  17. {
  18. return &m_camera;
  19. }
  20. void SimpleOpenGL2Renderer::setActiveCamera(CommonCameraInterface* cam)
  21. {
  22. b3Assert(0);//not supported yet
  23. }
  24. void SimpleOpenGL2Renderer::updateCamera(int upAxis)
  25. {
  26. float projection[16];
  27. float view[16];
  28. m_camera.setAspectRatio((float)m_width/(float)m_height);
  29. m_camera.update();
  30. m_camera.getCameraProjectionMatrix(projection);
  31. m_camera.getCameraViewMatrix(view);
  32. GLfloat projMat[16];
  33. GLfloat viewMat[16];
  34. for (int i=0;i<16;i++)
  35. {
  36. viewMat[i] = view[i];
  37. projMat[i] = projection[i];
  38. }
  39. glMatrixMode(GL_PROJECTION);
  40. glLoadIdentity();
  41. glMultMatrixf(projMat);
  42. glMatrixMode(GL_MODELVIEW);
  43. glLoadIdentity();
  44. glMultMatrixf(viewMat);
  45. }
  46. void SimpleOpenGL2Renderer::removeAllInstances()
  47. {
  48. }
  49. void SimpleOpenGL2Renderer::writeSingleInstanceColorToCPU(float* color, int srcIndex)
  50. {
  51. }
  52. void SimpleOpenGL2Renderer::writeSingleInstanceColorToCPU(double* color, int srcIndex)
  53. {
  54. }
  55. void SimpleOpenGL2Renderer::writeSingleInstanceScaleToCPU(float* scale, int srcIndex)
  56. {
  57. }
  58. void SimpleOpenGL2Renderer::writeSingleInstanceScaleToCPU(double* scale, int srcIndex)
  59. {
  60. }
  61. int SimpleOpenGL2Renderer::getTotalNumInstances() const
  62. {
  63. return 0;
  64. }
  65. void SimpleOpenGL2Renderer::getCameraViewMatrix(float viewMat[16]) const
  66. {
  67. b3Assert(0);
  68. }
  69. void SimpleOpenGL2Renderer::getCameraProjectionMatrix(float projMat[16]) const
  70. {
  71. b3Assert(0);
  72. }
  73. void SimpleOpenGL2Renderer::renderScene()
  74. {
  75. }
  76. int SimpleOpenGL2Renderer::registerGraphicsInstance(int shapeIndex, const double* position, const double* quaternion, const double* color, const double* scaling)
  77. {
  78. return 0;
  79. }
  80. int SimpleOpenGL2Renderer::registerGraphicsInstance(int shapeIndex, const float* position, const float* quaternion, const float* color, const float* scaling)
  81. {
  82. return 0;
  83. }
  84. void SimpleOpenGL2Renderer::drawLines(const float* positions, const float color[4], int numPoints, int pointStrideInBytes, const unsigned int* indices, int numIndices, float pointDrawSize)
  85. {
  86. int pointStrideInFloats = pointStrideInBytes/4;
  87. glLineWidth(pointDrawSize);
  88. for (int i=0;i<numIndices;i+=2)
  89. {
  90. int index0 = indices[i];
  91. int index1 = indices[i+1];
  92. b3Vector3 fromColor = b3MakeVector3(color[0],color[1],color[2]);
  93. b3Vector3 toColor = b3MakeVector3(color[0],color[1],color[2]);
  94. b3Vector3 from= b3MakeVector3(positions[index0*pointStrideInFloats],positions[index0*pointStrideInFloats+1],positions[index0*pointStrideInFloats+2]);
  95. b3Vector3 to= b3MakeVector3(positions[index1*pointStrideInFloats],positions[index1*pointStrideInFloats+1],positions[index1*pointStrideInFloats+2]);
  96. glBegin(GL_LINES);
  97. glColor3f(fromColor.getX(), fromColor.getY(), fromColor.getZ());
  98. glVertex3d(from.getX(), from.getY(), from.getZ());
  99. glColor3f(toColor.getX(), toColor.getY(), toColor.getZ());
  100. glVertex3d(to.getX(), to.getY(), to.getZ());
  101. glEnd();
  102. }
  103. }
  104. void SimpleOpenGL2Renderer::drawLine(const float from[4], const float to[4], const float color[4], float lineWidth)
  105. {
  106. glLineWidth(lineWidth);
  107. glBegin(GL_LINES);
  108. glColor3f(color[0],color[1],color[2]);
  109. glVertex3d(from[0],from[1],from[2]);
  110. glVertex3d(to[0],to[1],to[2]);
  111. glEnd();
  112. }
  113. int SimpleOpenGL2Renderer::registerShape(const float* vertices, int numvertices, const int* indices, int numIndices,int primitiveType, int textureIndex)
  114. {
  115. return 0;
  116. }
  117. void SimpleOpenGL2Renderer::writeSingleInstanceTransformToCPU(const float* position, const float* orientation, int srcIndex)
  118. {
  119. }
  120. void SimpleOpenGL2Renderer::writeSingleInstanceTransformToCPU(const double* position, const double* orientation, int srcIndex)
  121. {
  122. }
  123. void SimpleOpenGL2Renderer::writeTransforms()
  124. {
  125. }
  126. void SimpleOpenGL2Renderer::drawLine(const double from[4], const double to[4], const double color[4], double lineWidth)
  127. {
  128. }
  129. void SimpleOpenGL2Renderer::drawPoint(const float* position, const float color[4], float pointDrawSize)
  130. {
  131. }
  132. void SimpleOpenGL2Renderer::drawPoint(const double* position, const double color[4], double pointDrawSize)
  133. {
  134. }
  135. void SimpleOpenGL2Renderer::updateShape(int shapeIndex, const float* vertices)
  136. {
  137. }
  138. void SimpleOpenGL2Renderer::enableBlend(bool blend)
  139. {
  140. }
  141. void SimpleOpenGL2Renderer::clearZBuffer()
  142. {
  143. glClear(GL_DEPTH_BUFFER_BIT);
  144. }