summaryrefslogtreecommitdiffstats
path: root/progs/beos/GLInfo.cpp
blob: cfa8c83af82729f6b9f7656d588d199ba8a82f05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// 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>
#include <GL/glu.h>

#define GLUT_INFO 1
#ifdef GLUT_INFO
	#include <GL/glut.h>
#endif


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();
	
	list->AddItem(new BStringItem("OpenGL", 0));

	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("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 !
		}
	}

	list->AddItem(new BStringItem("GLU", 0));
	s = (char *) gluGetString(GLU_VERSION);
	if (s) {
		l = ""; l << "Version: " << s;
		list->AddItem(new BStringItem(l.String(), 1));
	}

	s = (char *) gluGetString(GLU_EXTENSIONS);
	if (s) {
		list->AddItem(new BStringItem("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 !
		}
	}

#ifdef GLUT_INFO
	list->AddItem(new BStringItem("GLUT", 0));
	l = "API version: "; l << GLUT_API_VERSION;
	list->AddItem(new BStringItem(l.String(), 1));
#endif

	// gl->UnlockGL();

	UnlockLooper();
}



int main(int argc, char *argv[])
{
   GLInfoApp *app = new GLInfoApp;
   app->Run();
   delete app;
   return 0;
}