From afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1c Mon Sep 17 00:00:00 2001 From: jtg Date: Thu, 19 Aug 1999 00:55:39 +0000 Subject: Initial revision --- progs/beos/Makefile | 42 ++++++++++ progs/beos/demo.cpp | 153 ++++++++++++++++++++++++++++++++++++ progs/beos/sample.cpp | 212 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 407 insertions(+) create mode 100644 progs/beos/Makefile create mode 100644 progs/beos/demo.cpp create mode 100644 progs/beos/sample.cpp (limited to 'progs/beos') diff --git a/progs/beos/Makefile b/progs/beos/Makefile new file mode 100644 index 0000000000..0d9c27b539 --- /dev/null +++ b/progs/beos/Makefile @@ -0,0 +1,42 @@ +# $Id: Makefile,v 1.1 1999/08/19 00:55:40 jtg Exp $ + +# Makefile for BeOS demos + +# Written by Brian Paul +# This file is in the public domain. + + + +CC = g++ + +# Use Mesa: +CFLAGS = -I../include -c -g +LFLAGS = -L../lib -Xlinker -rpath ../lib -lbe -lMesaGL + +# Use BeOS OpenGL: +#CFLAGS = -I/boot/develop/headers/be/opengl -c -g +#LFLAGS = -L../lib -Xlinker -rpath ../lib -lbe -lGL + + +PROGRAMS = demo sample + +default: $(PROGRAMS) + + +clean: + rm -f demo sample + rm -f *.o + + +demo: demo.o + $(CC) demo.o $(LFLAGS) -o $@ + +demo.o: demo.cpp + $(CC) $(CFLAGS) demo.cpp + + +sample: sample.o + $(CC) sample.o $(LFLAGS) -o $@ + +sample.o: sample.cpp + $(CC) $(CFLAGS) sample.cpp diff --git a/progs/beos/demo.cpp b/progs/beos/demo.cpp new file mode 100644 index 0000000000..c25eb93075 --- /dev/null +++ b/progs/beos/demo.cpp @@ -0,0 +1,153 @@ +// $Id: demo.cpp,v 1.1 1999/08/19 00:55:40 jtg Exp $ + +// Simple BeOS GLView demo +// Written by Brian Paul +// This file is in the public domain. + + + +#include +#include +#include +#include + + +class MyWindow : public BWindow +{ +public: + MyWindow(BRect frame); + virtual bool QuitRequested(); +}; + + +MyWindow::MyWindow(BRect frame) + : BWindow(frame, "demo", B_TITLED_WINDOW, B_NOT_ZOOMABLE) +{ + // no-op +} + +bool MyWindow::QuitRequested() +{ + be_app->PostMessage(B_QUIT_REQUESTED); + return true; +} + + +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) +{ + mAngle = 0.0; +} + + +#if 0 +void MyGL::AttachedToWindow() +{ + BGLView::AttachedToWindow(); + LockGL(); + glClearColor(.7, .7, 0, 0); + UnlockGL(); +} +#endif + + +void MyGL::FrameResized(float w, float 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(); +} + + + +void MyGL::Draw(BRect r) +{ + printf("MyGL::Draw\n"); + BGLView::Draw(r); + 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(); +} + + +void MyGL::Pulse() +{ + 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(); +} + + + +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(); + 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(); + + delete app; + + return 0; +} diff --git a/progs/beos/sample.cpp b/progs/beos/sample.cpp new file mode 100644 index 0000000000..2310b33882 --- /dev/null +++ b/progs/beos/sample.cpp @@ -0,0 +1,212 @@ +// sample BGLView app from the Be Book + + +#include +#include +#include +#include + + +class SampleGLView : public BGLView +{ +public: + SampleGLView(BRect frame, uint32 type); + virtual void AttachedToWindow(void); + virtual void FrameResized(float newWidth, float newHeight); + virtual void ErrorCallback(GLenum which); + + void Render(void); + +private: + void gInit(void); + void gDraw(void); + void gReshape(int width, int height); + + float width; + float height; +}; + + + +class SampleGLWindow : public BWindow +{ +public: + SampleGLWindow(BRect frame, uint32 type); + virtual bool QuitRequested() { return true; } + +private: + SampleGLView *theView; +}; + + +class SampleGLApp : public BApplication +{ +public: + SampleGLApp(); +private: + SampleGLWindow *theWindow; +}; + + +SampleGLApp::SampleGLApp() + : BApplication("application/x-vnd.sample") +{ + BRect windowRect; + uint32 type = BGL_RGB|BGL_DOUBLE; + + windowRect.Set(50, 50, 350, 350); + + theWindow = new SampleGLWindow(windowRect, type); +} + + + +SampleGLWindow::SampleGLWindow(BRect frame, uint32 type) + : BWindow(frame, "OpenGL Test", B_TITLED_WINDOW, 0) +{ + theView = new SampleGLView(Bounds(), type); + AddChild(theView); + Show(); + theView->Render(); +} + + + +SampleGLView::SampleGLView(BRect frame, uint32 type) + : BGLView(frame, "SampleGLView", B_FOLLOW_ALL_SIDES, 0, type) +{ + width = frame.right-frame.left; + height = frame.bottom-frame.top; +} + + +void SampleGLView::AttachedToWindow(void) +{ + LockGL(); + BGLView::AttachedToWindow(); + gInit(); + gReshape(width, height); + UnlockGL(); +} + + +void SampleGLView::FrameResized(float newWidth, float newHeight) +{ + LockGL(); + BGLView::FrameResized(width, height); + width = newWidth; + height = newHeight; + + gReshape(width,height); + + UnlockGL(); + Render(); +} + + +void SampleGLView::ErrorCallback(GLenum whichError) +{ +// fprintf(stderr, "Unexpected error occured (%d):\\n", whichError); +// fprintf(stderr, " %s\\n", gluErrorString(whichError)); +} + + + +// globals +GLenum use_stipple_mode; // GL_TRUE to use dashed lines +GLenum use_smooth_mode; // GL_TRUE to use anti-aliased lines +GLint linesize; // Line width +GLint pointsize; // Point diameter + +float pntA[3] = { + -160.0, 0.0, 0.0 +}; +float pntB[3] = { + -130.0, 0.0, 0.0 +}; + + + +void SampleGLView::gInit(void) +{ + glClearColor(0.0, 0.0, 0.0, 0.0); + glLineStipple(1, 0xF0E0); + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + use_stipple_mode = GL_FALSE; + use_smooth_mode = GL_TRUE; + linesize = 2; + pointsize = 4; +} + + + +void SampleGLView::gDraw(void) +{ + GLint i; + + glClear(GL_COLOR_BUFFER_BIT); + glLineWidth(linesize); + + if (use_stipple_mode) { + glEnable(GL_LINE_STIPPLE); + } else { + glDisable(GL_LINE_STIPPLE); + } + + if (use_smooth_mode) { + glEnable(GL_LINE_SMOOTH); + glEnable(GL_BLEND); + } else { + glDisable(GL_LINE_SMOOTH); + glDisable(GL_BLEND); + } + + glPushMatrix(); + + for (i = 0; i < 360; i += 5) { + glRotatef(5.0, 0,0,1); // Rotate right 5 degrees + glColor3f(1.0, 1.0, 0.0); // Set color for line + glBegin(GL_LINE_STRIP); // And create the line + glVertex3fv(pntA); + glVertex3fv(pntB); + glEnd(); + + glPointSize(pointsize); // Set size for point + glColor3f(0.0, 1.0, 0.0); // Set color for point + glBegin(GL_POINTS); + glVertex3fv(pntA); // Draw point at one end + glVertex3fv(pntB); // Draw point at other end + glEnd(); + } + + glPopMatrix(); // Done with matrix +} + + +void SampleGLView::gReshape(int width, int height) +{ + glViewport(0, 0, width, height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-175, 175, -175, 175, -1, 1); + glMatrixMode(GL_MODELVIEW); +} + + +void SampleGLView::Render(void) +{ + LockGL(); + gDraw(); + SwapBuffers(); + UnlockGL(); +} + + + +int main(int argc, char *argv[]) +{ + SampleGLApp *app = new SampleGLApp; + app->Run(); + delete app; + return 0; +} -- cgit v1.2.3