zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
glewinfo_tail.c
Go to the documentation of this file.
1 }
2 
3 #endif /* _WIN32 */
4 
5 /* ------------------------------------------------------------------------ */
6 
7 #if defined(_WIN32) || !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
8 int main (int argc, char** argv)
9 #else
10 int main (void)
11 #endif
12 {
13  GLuint err;
14 
15 #if defined(_WIN32) || !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
16  char* display = NULL;
17  int visual = -1;
18 
19  if (glewParseArgs(argc-1, argv+1, &display, &visual))
20  {
21 #if defined(_WIN32)
22  fprintf(stderr, "Usage: glewinfo [-pf <id>]\n");
23 #else
24  fprintf(stderr, "Usage: glewinfo [-display <display>] [-visual <id>]\n");
25 #endif
26  return 1;
27  }
28 #endif
29 
30 #if defined(_WIN32)
31  if (GL_TRUE == glewCreateContext(&visual))
32 #elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
33  if (GL_TRUE == glewCreateContext())
34 #else
35  if (GL_TRUE == glewCreateContext(display, &visual))
36 #endif
37  {
38  fprintf(stderr, "Error: glewCreateContext failed\n");
40  return 1;
41  }
43 #ifdef GLEW_MX
44  err = glewContextInit(glewGetContext());
45 #ifdef _WIN32
46  err = err || wglewContextInit(wglewGetContext());
47 #elif !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
48  err = err || glxewContextInit(glxewGetContext());
49 #endif
50 
51 #else
52  err = glewInit();
53 #endif
54  if (GLEW_OK != err)
55  {
56  fprintf(stderr, "Error [main]: glewInit failed: %s\n", glewGetErrorString(err));
58  return 1;
59  }
60 #if defined(_WIN32)
61  f = fopen("glewinfo.txt", "w");
62  if (f == NULL) f = stdout;
63 #else
64  f = stdout;
65 #endif
66  fprintf(f, "---------------------------\n");
67  fprintf(f, " GLEW Extension Info\n");
68  fprintf(f, "---------------------------\n\n");
69  fprintf(f, "GLEW version %s\n", glewGetString(GLEW_VERSION));
70 #if defined(_WIN32)
71  fprintf(f, "Reporting capabilities of pixelformat %d\n", visual);
72 #elif !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
73  fprintf(f, "Reporting capabilities of display %s, visual 0x%x\n",
74  display == NULL ? getenv("DISPLAY") : display, visual);
75 #endif
76  fprintf(f, "Running on a %s from %s\n",
78  fprintf(f, "OpenGL version %s is supported\n", glGetString(GL_VERSION));
79  glewInfo();
80 #if defined(_WIN32)
81  wglewInfo();
82 #else
83  glxewInfo();
84 #endif
85  if (f != stdout) fclose(f);
87  return 0;
88 }
89 
90 /* ------------------------------------------------------------------------ */
91 
92 #if defined(_WIN32) || !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
93 GLboolean glewParseArgs (int argc, char** argv, char** display, int* visual)
94 {
95  int p = 0;
96  while (p < argc)
97  {
98 #if defined(_WIN32)
99  if (!strcmp(argv[p], "-pf") || !strcmp(argv[p], "-pixelformat"))
100  {
101  if (++p >= argc) return GL_TRUE;
102  *display = 0;
103  *visual = strtol(argv[p++], NULL, 0);
104  }
105  else
106  return GL_TRUE;
107 #else
108  if (!strcmp(argv[p], "-display"))
109  {
110  if (++p >= argc) return GL_TRUE;
111  *display = argv[p++];
112  }
113  else if (!strcmp(argv[p], "-visual"))
114  {
115  if (++p >= argc) return GL_TRUE;
116  *visual = (int)strtol(argv[p++], NULL, 0);
117  }
118  else
119  return GL_TRUE;
120 #endif
121  }
122  return GL_FALSE;
123 }
124 #endif
125 
126 /* ------------------------------------------------------------------------ */
127 
128 #if defined(_WIN32)
129 
130 HWND wnd = NULL;
131 HDC dc = NULL;
132 HGLRC rc = NULL;
133 
134 GLboolean glewCreateContext (int* pixelformat)
135 {
136  WNDCLASS wc;
137  PIXELFORMATDESCRIPTOR pfd;
138  /* register window class */
139  ZeroMemory(&wc, sizeof(WNDCLASS));
140  wc.hInstance = GetModuleHandle(NULL);
141  wc.lpfnWndProc = DefWindowProc;
142  wc.lpszClassName = "GLEW";
143  if (0 == RegisterClass(&wc)) return GL_TRUE;
144  /* create window */
145  wnd = CreateWindow("GLEW", "GLEW", 0, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
146  CW_USEDEFAULT, NULL, NULL, GetModuleHandle(NULL), NULL);
147  if (NULL == wnd) return GL_TRUE;
148  /* get the device context */
149  dc = GetDC(wnd);
150  if (NULL == dc) return GL_TRUE;
151  /* find pixel format */
152  ZeroMemory(&pfd, sizeof(PIXELFORMATDESCRIPTOR));
153  if (*pixelformat == -1) /* find default */
154  {
155  pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
156  pfd.nVersion = 1;
157  pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
158  *pixelformat = ChoosePixelFormat(dc, &pfd);
159  if (*pixelformat == 0) return GL_TRUE;
160  }
161  /* set the pixel format for the dc */
162  if (FALSE == SetPixelFormat(dc, *pixelformat, &pfd)) return GL_TRUE;
163  /* create rendering context */
164  rc = wglCreateContext(dc);
165  if (NULL == rc) return GL_TRUE;
166  if (FALSE == wglMakeCurrent(dc, rc)) return GL_TRUE;
167  return GL_FALSE;
168 }
169 
170 void glewDestroyContext ()
171 {
172  if (NULL != rc) wglMakeCurrent(NULL, NULL);
173  if (NULL != rc) wglDeleteContext(rc);
174  if (NULL != wnd && NULL != dc) ReleaseDC(wnd, dc);
175  if (NULL != wnd) DestroyWindow(wnd);
176  UnregisterClass("GLEW", GetModuleHandle(NULL));
177 }
178 
179 /* ------------------------------------------------------------------------ */
180 
181 #elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
182 
183 #include <AGL/agl.h>
184 
185 AGLContext ctx, octx;
186 
188 {
189  int attrib[] = { AGL_RGBA, AGL_NONE };
190  AGLPixelFormat pf;
191  /*int major, minor;
192  SetPortWindowPort(wnd);
193  aglGetVersion(&major, &minor);
194  fprintf(stderr, "GL %d.%d\n", major, minor);*/
195  pf = aglChoosePixelFormat(NULL, 0, attrib);
196  if (NULL == pf) return GL_TRUE;
197  ctx = aglCreateContext(pf, NULL);
198  if (NULL == ctx || AGL_NO_ERROR != aglGetError()) return GL_TRUE;
199  aglDestroyPixelFormat(pf);
200  /*aglSetDrawable(ctx, GetWindowPort(wnd));*/
201  octx = aglGetCurrentContext();
202  if (GL_FALSE == aglSetCurrentContext(ctx)) return GL_TRUE;
203  /* Needed for Regal on the Mac */
204  #if defined(GLEW_REGAL) && defined(__APPLE__)
205  RegalMakeCurrent(octx);
206  #endif
207  return GL_FALSE;
208 }
209 
210 void glewDestroyContext ()
211 {
212  aglSetCurrentContext(octx);
213  if (NULL != ctx) aglDestroyContext(ctx);
214 }
215 
216 /* ------------------------------------------------------------------------ */
217 
218 #else /* __UNIX || (__APPLE__ && GLEW_APPLE_GLX) */
219 
220 Display* dpy = NULL;
221 XVisualInfo* vi = NULL;
222 XVisualInfo* vis = NULL;
224 Window wnd = 0;
225 Colormap cmap = 0;
226 
228 {
229  int attrib[] = { GLX_RGBA, GLX_DOUBLEBUFFER, None };
230  int erb, evb;
231  XSetWindowAttributes swa;
232  /* open display */
233  dpy = XOpenDisplay(display);
234  if (NULL == dpy) return GL_TRUE;
235  /* query for glx */
236  if (!glXQueryExtension(dpy, &erb, &evb)) return GL_TRUE;
237  /* choose visual */
238  if (*visual == -1)
239  {
240  vi = glXChooseVisual(dpy, DefaultScreen(dpy), attrib);
241  if (NULL == vi) return GL_TRUE;
242  *visual = (int)XVisualIDFromVisual(vi->visual);
243  }
244  else
245  {
246  int n_vis, i;
247  vis = XGetVisualInfo(dpy, 0, NULL, &n_vis);
248  for (i=0; i<n_vis; i++)
249  {
250  if ((int)XVisualIDFromVisual(vis[i].visual) == *visual)
251  vi = &vis[i];
252  }
253  if (vi == NULL) return GL_TRUE;
254  }
255  /* create context */
256  ctx = glXCreateContext(dpy, vi, None, True);
257  if (NULL == ctx) return GL_TRUE;
258  /* create window */
259  /*wnd = XCreateSimpleWindow(dpy, RootWindow(dpy, vi->screen), 0, 0, 1, 1, 1, 0, 0);*/
260  cmap = XCreateColormap(dpy, RootWindow(dpy, vi->screen), vi->visual, AllocNone);
261  swa.border_pixel = 0;
262  swa.colormap = cmap;
263  wnd = XCreateWindow(dpy, RootWindow(dpy, vi->screen),
264  0, 0, 1, 1, 0, vi->depth, InputOutput, vi->visual,
265  CWBorderPixel | CWColormap, &swa);
266  /* make context current */
267  if (!glXMakeCurrent(dpy, wnd, ctx)) return GL_TRUE;
268  return GL_FALSE;
269 }
270 
272 {
273  if (NULL != dpy && NULL != ctx) glXDestroyContext(dpy, ctx);
274  if (NULL != dpy && 0 != wnd) XDestroyWindow(dpy, wnd);
275  if (NULL != dpy && 0 != cmap) XFreeColormap(dpy, cmap);
276  if (NULL != vis)
277  XFree(vis);
278  else if (NULL != vi)
279  XFree(vi);
280  if (NULL != dpy) XCloseDisplay(dpy);
281 }
282 
283 #endif /* __UNIX || (__APPLE__ && GLEW_APPLE_GLX) */
#define GL_TRUE
Definition: gl2.h:51
Window wnd
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer retur XCloseDisplay)
Definition: SDL_x11sym.h:34
#define GL_FALSE
Definition: gl2.h:50
int main(int argc, char **argv)
Definition: bootstrap.cpp:102
#define glXCreateContext
Definition: glx_mangle.h:30
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int int int return Display Window Cursor return Display Window return Display Drawable GC int int unsigned int unsigned int return Display Drawable GC int int _Xconst char int return Display Drawable GC int int unsigned int unsigned int return Display return Display Cursor return Display GC return XModifierKeymap return char Display Window int return Display return Display Atom return Display Window XWindowAttributes return Display Window return Display XEvent Bool(*) XPointer return Display Window Bool unsigned int int int Window Cursor Time return Display Window int return KeySym return Display _Xconst char Bool return Display _Xconst char return XKeyEvent char int KeySym XComposeStatus return Display int int int XVisualInfo return Display Window int int retur XOpenDisplay)
Definition: SDL_x11sym.h:92
#define NULL
Definition: ftobjs.h:61
struct __GLXcontextRec * GLXContext
Definition: glxew_head.h:63
GLboolean glewExperimental
#define GLEW_VERSION
Definition: glew_tail.h:11
GLclampf f
Definition: glew.h:3390
unsigned char GLboolean
Definition: gl2.h:24
#define GLX_DOUBLEBUFFER
Definition: glxew_head.h:37
#define glXQueryExtension
Definition: glx_mangle.h:37
#define glXMakeCurrent
Definition: glx_mangle.h:32
GLenum GLEWAPIENTRY wglewContextInit(WGLEW_CONTEXT_ARG_DEF_LIST)
Definition: glew_init_wgl.c:23
void glewDestroyContext()
Definition: glewinfo.c:10669
static GLenum GLEWAPIENTRY glewContextInit(GLEW_CONTEXT_ARG_DEF_LIST)
Definition: glew_init_gl.c:19
char * display
Definition: visualinfo.c:85
#define GL_VERSION
Definition: gl2.h:303
static void glewInfo(void)
Definition: glewinfo_gl.c:3
typedef HDC(WINAPI *PFNWGLGETCURRENTREADDCARBPROC)(VOID)
#define GLX_RGBA
Definition: glxew_head.h:36
int
Definition: SDL_systhread.c:37
Colormap cmap
GLenum glxewContextInit(GLXEW_CONTEXT_ARG_DEF_LIST)
Definition: glew_init_glx.c:15
GLfloat GLfloat p
Definition: glew.h:14938
#define GLEW_OK
Definition: glew_tail.h:4
typedef HGLRC(WINAPI *PFNWGLCREATEASSOCIATEDCONTEXTAMDPROC)(UINT id)
#define glXDestroyContext
Definition: glx_mangle.h:31
#define FALSE
Definition: ftobjs.h:57
XVisualInfo * vi
unsigned int GLuint
Definition: gl2.h:32
#define GL_RENDERER
Definition: gl2.h:302
const GLubyte *GLEWAPIENTRY glewGetErrorString(GLenum error)
Definition: glew_init_tail.c:3
#define GL_VENDOR
Definition: gl2.h:301
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int int int return Display Window Cursor retur XDestroyWindow)
Definition: SDL_x11sym.h:46
GLboolean glewCreateContext(const char *display, int *visual)
Definition: glewinfo.c:10625
GLboolean glewParseArgs(int argc, char **argv, char **display, int *visual)
Definition: glewinfo.c:10491
int i
Definition: pngrutil.c:1377
int visual
Definition: visualinfo.c:86
const GLubyte *GLEWAPIENTRY glewGetString(GLenum name)
GLenum GLEWAPIENTRY glewInit(void)
#define glXChooseVisual
Definition: glx_mangle.h:29
static void glxewInfo()
Definition: glewinfo.c:10208
XVisualInfo * vis
#define glGetString
Definition: gl_mangle.h:824
Display * dpy
EGLContext ctx
Definition: eglext.h:87