chmod a-x **/glslnoise.c
[mesa-demos.git] / src / beos / sample.cpp
bloba86a118747f22a6c722ea12b77a209260e1da82a
1 // sample BGLView app from the Be Book
4 #include <stdio.h>
5 #include <Application.h>
6 #include <Window.h>
7 #include <GLView.h>
10 class SampleGLView : public BGLView
12 public:
13 SampleGLView(BRect frame, uint32 type);
14 virtual void AttachedToWindow(void);
15 virtual void FrameResized(float newWidth, float newHeight);
16 virtual void ErrorCallback(GLenum which);
18 void Render(void);
20 private:
21 void gInit(void);
22 void gDraw(void);
23 void gReshape(int width, int height);
25 float width;
26 float height;
31 class SampleGLWindow : public BWindow
33 public:
34 SampleGLWindow(BRect frame, uint32 type);
35 virtual bool QuitRequested() { be_app->PostMessage(B_QUIT_REQUESTED); return true; }
37 private:
38 SampleGLView *theView;
42 class SampleGLApp : public BApplication
44 public:
45 SampleGLApp();
46 private:
47 SampleGLWindow *theWindow;
51 SampleGLApp::SampleGLApp()
52 : BApplication("application/x-vnd.sample")
54 BRect windowRect;
55 uint32 type = BGL_RGB|BGL_DOUBLE;
57 windowRect.Set(50, 50, 350, 350);
59 theWindow = new SampleGLWindow(windowRect, type);
64 SampleGLWindow::SampleGLWindow(BRect frame, uint32 type)
65 : BWindow(frame, "OpenGL Test", B_TITLED_WINDOW, 0)
67 theView = new SampleGLView(Bounds(), type);
68 AddChild(theView);
69 Show();
70 theView->Render();
75 SampleGLView::SampleGLView(BRect frame, uint32 type)
76 : BGLView(frame, "SampleGLView", B_FOLLOW_ALL_SIDES, 0, type)
78 width = frame.right-frame.left;
79 height = frame.bottom-frame.top;
83 void SampleGLView::AttachedToWindow(void)
85 LockGL();
86 BGLView::AttachedToWindow();
87 gInit();
88 gReshape(width, height);
89 UnlockGL();
93 void SampleGLView::FrameResized(float newWidth, float newHeight)
95 BGLView::FrameResized(newWidth, newHeight);
97 LockGL();
99 width = newWidth;
100 height = newHeight;
102 gReshape(width,height);
104 UnlockGL();
105 Render();
109 void SampleGLView::ErrorCallback(GLenum whichError)
111 // fprintf(stderr, "Unexpected error occured (%d):\\n", whichError);
112 // fprintf(stderr, " %s\\n", gluErrorString(whichError));
117 // globals
118 GLenum use_stipple_mode; // GL_TRUE to use dashed lines
119 GLenum use_smooth_mode; // GL_TRUE to use anti-aliased lines
120 GLint linesize; // Line width
121 GLint pointsize; // Point diameter
123 float pntA[3] = {
124 -160.0, 0.0, 0.0
126 float pntB[3] = {
127 -130.0, 0.0, 0.0
132 void SampleGLView::gInit(void)
134 glClearColor(0.0, 0.0, 0.0, 0.0);
135 glLineStipple(1, 0xF0E0);
136 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
137 use_stipple_mode = GL_FALSE;
138 use_smooth_mode = GL_TRUE;
139 linesize = 2;
140 pointsize = 6;
145 void SampleGLView::gDraw(void)
147 GLint i;
149 glClear(GL_COLOR_BUFFER_BIT);
150 glLineWidth(linesize);
154 if (use_stipple_mode) {
155 glEnable(GL_LINE_STIPPLE);
156 } else {
157 glDisable(GL_LINE_STIPPLE);
161 glDisable(GL_POINT_SMOOTH);
164 glPushMatrix();
166 glPointSize(pointsize); // Set size for point
168 for (i = 0; i < 360; i += 5) {
169 glRotatef(5.0, 0,0,1); // Rotate right 5 degrees
171 if (use_smooth_mode) {
172 glEnable(GL_LINE_SMOOTH);
173 glEnable(GL_BLEND);
174 } else {
175 glDisable(GL_LINE_SMOOTH);
176 glDisable(GL_BLEND);
179 glColor3f(1.0, 1.0, 0.0); // Set color for line
180 glBegin(GL_LINE_STRIP); // And create the line
181 glVertex3fv(pntA);
182 glVertex3fv(pntB);
183 glEnd();
185 glDisable(GL_POINT_SMOOTH);
186 glDisable(GL_BLEND);
188 glColor3f(0.0, 1.0, 0.0); // Set color for point
189 glBegin(GL_POINTS);
190 glVertex3fv(pntA); // Draw point at one end
191 glVertex3fv(pntB); // Draw point at other end
192 glEnd();
195 glPopMatrix(); // Done with matrix
199 void SampleGLView::gReshape(int width, int height)
201 glViewport(0, 0, width, height);
202 glMatrixMode(GL_PROJECTION);
203 glLoadIdentity();
204 glOrtho(-175, 175, -175, 175, -1, 1);
205 glMatrixMode(GL_MODELVIEW);
209 void SampleGLView::Render(void)
211 LockGL();
212 gDraw();
213 SwapBuffers();
214 UnlockGL();
219 int main(int argc, char *argv[])
221 SampleGLApp *app = new SampleGLApp;
222 app->Run();
223 delete app;
224 return 0;