15 #include <grass/glocale.h> 
   16 #include <grass/nviz.h> 
   26     struct render_window *rwin;
 
   29     rwin = (
struct render_window *)G_malloc(
sizeof(
struct render_window));
 
   41 #if defined(OPENGL_X11) 
   42     rwin->displayId = 
NULL;
 
   43     rwin->contextId = 
NULL;
 
   46 #elif defined(OPENGL_AQUA) 
   47     rwin->pixelFmtId = 
NULL;
 
   48     rwin->contextId = 
NULL;
 
   49     rwin->windowId = 
NULL;
 
   50 #elif defined(OPENGL_WINDOWS) 
   51     rwin->displayId = 
NULL;
 
   52     rwin->contextId = 
NULL;
 
   53     rwin->bitmapId = 
NULL;
 
   64 #if defined(OPENGL_X11) 
   65     glXDestroyGLXPixmap(rwin->displayId, rwin->windowId);
 
   66     XFreePixmap(rwin->displayId, rwin->pixmap);
 
   67     glXDestroyContext(rwin->displayId, rwin->contextId);
 
   68     XCloseDisplay(rwin->displayId);
 
   69 #elif defined(OPENGL_AQUA) 
   70     aglDestroyPixelFormat(rwin->pixelFmtId);
 
   71     aglDestroyContext(rwin->contextId);
 
   72     aglDestroyPBuffer(rwin->windowId);
 
   74 #elif defined(OPENGL_WINDOWS) 
   75     wglDeleteContext(rwin->contextId);
 
   76     DeleteDC(rwin->displayId);
 
   77     DeleteObject(rwin->bitmapId);
 
   96 #if defined(OPENGL_X11) 
   97     int attributeList[] = { GLX_RGBA, GLX_RED_SIZE, 1,
 
   98         GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1,
 
   99         GLX_DEPTH_SIZE, 1, None
 
  103     rwin->displayId = XOpenDisplay((
char *)display);
 
  104     if (!rwin->displayId) {
 
  108     v = glXChooseVisual(rwin->displayId,
 
  109                         DefaultScreen(rwin->displayId), attributeList);
 
  111     rwin->contextId = glXCreateContext(rwin->displayId, v, 
NULL, GL_FALSE);
 
  113     if (!rwin->contextId) {
 
  118     rwin->pixmap = XCreatePixmap(rwin->displayId,
 
  119                                  RootWindow(rwin->displayId, v->screen),
 
  120                                  width, height, v->depth);
 
  123     rwin->windowId = glXCreateGLXPixmap(rwin->displayId, v, rwin->pixmap);
 
  128 #elif defined(OPENGL_AQUA) 
  129     int attributeList[] = { AGL_RGBA, AGL_RED_SIZE, 1,
 
  130         AGL_GREEN_SIZE, 1, AGL_BLUE_SIZE, 1,
 
  131         AGL_DEPTH_SIZE, 1, AGL_NONE
 
  136     rwin->pixelFmtId = aglChoosePixelFormat(
NULL, 0, attributeList);
 
  138     rwin->contextId = aglCreateContext(rwin->pixelFmtId, 
NULL);
 
  141     aglCreatePBuffer(width, height, GL_TEXTURE_2D, GL_RGBA, 0, &(rwin->windowId));
 
  142 #elif defined(OPENGL_WINDOWS) 
  143     PIXELFORMATDESCRIPTOR pfd = {
 
  144         sizeof(PIXELFORMATDESCRIPTOR),  
 
  165     rwin->displayId = CreateCompatibleDC(
NULL);
 
  166     iPixelFormat = ChoosePixelFormat(rwin->displayId, &pfd);
 
  167     SetPixelFormat(rwin->displayId, iPixelFormat, &pfd);
 
  168     rwin->bitmapId = CreateCompatibleBitmap(rwin->displayId, width, height);
 
  169     SelectObject(rwin->displayId, rwin->bitmapId);
 
  170     rwin->contextId = wglCreateContext(rwin->displayId);
 
  186 #if defined(OPENGL_X11) 
  187     if (!rwin->displayId || !rwin->contextId)
 
  190     if (rwin->contextId == glXGetCurrentContext())
 
  193     glXMakeCurrent(rwin->displayId, rwin->windowId, rwin->contextId);
 
  194 #elif defined(OPENGL_AQUA) 
  195     if (!rwin->contextId)
 
  198     if (rwin->contextId == aglGetCurrentContext())
 
  201     aglSetCurrentContext(rwin->contextId);
 
  202     aglSetPBuffer(rwin->contextId, rwin->windowId, 0, 0, 0);
 
  203 #elif defined(OPENGL_WINDOWS) 
  204     if (!rwin->displayId || !rwin->contextId)
 
  207     wglMakeCurrent(rwin->displayId, rwin->contextId);
 
int Nviz_make_current_render_window(const struct render_window *rwin)
Make window current for rendering. 
void G_free(void *buf)
Free allocated memory. 
void Nviz_destroy_render_window(struct render_window *rwin)
Free render window. 
struct render_window * Nviz_new_render_window(void)
Allocate memory for render window. 
int Nviz_create_render_window(struct render_window *rwin, void *display, int width, int height)
Create render window. 
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr. 
void Nviz_init_render_window(struct render_window *rwin)
Initialize render window.