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.

118 lines
3.1KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2014 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. // use namespace
  24. using DGL::Circle;
  25. using DGL::Triangle;
  26. using DGL::Rectangle;
  27. using DGL::Widget;
  28. using DGL::Window;
  29. // ------------------------------------------------------
  30. // our widget
  31. class ExampleShapesWidget : public Widget
  32. {
  33. public:
  34. ExampleShapesWidget(Window& parent)
  35. : Widget(parent)
  36. {
  37. setSize(300, 300);
  38. }
  39. ExampleShapesWidget(Widget* groupWidget)
  40. : Widget(groupWidget)
  41. {
  42. setSize(300, 300);
  43. }
  44. protected:
  45. void onDisplay() override
  46. {
  47. #if 0
  48. glEnable(GL_MULTISAMPLE);
  49. glEnable(GL_LINE_SMOOTH);
  50. glEnable(GL_SRC_ALPHA);
  51. glEnable(GL_ONE_MINUS_SRC_ALPHA);
  52. glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
  53. glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
  54. #endif
  55. glLineWidth(1.0f);
  56. glColor3f(0.302f, 0.337f, 0.361f);
  57. bg.draw();
  58. glColor3f(0.235f, 0.271f, 0.294f);
  59. rect.draw();
  60. glColor3f(0.176f, 0.212f, 0.235f);
  61. rect.drawOutline();
  62. glColor3f(0.302f*2, 0.337f*2, 0.361f*2);
  63. tri.draw();
  64. glLineWidth(3.0f);
  65. glColor3f(0.302f/2.0f, 0.337f/2.0f, 0.361f/2.0f);
  66. tri.drawOutline();
  67. glColor3f(0.235f, 0.271f, 0.294f);
  68. cir.draw();
  69. glLineWidth(2.0f);
  70. glColor3f(0.176f/4, 0.212f/4, 0.235f/4);
  71. cir.drawOutline();
  72. }
  73. void onResize(const ResizeEvent& ev) override
  74. {
  75. const int width = ev.size.getWidth();
  76. const int height = ev.size.getHeight();
  77. // background
  78. bg = Rectangle<int>(0, 0, width, height);
  79. // rectangle
  80. rect = Rectangle<int>(20, 10, width-40, height-20);
  81. // center triangle
  82. tri = Triangle<int>(width*0.5, height*0.1, width*0.1, height*0.9, width*0.9, height*0.9);
  83. // circle
  84. cir = Circle<int>(width/2, height*2/3, height/6, 300);
  85. }
  86. private:
  87. Rectangle<int> bg;
  88. Rectangle<int> rect;
  89. Triangle<int> tri;
  90. Circle<int> cir;
  91. };
  92. // ------------------------------------------------------
  93. #endif // EXAMPLE_SHAPES_WIDGET_HPP_INCLUDED