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);
95 int width,
int height)
97 #if defined(OPENGL_X11)
98 int attributeList[] = { GLX_RGBA, GLX_RED_SIZE, 1,
99 GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1,
100 GLX_DEPTH_SIZE, 1, None
104 rwin->displayId = XOpenDisplay((
char *)display);
105 if (!rwin->displayId) {
109 v = glXChooseVisual(rwin->displayId,
110 DefaultScreen(rwin->displayId), attributeList);
112 G_warning(_(
"Unable to get visual info"));
116 rwin->contextId = glXCreateContext(rwin->displayId, v,
NULL, GL_FALSE);
118 if (!rwin->contextId) {
119 G_warning(_(
"Unable to create rendering context"));
124 rwin->pixmap = XCreatePixmap(rwin->displayId,
125 RootWindow(rwin->displayId, v->screen),
126 width, height, v->depth);
129 rwin->windowId = glXCreateGLXPixmap(rwin->displayId, v, rwin->pixmap);
132 #elif defined(OPENGL_AQUA)
133 int attributeList[] = { AGL_RGBA, AGL_RED_SIZE, 1,
134 AGL_GREEN_SIZE, 1, AGL_BLUE_SIZE, 1,
135 AGL_DEPTH_SIZE, 1, AGL_NONE
140 rwin->pixelFmtId = aglChoosePixelFormat(
NULL, 0, attributeList);
142 rwin->contextId = aglCreateContext(rwin->pixelFmtId,
NULL);
145 aglCreatePBuffer(width, height, GL_TEXTURE_2D, GL_RGBA, 0, &(rwin->windowId));
146 #elif defined(OPENGL_WINDOWS)
147 PIXELFORMATDESCRIPTOR pfd = {
148 sizeof(PIXELFORMATDESCRIPTOR),
169 rwin->displayId = CreateCompatibleDC(
NULL);
170 iPixelFormat = ChoosePixelFormat(rwin->displayId, &pfd);
171 SetPixelFormat(rwin->displayId, iPixelFormat, &pfd);
172 rwin->bitmapId = CreateCompatibleBitmap(rwin->displayId, width, height);
173 SelectObject(rwin->displayId, rwin->bitmapId);
174 rwin->contextId = wglCreateContext(rwin->displayId);
190 #if defined(OPENGL_X11)
191 if (!rwin->displayId || !rwin->contextId)
194 if (rwin->contextId == glXGetCurrentContext())
197 glXMakeCurrent(rwin->displayId, rwin->windowId, rwin->contextId);
198 #elif defined(OPENGL_AQUA)
199 if (!rwin->contextId)
202 if (rwin->contextId == aglGetCurrentContext())
205 aglSetCurrentContext(rwin->contextId);
206 aglSetPBuffer(rwin->contextId, rwin->windowId, 0, 0, 0);
207 #elif defined(OPENGL_WINDOWS)
208 if (!rwin->displayId || !rwin->contextId)
211 wglMakeCurrent(rwin->displayId, rwin->contextId);
int Nviz_make_current_render_window(const struct render_window *rwin)
Make window current for rendering.
void Nviz_destroy_render_window(struct render_window *rwin)
Free render window.
void 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.
int Nviz_create_render_window(struct render_window *rwin, void *display, int width, int height)
Create render window.
void G_free(void *buf)
Free allocated memory.
void G_warning(const char *msg,...)
Print a warning message to stderr.
struct render_window * Nviz_new_render_window(void)
Allocate memory for render window.