Fix demo.cpp, which wasn't working as expected.

Add a GLInfo app, a graphical tool displaying GL Info as a treeview.
Usefull to see which OpenGL renderer you use and which extension(s) is supported.
Convert the Makefile to be $(TOP)/configs/default-based.
This commit is contained in:
Philippe Houdoin 2004-08-14 09:59:16 +00:00
parent 41ea155878
commit f17ddd4884
4 changed files with 208 additions and 101 deletions

122
progs/beos/GLInfo.cpp Normal file
View File

@ -0,0 +1,122 @@
// Small app to display GL infos
#include <stdio.h>
#include <string.h>
#include <Application.h>
#include <Window.h>
#include <OutlineListView.h>
#include <ScrollView.h>
#include <GLView.h>
#include <String.h>
#include <GL/gl.h>
class GLInfoWindow : public BWindow
{
public:
GLInfoWindow(BRect frame);
virtual bool QuitRequested() { be_app->PostMessage(B_QUIT_REQUESTED); return true; }
private:
BGLView *gl;
BOutlineListView *list;
BScrollView *scroller;
};
class GLInfoApp : public BApplication
{
public:
GLInfoApp();
private:
GLInfoWindow *window;
};
GLInfoApp::GLInfoApp()
: BApplication("application/x-vnd.OBOS-GLInfo")
{
window = new GLInfoWindow(BRect(50, 50, 350, 350));
}
GLInfoWindow::GLInfoWindow(BRect frame)
: BWindow(frame, "OpenGL Info", B_TITLED_WINDOW, 0)
{
BRect r = Bounds();
char *s;
BString l;
// Add a outline list view
r.right -= B_V_SCROLL_BAR_WIDTH;
list = new BOutlineListView(r, "GLInfoList", B_SINGLE_SELECTION_LIST, B_FOLLOW_ALL_SIDES);
scroller = new BScrollView("GLInfoListScroller", list, B_FOLLOW_ALL_SIDES,
B_WILL_DRAW | B_FRAME_EVENTS, false, true);
gl = new BGLView(r, "opengl", B_FOLLOW_ALL_SIDES, 0, BGL_RGB | BGL_DOUBLE);
gl->Hide();
AddChild(gl);
AddChild(scroller);
Show();
LockLooper();
// gl->LockGL();
s = (char *) glGetString(GL_RENDERER);
if (!s)
goto error;
list->AddItem(new BStringItem(s));
s = (char *) glGetString(GL_VENDOR);
if (s) {
l = ""; l << "Vendor Name: " << s;
list->AddItem(new BStringItem(l.String(), 1));
}
s = (char *) glGetString(GL_VERSION);
if (s) {
l = ""; l << "Version: " << s;
list->AddItem(new BStringItem(l.String(), 1));
}
s = (char *) glGetString(GL_RENDERER);
if (s) {
l = ""; l << "Renderer Name: " << s;
list->AddItem(new BStringItem(l.String(), 1));
}
s = (char *) glGetString(GL_EXTENSIONS);
if (s) {
list->AddItem(new BStringItem("OpenGL Extensions", 1));
while (*s) {
char extname[255];
int n = strcspn(s, " ");
strncpy(extname, s, n);
extname[n] = 0;
list->AddItem(new BStringItem(extname, 2));
if (! s[n])
break;
s += (n + 1); // next !
}
}
// gl->UnlockGL();
error:
UnlockLooper();
}
int main(int argc, char *argv[])
{
GLInfoApp *app = new GLInfoApp;
app->Run();
delete app;
return 0;
}

View File

@ -1,42 +1,31 @@
# $Id: Makefile,v 1.2 1999/09/17 00:55:21 brianp Exp $ # progs/beos/Makefile
TOP = ../..
include $(TOP)/configs/current
# Makefile for BeOS demos # Makefile for BeOS demos
# Written by Brian Paul # Written by Brian Paul
# This file is in the public domain. # This file is in the public domain.
#
# Modified by Philippe Houdoin
LDFLAGS += -soname=_APP_ $(APP_LIB_DEPS)
default: demo sample GLInfo
CC = g++
# Use Mesa:
CFLAGS = -I../include -c -g
LFLAGS = -L../lib -Xlinker -rpath ../lib -lbe -lGL
# 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: clean:
rm -f demo sample rm -f demo sample GLInfo
rm -f *.o rm -f *.o
demo: demo.o demo: demo.o
$(CC) demo.o $(LFLAGS) -o $@ $(LD) demo.o $(LDFLAGS) -o $@
demo.o: demo.cpp
$(CC) $(CFLAGS) demo.cpp
sample: sample.o sample: sample.o
$(CC) sample.o $(LFLAGS) -o $@ $(LD) sample.o $(LDFLAGS) -o $@
sample.o: sample.cpp GTLInfo: GLInfo.o
$(CC) $(CFLAGS) sample.cpp $(LD) GLInfo.o $(LDFLAGS) -o $@
.cpp.o:
$(CC) -c $< $(CFLAGS) -o $@

