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
2.9KB

  1. //
  2. // "$Id: shape.cxx 8033 2010-12-15 12:11:16Z AlbrechtS $"
  3. //
  4. // Tiny OpenGL demo program for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-2010 by Bill Spitzak and others.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems on the following page:
  24. //
  25. // http://www.fltk.org/str.php
  26. //
  27. #include <config.h>
  28. #include <FL/Fl.H>
  29. #include <FL/Fl_Window.H>
  30. #include <FL/Fl_Hor_Slider.H>
  31. #include <FL/math.h>
  32. #if HAVE_GL
  33. #include <FL/gl.h>
  34. #include <FL/Fl_Gl_Window.H>
  35. class shape_window : public Fl_Gl_Window {
  36. void draw();
  37. public:
  38. int sides;
  39. shape_window(int x,int y,int w,int h,const char *l=0);
  40. };
  41. shape_window::shape_window(int x,int y,int w,int h,const char *l) :
  42. Fl_Gl_Window(x,y,w,h,l) {
  43. sides = 3;
  44. }
  45. void shape_window::draw() {
  46. // the valid() property may be used to avoid reinitializing your
  47. // GL transformation for each redraw:
  48. if (!valid()) {
  49. valid(1);
  50. glLoadIdentity();
  51. glViewport(0, 0, w(), h());
  52. }
  53. // draw an amazing graphic:
  54. glClear(GL_COLOR_BUFFER_BIT);
  55. glColor3f(.5,.6,.7);
  56. glBegin(GL_POLYGON);
  57. for (int j=0; j<sides; j++) {
  58. double ang = j*2*M_PI/sides;
  59. glVertex3f(cos(ang),sin(ang),0);
  60. }
  61. glEnd();
  62. }
  63. #else
  64. #include <FL/Fl_Box.H>
  65. class shape_window : public Fl_Box {
  66. public:
  67. int sides;
  68. shape_window(int x,int y,int w,int h,const char *l=0)
  69. :Fl_Box(FL_DOWN_BOX,x,y,w,h,l){
  70. label("This demo does\nnot work without GL");
  71. }
  72. };
  73. #endif
  74. // when you change the data, as in this callback, you must call redraw():
  75. void sides_cb(Fl_Widget *o, void *p) {
  76. shape_window *sw = (shape_window *)p;
  77. sw->sides = int(((Fl_Slider *)o)->value());
  78. sw->redraw();
  79. }
  80. int main(int argc, char **argv) {
  81. Fl_Window window(300, 330);
  82. // the shape window could be it's own window, but here we make it
  83. // a child window:
  84. shape_window sw(10, 10, 280, 280);
  85. // make it resize:
  86. window.resizable(&sw);
  87. // window.size_range(300,330,0,0,1,1,1);
  88. // add a knob to control it:
  89. Fl_Hor_Slider slider(50, 295, window.w()-60, 30, "Sides:");
  90. slider.align(FL_ALIGN_LEFT);
  91. slider.callback(sides_cb,&sw);
  92. slider.value(sw.sides);
  93. slider.step(1);
  94. slider.bounds(3,40);
  95. window.end();
  96. window.show(argc,argv);
  97. return Fl::run();
  98. }
  99. //
  100. // End of "$Id: shape.cxx 8033 2010-12-15 12:11:16Z AlbrechtS $".
  101. //