Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

openglrenderdevice.cpp 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include "openglrenderdevice.h"
  2. #include "GL/gl.h"
  3. #include "GL/glu.h"
  4. OpenGLRenderDevice::OpenGLRenderDevice(QObject *parent) :
  5. AbstractRenderDevice(parent)
  6. {
  7. }
  8. void OpenGLRenderDevice::initialize(int fov, int width, int height)
  9. {
  10. glClearColor(_clearColor.redF(), _clearColor.greenF(),
  11. _clearColor.blue(), _clearColor.alpha());
  12. glEnable(GL_DEPTH_TEST);
  13. glEnable(GL_CULL_FACE);
  14. glShadeModel(GL_SMOOTH);
  15. glEnable(GL_MULTISAMPLE);
  16. glMatrixMode(GL_PROJECTION);
  17. gluPerspective(fov, width / height, 0.1, 100.0);
  18. glMatrixMode(GL_MODELVIEW);
  19. }
  20. void OpenGLRenderDevice::resize(int width, int height)
  21. {
  22. int side = qMin(width, height);
  23. glViewport((width - side) / 2, (height - side) / 2, side, side);
  24. }
  25. void OpenGLRenderDevice::preDraw()
  26. {
  27. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  28. glLoadIdentity();
  29. gluLookAt(_lookEye.getX(), _lookEye.getY(), _lookEye.getZ(),
  30. _lookCenter.getX(), _lookCenter.getY(), _lookCenter.getZ(),
  31. _lookUp.getX(), _lookUp.getY(), _lookUp.getZ());
  32. }
  33. void OpenGLRenderDevice::postDraw()
  34. {
  35. }
  36. void OpenGLRenderDevice::drawVertex(const ColorVector3D &point)
  37. {
  38. glColor4f(point.getColor().redF(), point.getColor().greenF(),
  39. point.getColor().blue(), point.getColor().alpha());
  40. glVertex3d(point.getX(), point.getY(), point.getZ());
  41. }
  42. void OpenGLRenderDevice::drawPoint(const ColorVector3D &point)
  43. {
  44. glBegin(GL_POINTS);
  45. drawVertex(point);
  46. glEnd();
  47. }
  48. void OpenGLRenderDevice::drawLine(const ColorVector3D &begin, const ColorVector3D &end, double width)
  49. {
  50. glLineWidth(width);
  51. glBegin(GL_LINES);
  52. drawVertex(begin);
  53. drawVertex(end);
  54. glEnd();
  55. }
  56. void OpenGLRenderDevice::drawPolygon(const QList<ColorVector3D> &points)
  57. {
  58. glBegin(GL_POLYGON);
  59. for (int i = 0; i < points.size(); ++i) {
  60. drawVertex(points[i]);
  61. }
  62. glEnd();
  63. }