[GRASS-SVN] r32118 - in grass/trunk: include lib/nviz
visualization/nviz2/cmd
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Jul 15 03:57:08 EDT 2008
Author: glynn
Date: 2008-07-15 03:57:07 -0400 (Tue, 15 Jul 2008)
New Revision: 32118
Modified:
grass/trunk/include/nviz.h
grass/trunk/lib/nviz/Makefile
grass/trunk/lib/nviz/render.c
grass/trunk/visualization/nviz2/cmd/write_img.c
Log:
Clean-up, portability fixes
Modified: grass/trunk/include/nviz.h
===================================================================
--- grass/trunk/include/nviz.h 2008-07-15 05:53:52 UTC (rev 32117)
+++ grass/trunk/include/nviz.h 2008-07-15 07:57:07 UTC (rev 32118)
@@ -117,12 +117,14 @@
GLXPixmap windowId;
Pixmap pixmap;
#elif defined(OPENGL_AQUA)
- AGLPixelFmtID displayId;
+ AGLPixelFmtID pixelFmtId;
AGLContext contextId;
AGLPixmap windowId;
GWorldPtr pixmap;
#elif defined(OPENGL_WINDOWS)
- /* TODO */
+ HDC displayId; /* display context */
+ HGLRC contextId; /* rendering context */
+ HBITMAP bitmapId;
#endif
};
Modified: grass/trunk/lib/nviz/Makefile
===================================================================
--- grass/trunk/lib/nviz/Makefile 2008-07-15 05:53:52 UTC (rev 32117)
+++ grass/trunk/lib/nviz/Makefile 2008-07-15 07:57:07 UTC (rev 32118)
@@ -7,6 +7,10 @@
include $(MODULE_TOPDIR)/include/Make/Lib.make
include $(MODULE_TOPDIR)/include/Make/Doxygen.make
+ifeq ($(OPENGL_WINDOWS),1)
+EXTRA_LIBS += -lgdi32
+endif
+
EXTRA_INC = $(VECT_INC) $(OPENGLINC) $(TIFFINCPATH) $(FFMPEGINCPATH)
EXTRA_CFLAGS = $(VECT_CFLAGS) $(XCFLAGS)
Modified: grass/trunk/lib/nviz/render.c
===================================================================
--- grass/trunk/lib/nviz/render.c 2008-07-15 05:53:52 UTC (rev 32117)
+++ grass/trunk/lib/nviz/render.c 2008-07-15 07:57:07 UTC (rev 32118)
@@ -25,7 +25,7 @@
\return pointer to render_window struct
\return NULL on failure
*/
-struct render_window *Nviz_new_render_window()
+struct render_window *Nviz_new_render_window(void)
{
struct render_window *rwin;
@@ -42,12 +42,20 @@
*/
void Nviz_init_render_window(struct render_window *rwin)
{
+#if defined(OPENGL_X11)
rwin->displayId = NULL;
rwin->contextId = NULL;
rwin->pixmap = 0;
rwin->windowId = 0;
-
- return;
+#elif defined(OPENGL_AQUA)
+ rwin->pixelFmtId = NULL;
+ rwin->contextId = NULL;
+ rwin->pixmap = 0;
+ rwin->windowId = 0;
+#elif defined(OPENGL_WINDOWS)
+ rwin->displayId = NULL;
+ rwin->contextId = NULL;
+#endif
}
/*!
@@ -66,12 +74,12 @@
aglDestroyAGLPixmap(rwin->windowId);
/* TODO FreePixMap */
#elif defined(OPENGL_WINDOWS)
- /* TODO: wglDeleteContext( HRC hrc ) */
+ wglDeleteContext(rwin->contextId);
+ DeleteDC(rwin->displayId);
+ DeleteObject(rwin->bitmapId);
#endif
G_free ((void *) rwin);
-
- return;
}
/*!
@@ -88,53 +96,27 @@
int width, int height)
{
#if defined(OPENGL_X11)
- XVisualInfo *v;
-#elif defined(OPENGL_AQUA)
- AGLPixelFmtID v;
-#elif defined(OPENGL_WINDOWS)
- int v;
-#endif
-
int attributeList[] = { GLX_RGBA, GLX_RED_SIZE, 1,
GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1,
GLX_DEPTH_SIZE, 1, None };
+ XVisualInfo *v;
- /* get the default display connection */
-#if defined(OPENGL_X11)
rwin->displayId = XOpenDisplay((char *) display);
-#elif defined(OPENGL_AQUA)
- /* TODO: open mac display */
-#elif defined(OPENGL_WINDOWS)
- /* TODO */
-#endif
-
if (!rwin->displayId) {
G_fatal_error (_("Bad server connection"));
}
- /* get visual info and set up pixmap buffer */
-#if defined(OPENGL_X11)
v = glXChooseVisual(rwin->displayId,
DefaultScreen(rwin->displayId),
attributeList);
rwin->contextId = glXCreateContext(rwin->displayId,
v, NULL, GL_FALSE);
-#elif defined(OPENGL_AQUA)
- /* TODO: dev = NULL, ndev = 0 ? */
- rwin->displayId = aglChoosePixelFmt(NULL, 0, attributeList);
-
- rwin->contextId = aglCreateContext(rwin->displayId, NULL);
-#elif defined(OPENGL_WINDOWS)
- /* TODO int ChoosePixelFormat( HDC hdc, PIXELFORMATDESCRIPTOR *pfd ) */
-#endif
if (!rwin->contextId) {
G_fatal_error (_("Unable to create rendering context"));
}
-
-#if defined(OPENGL_X11)
/* create win pixmap to render to (same depth as RootWindow) */
rwin->pixmap = XCreatePixmap(rwin->displayId,
RootWindow(rwin->displayId, v->screen),
@@ -145,20 +127,57 @@
/* create an off-screen GLX rendering area */
rwin->windowId = glXCreateGLXPixmap(rwin->displayId,
v, rwin->pixmap);
+
+ if (v) {
+ XFree(v);
+ }
#elif defined(OPENGL_AQUA)
+ int attributeList[] = { AGL_RGBA, AGL_RED_SIZE, 1,
+ AGL_GREEN_SIZE, 1, AGL_BLUE_SIZE, 1,
+ AGL_DEPTH_SIZE, 1, AGL_NONE };
+ /* TODO: open mac display */
+
+ /* TODO: dev = NULL, ndev = 0 ? */
+ rwin->pixelFmtId = aglChoosePixelFmt(NULL, 0, attributeList);
+
+ rwin->contextId = aglCreateContext(rwin->pixelFmtId, NULL);
+
/* create win pixmap to render to (same depth as RootWindow) */
rwin->pixmap = NULL; /* TODO: create GWorldPtr */
/* create an off-screen AGL rendering area */
- rwin->windowId = aglCreateAGLPixmap(rwin->displayId,
+ rwin->windowId = aglCreateAGLPixmap(rwin->pixelFmtId,
rwin->pixmap);
#elif defined(OPENGL_WINDOWS)
+ PIXELFORMATDESCRIPTOR pfd = {
+ sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
+ 1, /* version number */
+ PFD_DRAW_TO_WINDOW | /* support window */
+ PFD_SUPPORT_OPENGL | /* support OpenGL */
+ PFD_DOUBLEBUFFER, /* double buffered */
+ PFD_TYPE_RGBA, /* RGBA type */
+ 24, /* 24-bit color depth */
+ 0, 0, 0, 0, 0, 0, /* color bits ignored */
+ 0, /* no alpha buffer */
+ 0, /* shift bit ignored */
+ 0, /* no accumulation buffer */
+ 0, 0, 0, 0, /* accum bits ignored */
+ 32, /* 32-bit z-buffer */
+ 0, /* no stencil buffer */
+ 0, /* no auxiliary buffer */
+ PFD_MAIN_PLANE, /* main layer */
+ 0, /* reserved */
+ 0, 0, 0 /* layer masks ignored */
+ };
+ int iPixelFormat;
+
+ rwin->displayId = CreateCompatibleDC(NULL);
+ iPixelFormat = ChoosePixelFormat(rwin->displayId, &pfd);
+ SetPixelFormat(rwin->displayId, iPixelFormat, &pfd);
+ rwin->bitmapId = CreateCompatibleBitmap(rwin->displayId, width, height);
+ SelectObject(rwin->displayId, rwin->bitmapId);
+ rwin->contextId = wglCreateContext(rwin->displayId);
/* TODO */
#endif
-
- if (v) {
- XFree(v);
- }
-
return 1;
}
@@ -172,10 +191,10 @@
*/
int Nviz_make_current_render_window(const struct render_window *rwin)
{
+#if defined(OPENGL_X11)
if (!rwin->displayId || !rwin->contextId)
return 0;
-#if defined(OPENGL_X11)
if (rwin->contextId == glXGetCurrentContext())
return 1;
@@ -188,7 +207,10 @@
/* TODO: mac_win */
aglMakeCurrent((AGLDrawable) mac_win, rwin->contextId);
#elif defined(OPENGL_WINDOWS)
- /* TODO wglMakeCurrent( HDC hdc, HGLRC hrc ) */
+ if (!rwin->displayId || !rwin->contextId)
+ return 0;
+
+ wglMakeCurrent(rwin->displayId, rwin->contextId);
#endif
return 1;
Modified: grass/trunk/visualization/nviz2/cmd/write_img.c
===================================================================
--- grass/trunk/visualization/nviz2/cmd/write_img.c 2008-07-15 05:53:52 UTC (rev 32117)
+++ grass/trunk/visualization/nviz2/cmd/write_img.c 2008-07-15 07:57:07 UTC (rev 32118)
@@ -16,11 +16,11 @@
\date 2008
*/
+#include "local_proto.h"
+
#include <grass/gsurf.h>
#include <grass/gstypes.h>
-#include "local_proto.h"
-
/*!
\brief Save current GL screen to an ppm file.
More information about the grass-commit
mailing list