diff options
Diffstat (limited to 'progs/beos/demo.cpp')
-rw-r--r-- | progs/beos/demo.cpp | 138 |
1 files changed, 66 insertions, 72 deletions
diff --git a/progs/beos/demo.cpp b/progs/beos/demo.cpp index c25eb93075c..6b0b9576d66 100644 --- a/progs/beos/demo.cpp +++ b/progs/beos/demo.cpp @@ -1,7 +1,8 @@ -// $Id: demo.cpp,v 1.1 1999/08/19 00:55:40 jtg Exp $ +// $Id: demo.cpp,v 1.2 2004/08/14 09:59:16 phoudoin Exp $ // Simple BeOS GLView demo // Written by Brian Paul +// Changes by Philippe Houdoin // This file is in the public domain. @@ -11,19 +12,40 @@ #include <Window.h> #include <GLView.h> +class MyGL : public BGLView +{ +public: + MyGL(BRect rect, char *name, ulong options); + + virtual void AttachedToWindow(); + virtual void Pulse(); + virtual void FrameResized(float w, float h); + +private: + void Render(); + void Reshape(float w, float h); + float mAngle; +}; + class MyWindow : public BWindow { public: - MyWindow(BRect frame); - virtual bool QuitRequested(); + MyWindow(BRect frame); + virtual bool QuitRequested(); }; MyWindow::MyWindow(BRect frame) : BWindow(frame, "demo", B_TITLED_WINDOW, B_NOT_ZOOMABLE) { - // no-op + // Make OpenGL view and put it in the window + BRect r = Bounds(); + r.InsetBy(5, 5); + + MyGL *gl = new MyGL(r, "GL", BGL_RGB | BGL_DOUBLE); + AddChild(gl); + SetPulseRate(1000000 / 30); } bool MyWindow::QuitRequested() @@ -33,119 +55,91 @@ bool MyWindow::QuitRequested() } -class MyGL : public BGLView -{ -public: - MyGL(BRect rect, char *name, ulong options); - -// virtual void AttachedToWindow(); - virtual void Draw(BRect updateRect); - virtual void Pulse(); - virtual void FrameResized(float w, float h); -private: - float mAngle; -}; - MyGL::MyGL(BRect rect, char *name, ulong options) - : BGLView(rect, name, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP_BOTTOM, 0, options) + : BGLView(rect, name, B_FOLLOW_ALL_SIDES, B_PULSE_NEEDED, options) { - mAngle = 0.0; + mAngle = 0.0; } -#if 0 void MyGL::AttachedToWindow() { - BGLView::AttachedToWindow(); - LockGL(); - glClearColor(.7, .7, 0, 0); - UnlockGL(); + BGLView::AttachedToWindow(); + + LockGL(); + glClearColor(0.7, 0.7, 0, 0); + Reshape(Bounds().Width(), Bounds().Height()); + UnlockGL(); } -#endif void MyGL::FrameResized(float w, float h) { - BGLView::FrameResized(w, h); + BGLView::FrameResized(w, h); - printf("FrameResized\n"); - LockGL(); - BGLView::FrameResized(w,h); - glViewport(0, 0, (int) (w + 1), (int) (h + 1)); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glFrustum(-1, 1, -1, 1, 10, 30); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glTranslatef(0, 0, -18); - UnlockGL(); + LockGL(); + Reshape(w, h); + UnlockGL(); + + Render(); } +void MyGL::Pulse() +{ + mAngle += 1.0; + Render(); +} + -void MyGL::Draw(BRect r) +void MyGL::Render() { - printf("MyGL::Draw\n"); - BGLView::Draw(r); LockGL(); + glClear(GL_COLOR_BUFFER_BIT); + glPushMatrix(); - glRotatef(mAngle, 0, 0, 1); + + glRotated(mAngle, 0, 0, 1); glColor3f(0, 0, 1); + glBegin(GL_POLYGON); glVertex2f(-1, -1); glVertex2f( 1, -1); glVertex2f( 1, 1); glVertex2f(-1, 1); glEnd(); + + glPopMatrix(); + SwapBuffers(); + UnlockGL(); } -void MyGL::Pulse() +void MyGL::Reshape(float w, float h) { - printf("pulse\n"); - BGLView::Pulse(); - mAngle += 1.0; - - LockGL(); - glClear(GL_COLOR_BUFFER_BIT); - glPushMatrix(); - glRotatef(mAngle, 0, 0, 1); - glColor3f(0, 0, 1); - glBegin(GL_POLYGON); - glVertex2f(-1, -1); - glVertex2f( 1, -1); - glVertex2f( 1, 1); - glVertex2f(-1, 1); - glEnd(); - SwapBuffers(); - UnlockGL(); + glViewport(0, 0, (int) (w + 1), (int) (h + 1)); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-1, 1, -1, 1, 10, 30); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0, 0, -18); } - int main(int argc, char *argv[]) { BApplication *app = new BApplication("application/demo"); // make top-level window - int x = 500, y = 500; - int w = 400, h = 400; - MyWindow *win = new MyWindow(BRect(x, y, x + w, y + h)); - // win->Lock(); - // win->Unlock(); + MyWindow *win = new MyWindow(BRect(100, 100, 500, 500)); win->Show(); - // Make OpenGL view and put it in the window - MyGL *gl = new MyGL(BRect(5, 5, w-10, h-10), "GL", BGL_RGB | BGL_DOUBLE); - // MyGL *gl = new MyGL(BRect(5, 5, w-10, h-10), "GL", BGL_RGB ); - win->AddChild(gl); - - printf("calling app->Run\n"); - app->Run(); + app->Run(); delete app; |