125#if defined(OPENGL_X11)
126 glXDestroyGLXPixmap(rwin->displayId, rwin->windowId);
127 XFreePixmap(rwin->displayId, rwin->pixmap);
128 glXDestroyContext(rwin->displayId, rwin->contextId);
129 XCloseDisplay(rwin->displayId);
130#elif defined(OPENGL_AQUA)
131#if defined(OPENGL_AGL)
132 aglDestroyPixelFormat(rwin->pixelFmtId);
133 aglDestroyContext(rwin->contextId);
134 aglDestroyPBuffer(rwin->windowId);
136 CGLDestroyContext(rwin->contextId);
138#elif defined(OPENGL_WINDOWS)
139 wglDeleteContext(rwin->contextId);
140 DeleteDC(rwin->displayId);
158 int width,
int height)
160#if defined(OPENGL_X11)
161 int attributeList[] = {
171#if !defined(OPENGL_FBO)
178 rwin->displayId = XOpenDisplay((
char *)display);
179 if (!rwin->displayId) {
183 v = glXChooseVisual(rwin->displayId, DefaultScreen(rwin->displayId),
186 G_warning(_(
"Unable to get visual info"));
190 rwin->contextId = glXCreateContext(rwin->displayId, v,
NULL, GL_TRUE);
192 if (!rwin->contextId) {
193 G_warning(_(
"Unable to create rendering context"));
199 XCreatePixmap(rwin->displayId, RootWindow(rwin->displayId, v->screen),
200 width, height, v->depth);
203 rwin->windowId = glXCreateGLXPixmap(rwin->displayId, v, rwin->pixmap);
206#elif defined(OPENGL_AQUA)
207#if defined(OPENGL_AGL)
208 int attributeList[] = {
218#if !defined(OPENGL_FBO)
227 rwin->pixelFmtId = aglChoosePixelFormat(
NULL, 0, attributeList);
229 rwin->contextId = aglCreateContext(rwin->pixelFmtId,
NULL);
232 aglCreatePBuffer(width, height, GL_TEXTURE_2D, GL_RGBA, 0,
234 aglSetPBuffer(rwin->contextId, rwin->windowId, 0, 0, 0);
236 CGLPixelFormatAttribute attributeList[] = {
237 kCGLPFAColorSize, 24, kCGLPFADepthSize, 32, (CGLPixelFormatAttribute)0};
238 CGLPixelFormatObj pix;
242 error = CGLChoosePixelFormat(attributeList, &pix, &nvirt);
244 G_warning(_(
"Unable to choose pixel format (CGL error = %d)"), error);
248 error = CGLCreateContext(pix,
NULL, &rwin->contextId);
250 G_warning(_(
"Unable to create context (CGL error = %d)"), error);
254 CGLDestroyPixelFormat(pix);
256#elif defined(OPENGL_WINDOWS)
260 PIXELFORMATDESCRIPTOR pfd = {
261 sizeof(PIXELFORMATDESCRIPTOR),
292 wc.lpfnWndProc = DefWindowProc;
293 wc.lpszClassName =
"nviz";
295 if (!RegisterClass(&wc)) {
296 G_warning(_(
"Unable to register window class"));
300 hWnd = CreateWindow(wc.lpszClassName, wc.lpszClassName, WS_POPUP,
301 CW_USEDEFAULT, CW_USEDEFAULT, width, height,
NULL,
NULL,
309 rwin->displayId = GetDC(hWnd);
310 iPixelFormat = ChoosePixelFormat(rwin->displayId, &pfd);
311 SetPixelFormat(rwin->displayId, iPixelFormat, &pfd);
312 rwin->contextId = wglCreateContext(rwin->displayId);
316 rwin->height = height;
331#if defined(OPENGL_X11)
332 if (!rwin->displayId || !rwin->contextId)
335 if (rwin->contextId == glXGetCurrentContext())
338 glXMakeCurrent(rwin->displayId, rwin->windowId, rwin->contextId);
339#elif defined(OPENGL_AQUA)
340#if defined(OPENGL_AGL)
341 if (!rwin->contextId)
344 if (rwin->contextId == aglGetCurrentContext())
347 aglSetCurrentContext(rwin->contextId);
351 error = CGLSetCurrentContext(rwin->contextId);
353 G_warning(_(
"Unable to set current context (CGL error = %d)"), error);
357#elif defined(OPENGL_WINDOWS)
358 if (!rwin->displayId || !rwin->contextId)
361 wglMakeCurrent(rwin->displayId, rwin->contextId);
364#if defined(OPENGL_FBO)
365#if defined(OPENGL_WINDOWS)
369 GLuint framebuf, renderbuf, depthbuf;
372 glGenFramebuffers(1, &framebuf);
373 glBindFramebuffer(GL_FRAMEBUFFER, framebuf);
375 glGenRenderbuffers(1, &renderbuf);
376 glBindRenderbuffer(GL_RENDERBUFFER, renderbuf);
377 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, rwin->width, rwin->height);
378 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
379 GL_RENDERBUFFER, renderbuf);
381 glGenRenderbuffers(1, &depthbuf);
382 glBindRenderbuffer(GL_RENDERBUFFER, depthbuf);
383 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, rwin->width,
385 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
386 GL_RENDERBUFFER, depthbuf);
388 status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
389 if (status != GL_FRAMEBUFFER_COMPLETE) {
390 G_warning(_(
"Incomplete framebuffer status (status = %d)"), status);
395 glViewport(0, 0, rwin->width, rwin->height);