2 // "$Id: shape.cxx 8033 2010-12-15 12:11:16Z AlbrechtS $"
4 // Tiny OpenGL demo 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>
37 #include <FL/Fl_Gl_Window.H>
39 class shape_window
: public Fl_Gl_Window
{
43 shape_window(int x
,int y
,int w
,int h
,const char *l
=0);
46 shape_window::shape_window(int x
,int y
,int w
,int h
,const char *l
) :
47 Fl_Gl_Window(x
,y
,w
,h
,l
) {
51 void shape_window::draw() {
52 // the valid() property may be used to avoid reinitializing your
53 // GL transformation for each redraw:
57 glViewport(0, 0, w(), h());
59 // draw an amazing graphic:
60 glClear(GL_COLOR_BUFFER_BIT
);
63 for (int j
=0; j
<sides
; j
++) {
64 double ang
= j
*2*M_PI
/sides
;
65 glVertex3f(cos(ang
),sin(ang
),0);
72 #include <FL/Fl_Box.H>
73 class shape_window
: public Fl_Box
{
76 shape_window(int x
,int y
,int w
,int h
,const char *l
=0)
77 :Fl_Box(FL_DOWN_BOX
,x
,y
,w
,h
,l
){
78 label("This demo does\nnot work without GL");
84 // when you change the data, as in this callback, you must call redraw():
85 void sides_cb(Fl_Widget
*o
, void *p
) {
86 shape_window
*sw
= (shape_window
*)p
;
87 sw
->sides
= int(((Fl_Slider
*)o
)->value());
91 int main(int argc
, char **argv
) {
93 Fl_Window
window(300, 330);
95 // the shape window could be it's own window, but here we make it
97 shape_window
sw(10, 10, 280, 280);
99 window
.resizable(&sw
);
100 // window.size_range(300,330,0,0,1,1,1);
101 // add a knob to control it:
102 Fl_Hor_Slider
slider(50, 295, window
.w()-60, 30, "Sides:");
103 slider
.align(FL_ALIGN_LEFT
);
104 slider
.callback(sides_cb
,&sw
);
105 slider
.value(sw
.sides
);
110 window
.show(argc
,argv
);
116 // End of "$Id: shape.cxx 8033 2010-12-15 12:11:16Z AlbrechtS $".