Use cairo to draw everything.
[ntk.git] / test / gl_overlay.cxx
blob30e38357551b96308cac9dbc60a29ca05b60c1fe
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.
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
21 // USA.
23 // Please report all bugs and problems on the following page:
25 // http://www.fltk.org/str.php
28 #include <config.h>
29 #include <FL/Fl.H>
30 #include <FL/Fl_Window.H>
31 #include <FL/Fl_Hor_Slider.H>
32 #include <FL/Fl_Toggle_Button.H>
33 #include <FL/math.h>
35 #if !HAVE_GL
36 #include <FL/Fl_Box.H>
37 class shape_window : public Fl_Box {
38 public:
39 int sides;
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");
45 #else
46 #include <FL/gl.h>
47 #include <FL/Fl_Gl_Window.H>
49 class shape_window : public Fl_Gl_Window {
50 void draw();
51 void draw_overlay();
52 public:
53 int sides;
54 int overlay_sides;
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:
66 if (!valid()) {
67 valid(1);
68 glLoadIdentity();
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++) {
74 glBegin(GL_POLYGON);
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);
80 glEnd();
81 // }
84 void shape_window::draw_overlay() {
85 // the valid() property may be used to avoid reinitializing your
86 // GL transformation for each redraw:
87 if (!valid()) {
88 valid(1);
89 glLoadIdentity();
90 glViewport(0,0,w(),h());
92 // draw an amazing graphic:
93 gl_color(FL_RED);
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);
99 glEnd();
101 #endif
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());
107 sw->redraw();
110 #if HAVE_GL
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();
116 #endif
117 #include <stdio.h>
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);
123 //sw.mode(FL_RGB);
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);
130 slider.step(1);
131 slider.bounds(3,40);
133 Fl_Hor_Slider oslider(60, 40, window.w()-70, 30, "Overlay:");
134 oslider.align(FL_ALIGN_LEFT);
135 #if HAVE_GL
136 oslider.callback(overlay_sides_cb,&sw);
137 oslider.value(sw.overlay_sides);
138 #endif
139 oslider.step(1);
140 oslider.bounds(3,40);
142 window.end();
143 window.show(argc,argv);
144 #if HAVE_GL
145 printf("Can do overlay = %d\n", sw.can_do_overlay());
146 sw.show();
147 sw.redraw_overlay();
148 #else
149 sw.show();
150 #endif
152 return Fl::run();
156 // End of "$Id: gl_overlay.cxx 8033 2010-12-15 12:11:16Z AlbrechtS $".