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.

112 lines
2.6KB

  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. glColor3f(0.302f, 0.337f, 0.361f);
  37. bgFull.draw();
  38. glColor3f(0.235f, 0.271f, 0.294f);
  39. bgSmall.draw();
  40. glColor3f(0.176f, 0.212f, 0.235f);
  41. bgSmall.drawOutline();
  42. glColor3f(0.302f*2, 0.337f*2, 0.361f*2);
  43. tri.draw();
  44. }
  45. void onReshape(int width, int height)
  46. {
  47. // full bg
  48. bgFull = DGL::Rectangle<int>(0, 0, width, height);
  49. // small bg
  50. bgSmall = DGL::Rectangle<int>(20, 10, width-40, height-20);
  51. // center triangle
  52. tri = Triangle<int>(width*0.5, height*0.1, width*0.1, height*0.9, width*0.9, height*0.9);
  53. // make widget same size as window
  54. setSize(width, height);
  55. // default reshape implementation
  56. Widget::onReshape(width, height);
  57. }
  58. private:
  59. Rectangle<int> bgFull, bgSmall;
  60. Triangle<int> tri;
  61. };
  62. // ------------------------------------------------------
  63. // Our Demo Window
  64. class DemoWindow : public Window
  65. {
  66. public:
  67. DemoWindow(App& app)
  68. : Window(app),
  69. w1(*this)
  70. {
  71. setSize(300, 300);
  72. setTitle("DGL Demo");
  73. }
  74. private:
  75. DummyWidget w1;
  76. };
  77. // ------------------------------------------------------
  78. // main entry point
  79. int main()
  80. {
  81. App app;
  82. DemoWindow win(app);
  83. win.show();
  84. app.exec();
  85. return 0;
  86. }
  87. // ------------------------------------------------------