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.

126 lines
3.0KB

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