DPF OpenGL examples
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.

109 lines
2.9KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2015 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. * or without fee is hereby granted, provided that the above copyright notice and this
  7. * permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  10. * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  11. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  12. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  13. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #ifndef EXAMPLE_SHAPES_WIDGET_HPP_INCLUDED
  17. #define EXAMPLE_SHAPES_WIDGET_HPP_INCLUDED
  18. // ------------------------------------------------------
  19. // DGL Stuff
  20. #include "Widget.hpp"
  21. #include "Window.hpp"
  22. // ------------------------------------------------------
  23. // our widget
  24. class ExampleShapesWidget : public Widget
  25. {
  26. public:
  27. ExampleShapesWidget(Window& parent)
  28. : Widget(parent)
  29. {
  30. setSize(300, 300);
  31. }
  32. ExampleShapesWidget(Widget* groupWidget)
  33. : Widget(groupWidget)
  34. {
  35. setSize(300, 300);
  36. }
  37. protected:
  38. void onDisplay() override
  39. {
  40. #if 0
  41. glEnable(GL_MULTISAMPLE);
  42. glEnable(GL_LINE_SMOOTH);
  43. glEnable(GL_SRC_ALPHA);
  44. glEnable(GL_ONE_MINUS_SRC_ALPHA);
  45. glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
  46. glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
  47. #endif
  48. glLineWidth(1.0f);
  49. glColor3f(0.302f, 0.337f, 0.361f);
  50. bg.draw();
  51. glColor3f(0.235f, 0.271f, 0.294f);
  52. rect.draw();
  53. glColor3f(0.176f, 0.212f, 0.235f);
  54. rect.drawOutline();
  55. glColor3f(0.302f*2, 0.337f*2, 0.361f*2);
  56. tri.draw();
  57. glLineWidth(3.0f);
  58. glColor3f(0.302f/2.0f, 0.337f/2.0f, 0.361f/2.0f);
  59. tri.drawOutline();
  60. glColor3f(0.235f, 0.271f, 0.294f);
  61. cir.draw();
  62. glLineWidth(2.0f);
  63. glColor3f(0.176f/4, 0.212f/4, 0.235f/4);
  64. cir.drawOutline();
  65. }
  66. void onResize(const ResizeEvent& ev) override
  67. {
  68. const int width = ev.size.getWidth();
  69. const int height = ev.size.getHeight();
  70. // background
  71. bg = Rectangle<int>(0, 0, width, height);
  72. // rectangle
  73. rect = Rectangle<int>(20, 10, width-40, height-20);
  74. // center triangle
  75. tri = Triangle<int>(width*0.5, height*0.1, width*0.1, height*0.9, width*0.9, height*0.9);
  76. // circle
  77. cir = Circle<int>(width/2, height*2/3, height/6, 300);
  78. }
  79. private:
  80. Rectangle<int> bg;
  81. Rectangle<int> rect;
  82. Triangle<int> tri;
  83. Circle<int> cir;
  84. };
  85. // ------------------------------------------------------
  86. #endif // EXAMPLE_SHAPES_WIDGET_HPP_INCLUDED