View File

@ -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 // Simple BeOS GLView demo
// Written by Brian Paul // Written by Brian Paul
// Changes by Philippe Houdoin
// This file is in the public domain. // This file is in the public domain.
@ -11,19 +12,40 @@
#include <Window.h> #include <Window.h>
#include <GLView.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 class MyWindow : public BWindow
{ {
public: public:
MyWindow(BRect frame); MyWindow(BRect frame);
virtual bool QuitRequested(); virtual bool QuitRequested();
}; };
MyWindow::MyWindow(BRect frame) MyWindow::MyWindow(BRect frame)
: BWindow(frame, "demo", B_TITLED_WINDOW, B_NOT_ZOOMABLE) : 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() 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) 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() void MyGL::AttachedToWindow()
{ {
BGLView::AttachedToWindow(); BGLView::AttachedToWindow();
LockGL();
glClearColor(.7, .7, 0, 0); LockGL();
UnlockGL(); glClearColor(0.7, 0.7, 0, 0);
Reshape(Bounds().Width(), Bounds().Height());
UnlockGL();
} }
#endif
void MyGL::FrameResized(float w, float h) void MyGL::FrameResized(float w, float h)
{ {
BGLView::FrameResized(w, h); BGLView::FrameResized(w, h);
printf("FrameResized\n"); LockGL();
LockGL(); Reshape(w, h);
BGLView::FrameResized(w,h); UnlockGL();
glViewport(0, 0, (int) (w + 1), (int) (h + 1));
glMatrixMode(GL_PROJECTION); Render();
glLoadIdentity();
glFrustum(-1, 1, -1, 1, 10, 30);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0, 0, -18);
UnlockGL();
} }
void MyGL::Pulse()
void MyGL::Draw(BRect r) {
mAngle += 1.0;
Render();
}
void MyGL::Render()
{ {
printf("MyGL::Draw\n");
BGLView::Draw(r);
LockGL(); LockGL();
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix(); glPushMatrix();
glRotatef(mAngle, 0, 0, 1);
glRotated(mAngle, 0, 0, 1);
glColor3f(0, 0, 1); glColor3f(0, 0, 1);
glBegin(GL_POLYGON); glBegin(GL_POLYGON);
glVertex2f(-1, -1); glVertex2f(-1, -1);
glVertex2f( 1, -1); glVertex2f( 1, -1);
glVertex2f( 1, 1); glVertex2f( 1, 1);
glVertex2f(-1, 1); glVertex2f(-1, 1);
glEnd(); glEnd();
glPopMatrix();
SwapBuffers(); SwapBuffers();
UnlockGL(); UnlockGL();
} }
void MyGL::Pulse() void MyGL::Reshape(float w, float h)
{ {
printf("pulse\n"); glViewport(0, 0, (int) (w + 1), (int) (h + 1));
BGLView::Pulse(); glMatrixMode(GL_PROJECTION);
mAngle += 1.0; glLoadIdentity();
glFrustum(-1, 1, -1, 1, 10, 30);
LockGL(); glMatrixMode(GL_MODELVIEW);
glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity();
glPushMatrix(); glTranslatef(0, 0, -18);
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[]) int main(int argc, char *argv[])
{ {
BApplication *app = new BApplication("application/demo"); BApplication *app = new BApplication("application/demo");
// make top-level window // make top-level window
int x = 500, y = 500; MyWindow *win = new MyWindow(BRect(100, 100, 500, 500));
int w = 400, h = 400;
MyWindow *win = new MyWindow(BRect(x, y, x + w, y + h));
// win->Lock();
// win->Unlock();
win->Show(); win->Show();
// Make OpenGL view and put it in the window app->Run();
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; delete app;

View File

@ -92,8 +92,10 @@ void SampleGLView::AttachedToWindow(void)
void SampleGLView::FrameResized(float newWidth, float newHeight) void SampleGLView::FrameResized(float newWidth, float newHeight)
{ {
BGLView::FrameResized(newWidth, newHeight);
LockGL(); LockGL();
BGLView::FrameResized(width, height);
width = newWidth; width = newWidth;
height = newHeight; height = newHeight;