2 // "$Id: gl_overlay.cxx 8033 2010-12-15 12:11:16Z AlbrechtS $"
4 // OpenGL overlay test program for the Fast Light Tool Kit (FLTK).
6 // Copyright 1998-2010 by Bill Spitzak and others.
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.
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.
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
23 // Please report all bugs and problems on the following page:
25 // http://www.fltk.org/str.php
30 #include <FL/Fl_Window.H>
31 #include <FL/Fl_Hor_Slider.H>
32 #include <FL/Fl_Toggle_Button.H>
36 #include <FL/Fl_Box.H>
37 class shape_window
: public Fl_Box
{
40 shape_window(int x
,int y
,int w
,int h
,const char *l
=0)
41 :Fl_Box(FL_DOWN_BOX
,x
,y
,w
,h
,l
){
42 label("This demo does\nnot work without GL");
47 #include <FL/Fl_Gl_Window.H>
49 class shape_window
: public Fl_Gl_Window
{
55 shape_window(int x
,int y
,int w
,int h
,const char *l
=0);
58 shape_window::shape_window(int x
,int y
,int w
,int h
,const char *l
) :
59 Fl_Gl_Window(x
,y
,w
,h
,l
) {
60 sides
= overlay_sides
= 3;
63 void shape_window::draw() {
64 // the valid() property may be used to avoid reinitializing your
65 // GL transformation for each redraw:
69 glViewport(0,0,w(),h());
71 // draw an amazing but slow graphic:
72 glClear(GL_COLOR_BUFFER_BIT
);
73 // for (int j=1; j<=1000; j++) {
75 for (int j
=0; j
<sides
; j
++) {
76 double ang
= j
*2*M_PI
/sides
;
77 glColor3f(float(j
)/sides
,float(j
)/sides
,float(j
)/sides
);
78 glVertex3f(cos(ang
),sin(ang
),0);
84 void shape_window::draw_overlay() {
85 // the valid() property may be used to avoid reinitializing your
86 // GL transformation for each redraw:
90 glViewport(0,0,w(),h());
92 // draw an amazing graphic:
94 glBegin(GL_LINE_LOOP
);
95 for (int j
=0; j
<overlay_sides
; j
++) {
96 double ang
= j
*2*M_PI
/overlay_sides
;
97 glVertex3f(cos(ang
),sin(ang
),0);
103 // when you change the data, as in this callback, you must call redraw():
104 void sides_cb(Fl_Widget
*o
, void *p
) {
105 shape_window
*sw
= (shape_window
*)p
;
106 sw
->sides
= int(((Fl_Slider
*)o
)->value());
111 void overlay_sides_cb(Fl_Widget
*o
, void *p
) {
112 shape_window
*sw
= (shape_window
*)p
;
113 sw
->overlay_sides
= int(((Fl_Slider
*)o
)->value());
114 sw
->redraw_overlay();
118 int main(int argc
, char **argv
) {
120 Fl_Window
window(300, 370);
122 shape_window
sw(10, 75, window
.w()-20, window
.h()-90);
124 window
.resizable(&sw
);
126 Fl_Hor_Slider
slider(60, 5, window
.w()-70, 30, "Sides:");
127 slider
.align(FL_ALIGN_LEFT
);
128 slider
.callback(sides_cb
,&sw
);
129 slider
.value(sw
.sides
);
133 Fl_Hor_Slider
oslider(60, 40, window
.w()-70, 30, "Overlay:");
134 oslider
.align(FL_ALIGN_LEFT
);
136 oslider
.callback(overlay_sides_cb
,&sw
);
137 oslider
.value(sw
.overlay_sides
);
140 oslider
.bounds(3,40);
143 window
.show(argc
,argv
);
145 printf("Can do overlay = %d\n", sw
.can_do_overlay());
156 // End of "$Id: gl_overlay.cxx 8033 2010-12-15 12:11:16Z AlbrechtS $".