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.

139 lines
3.3KB

  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. // ------------------------------------------------------
  17. // DGL Stuff
  18. #include "App.hpp"
  19. #include "Window.hpp"
  20. #include "Widget.hpp"
  21. #include <cmath>
  22. // ------------------------------------------------------
  23. // use namespace
  24. using namespace DGL;
  25. // ------------------------------------------------------
  26. // our widget
  27. class DummyWidget : public Widget
  28. {
  29. public:
  30. DummyWidget(Window& win)
  31. : Widget(win)
  32. {
  33. }
  34. protected:
  35. void onDisplay() override
  36. {
  37. #if 0
  38. glEnable(GL_MULTISAMPLE);
  39. glEnable(GL_LINE_SMOOTH);
  40. glEnable(GL_SRC_ALPHA);
  41. glEnable(GL_ONE_MINUS_SRC_ALPHA);
  42. glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
  43. glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
  44. #endif
  45. glLineWidth(1.0f);
  46. glColor3f(0.302f, 0.337f, 0.361f);
  47. bgFull.draw();
  48. glColor3f(0.235f, 0.271f, 0.294f);
  49. bgSmall.draw();
  50. glColor3f(0.176f, 0.212f, 0.235f);
  51. bgSmall.drawOutline();
  52. glColor3f(0.302f*2, 0.337f*2, 0.361f*2);
  53. tri.draw();
  54. glLineWidth(3.0f);
  55. glColor3f(0.302f/2.0f, 0.337f/2.0f, 0.361f/2.0f);
  56. tri.drawOutline();
  57. glColor3f(0.235f, 0.271f, 0.294f);
  58. cir.draw();
  59. glLineWidth(2.0f);
  60. glColor3f(0.176f/4, 0.212f/4, 0.235f/4);
  61. cir.drawOutline();
  62. }
  63. void onReshape(int width, int height) override
  64. {
  65. // full bg
  66. bgFull = Rectangle<int>(0, 0, width, height);
  67. // small bg
  68. bgSmall = Rectangle<int>(20, 10, width-40, height-20);
  69. // center triangle
  70. tri = Triangle<int>(width*0.5, height*0.1, width*0.1, height*0.9, width*0.9, height*0.9);
  71. // circle
  72. cir = Circle<int>(width/2, height*2/3, height/6, 300);
  73. // make widget same size as window
  74. setSize(width, height);
  75. // default reshape implementation
  76. Widget::onReshape(width, height);
  77. }
  78. private:
  79. Rectangle<int> bgFull, bgSmall;
  80. Triangle<int> tri;
  81. Circle<int> cir;
  82. };
  83. // ------------------------------------------------------
  84. // Our Demo Window
  85. class DemoWindow : public Window
  86. {
  87. public:
  88. DemoWindow(App& app)
  89. : Window(app),
  90. w1(*this)
  91. {
  92. setSize(300, 300);
  93. setTitle("DGL Demo");
  94. }
  95. private:
  96. DummyWidget w1;
  97. };
  98. // ------------------------------------------------------
  99. // main entry point
  100. int main()
  101. {
  102. App app;
  103. DemoWindow win(app);
  104. win.show();
  105. app.exec();
  106. return 0;
  107. }
  108. // ------------------------------------------------------