OSMesa 'frontend' troubles
Posted: 06.08.2012, 22:12
Hi all
You guys are probably going to think I'm crazy, but I want to use celestia as sort of a real-time background generator. Specifically, I would like to take screenshots of celestia scenes and set it as my desktop background every so often (every minute for example). The external scripting necessary to do this should be relatively trivial (add cron job to execute celestia with background script which saves screenshot, set root window to display this image). AFAIK though, there is no way to take a celestia screenshot without first opening a celestia instance.(?) Which leads me to believe OSMesa (Off-Screen rendering) is a possible solution.
So using glutmain.cpp as reference, I took it upon myself, to create a new 'front end' to celestia: osmesamain.cpp (below). The code compiles, runs, and celestia detects the osmesa context as "render path: 0" (basic, I think), but when it goes to save the contents of the render buffer to file, the image is solid black. (Perhaps no data ever made it to render buffer?) This is where I'm stuck. I do not have enough knowledge of the celestia/opengl pipeline to determine what has gone awry.
svn diff configure.in
svn diff src/celestia Makefile.am
You guys are probably going to think I'm crazy, but I want to use celestia as sort of a real-time background generator. Specifically, I would like to take screenshots of celestia scenes and set it as my desktop background every so often (every minute for example). The external scripting necessary to do this should be relatively trivial (add cron job to execute celestia with background script which saves screenshot, set root window to display this image). AFAIK though, there is no way to take a celestia screenshot without first opening a celestia instance.(?) Which leads me to believe OSMesa (Off-Screen rendering) is a possible solution.
So using glutmain.cpp as reference, I took it upon myself, to create a new 'front end' to celestia: osmesamain.cpp (below). The code compiles, runs, and celestia detects the osmesa context as "render path: 0" (basic, I think), but when it goes to save the contents of the render buffer to file, the image is solid black. (Perhaps no data ever made it to render buffer?) This is where I'm stuck. I do not have enough knowledge of the celestia/opengl pipeline to determine what has gone awry.
svn diff configure.in
Code: Select all
Index: configure.in
===================================================================
--- configure.in (revision 5213)
+++ configure.in (working copy)
@@ -10,12 +10,16 @@
dnl The following section confirms that the user provided necessary option
dnl BEFORE anything is checked.
+ui_osmesa="no"
ui_glut="no"
ui_gtk="no"
ui_gnome="no"
ui_kde="no"
ui_qt="no"
+AC_ARG_WITH([osmesa],
+ AC_HELP_STRING([--with-osmesa], [Use OSMesa for off-screen rendering]),
+ ui_osmesa="yes")
AC_ARG_WITH([glut],
AC_HELP_STRING([--with-glut], [Use Glut for the UI]),
ui_glut="yes")
@@ -40,9 +44,10 @@
dnl AC_MSG_ERROR([$ui_glut $ui_gtk $ui_gnome $ui_kde])
dnl Check that an interface was provided
-if (test "$ui_glut" != "yes" -a "$ui_gtk" != "yes" -a "$ui_gnome" != "yes" -a "$ui_kde" != "yes" -a "$ui_qt" != "yes"); then
+if (test "$ui_osmesa" != "yes" -a "$ui_glut" != "yes" -a "$ui_gtk" != "yes" -a "$ui_gnome" != "yes" -a "$ui_kde" != "yes" -a "$ui_qt" != "yes"); then
AC_MSG_ERROR([You must select an interface to build.
Possible options are:
+ --with-osmesa OSMesa rendering
--with-glut GLUT front-end
--with-gtk Enhanced GTK GUI
--with-gnome Enhanced GTK GUI with Gnome features
@@ -160,6 +165,13 @@
AM_CONDITIONAL(ENABLE_SPICE, test "$SPICE_LIBS" != "")
+AC_MSG_CHECKING([whether to enable OSMesa])
+if (test "$ui_osmesa" != "no"); then
+ AC_MSG_RESULT(yes)
+else
+ AC_MSG_RESULT(no)
+fi
+
AC_MSG_CHECKING([whether to enable GLUT])
if (test "$ui_glut" != "no"); then
AC_MSG_RESULT(yes)
@@ -234,6 +246,17 @@
PKG_PROG_PKG_CONFIG
+if (test "$ui_osmesa" = "yes"); then
+ dnl Check for OSMesa header
+ AC_CHECK_HEADERS(GL/osmesa.h, ,
+ [AC_MSG_ERROR([osmesa.h not found. See INSTALL file for help.])])
+
+ dnl Check for OSMesa
+ AC_CHECK_LIB(OSMesa32, OSMesaCreateContext, ,
+ [AC_MSG_ERROR([OSMesa library not found])])
+fi
+AM_CONDITIONAL(ENABLE_OSMESA, test "$ui_osmesa" = "yes")
+
if (test "$ui_glut" = "yes"); then
dnl Check for GLUT headers first.
AC_CHECK_HEADERS(GL/glut.h, ,
@@ -472,6 +495,10 @@
AC_MSG_RESULT(***************************************************************)
AC_MSG_RESULT()
+if (test "$ui_osmesa" = "yes"); then
+ AC_MSG_RESULT([Front-End: OSMesa]);
+fi
+
if (test "$ui_glut" = "yes"); then
AC_MSG_RESULT([Front-End: GLUT]);
fi
svn diff src/celestia Makefile.am
Code: Select all
Index: src/celestia/Makefile.am
===================================================================
--- src/celestia/Makefile.am (revision 5213)
+++ src/celestia/Makefile.am (working copy)
@@ -51,13 +51,17 @@
GLUTSOURCES = glutmain.cpp
endif
+if ENABLE_OSMESA
+OSMESASOURCES = osmesamain.cpp
+endif
+
if ENABLE_THEORA
THEORASOURCES = oggtheoracapture.cpp
endif
celestia_CXXFLAGS = $(LUA_CFLAGS) $(SPICE_CFLAGS) $(THEORA_CFLAGS) -Wl,--no-as-needed
-celestia_SOURCES = $(COMMONSOURCES) $(CELXSOURCES) $(GLUTSOURCES) $(THEORASOURCES)
+celestia_SOURCES = $(COMMONSOURCES) $(CELXSOURCES) $(GLUTSOURCES) $(OSMESASOURCES) $(THEORASOURCES)
celestia_LDADD = \
$(celestiaKDELIBS) \