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.

158 lines
4.0KB

  1. //
  2. // "$Id: gl_overlay.cxx 8033 2010-12-15 12:11:16Z AlbrechtS $"
  3. //
  4. // OpenGL overlay test 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/Fl_Toggle_Button.H>
  32. #include <FL/math.h>
  33. #if !HAVE_GL
  34. #include <FL/Fl_Box.H>
  35. class shape_window : public Fl_Box {
  36. public:
  37. int sides;
  38. shape_window(int x,int y,int w,int h,const char *l=0)
  39. :Fl_Box(FL_DOWN_BOX,x,y,w,h,l){
  40. label("This demo does\nnot work without GL");
  41. }
  42. };
  43. #else
  44. #include <FL/gl.h>
  45. #include <FL/Fl_Gl_Window.H>
  46. class shape_window : public Fl_Gl_Window {
  47. void draw();
  48. void draw_overlay();
  49. public:
  50. int sides;
  51. int overlay_sides;
  52. shape_window(int x,int y,int w,int h,const char *l=0);
  53. };
  54. shape_window::shape_window(int x,int y,int w,int h,const char *l) :
  55. Fl_Gl_Window(x,y,w,h,l) {
  56. sides = overlay_sides = 3;
  57. }
  58. void shape_window::draw() {
  59. // the valid() property may be used to avoid reinitializing your
  60. // GL transformation for each redraw:
  61. if (!valid()) {
  62. valid(1);
  63. glLoadIdentity();
  64. glViewport(0,0,w(),h());
  65. }
  66. // draw an amazing but slow graphic:
  67. glClear(GL_COLOR_BUFFER_BIT);
  68. // for (int j=1; j<=1000; j++) {
  69. glBegin(GL_POLYGON);
  70. for (int j=0; j<sides; j++) {
  71. double ang = j*2*M_PI/sides;
  72. glColor3f(float(j)/sides,float(j)/sides,float(j)/sides);
  73. glVertex3f(cos(ang),sin(ang),0);
  74. }
  75. glEnd();
  76. // }
  77. }
  78. void shape_window::draw_overlay() {
  79. // the valid() property may be used to avoid reinitializing your
  80. // GL transformation for each redraw:
  81. if (!valid()) {
  82. valid(1);
  83. glLoadIdentity();
  84. glViewport(0,0,w(),h());
  85. }
  86. // draw an amazing graphic:
  87. gl_color(FL_RED);
  88. glBegin(GL_LINE_LOOP);
  89. for (int j=0; j<overlay_sides; j++) {
  90. double ang = j*2*M_PI/overlay_sides;
  91. glVertex3f(cos(ang),sin(ang),0);
  92. }
  93. glEnd();
  94. }
  95. #endif
  96. // when you change the data, as in this callback, you must call redraw():
  97. void sides_cb(Fl_Widget *o, void *p) {
  98. shape_window *sw = (shape_window *)p;
  99. sw->sides = int(((Fl_Slider *)o)->value());
  100. sw->redraw();
  101. }
  102. #if HAVE_GL
  103. void overlay_sides_cb(Fl_Widget *o, void *p) {
  104. shape_window *sw = (shape_window *)p;
  105. sw->overlay_sides = int(((Fl_Slider *)o)->value());
  106. sw->redraw_overlay();
  107. }
  108. #endif
  109. #include <stdio.h>
  110. int main(int argc, char **argv) {
  111. Fl_Window window(300, 370);
  112. shape_window sw(10, 75, window.w()-20, window.h()-90);
  113. //sw.mode(FL_RGB);
  114. window.resizable(&sw);
  115. Fl_Hor_Slider slider(60, 5, window.w()-70, 30, "Sides:");
  116. slider.align(FL_ALIGN_LEFT);
  117. slider.callback(sides_cb,&sw);
  118. slider.value(sw.sides);
  119. slider.step(1);
  120. slider.bounds(3,40);
  121. Fl_Hor_Slider oslider(60, 40, window.w()-70, 30, "Overlay:");
  122. oslider.align(FL_ALIGN_LEFT);
  123. #if HAVE_GL
  124. oslider.callback(overlay_sides_cb,&sw);
  125. oslider.value(sw.overlay_sides);
  126. #endif
  127. oslider.step(1);
  128. oslider.bounds(3,40);
  129. window.end();
  130. window.show(argc,argv);
  131. #if HAVE_GL
  132. printf("Can do overlay = %d\n", sw.can_do_overlay());
  133. sw.show();
  134. sw.redraw_overlay();
  135. #else
  136. sw.show();
  137. #endif
  138. return Fl::run();
  139. }
  140. //
  141. // End of "$Id: gl_overlay.cxx 8033 2010-12-15 12:11:16Z AlbrechtS $".
  142. //