I'm looking for a simple C
subroutine (in Linux) that takes a filename parameter and makes the 6 calls to glTexImage2D
to define a "cubemap" texture (GL_TEXTURE_CUBE_MAP
).
I'd like to be able to read a "cross layout" file (horizontal or vertical) or a "Horizontal Strip" file, so this requires various cropping operations (and possibly some rotates to match the orientation that OpenGL expects).
I'm sure this code exists, but I Googled around and only found fragments.
I stumbled on the GEGL / BABL
libraries. This looks good. A bit overkill, but it can read from a file ("gegl:load
"), crop, rotate and BABL can do various pixel format operations (to match the OpenGL GL_RGB
or GL_RGBA
format).
Also, it might be useful to read a "rectilinear" texture file and convert to the gnomic projections (I'm using MMPS for this now).
I found this Python "gimpfu" code ( http://registry.gimp.org/files/cubemap-to-dds-v0.3.py.txt ) that converts from a "cross layout" to a multi-image DDS file, so that's similar to what I want, but I'd rather not have Python code in my app. GIMP uses GEGL internally, so that's why I'm using that.
Well... I wrote a very simple "vertical strip" cubemap reader using the Freeimage library. Here's the crux:
That gets me started. I have a MMPS script that converts from rectilinear to v-strip, but I'm still fiddling with the orientations. As one book says, "The orientation of the texture coordinates of each face are counter-intuitive". I might convert the script to "nona" / PTstitcher (part of PanoTools).
FYI, there are many cubemap image file formats. V-strip is easiest to read. "Horizontal cross" seems to be popular. In general, there are {horizontal, vertical} x {cross, strip, tee} (and probably more).
I have some code that reads crosses, h-strips (it uses glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, width0) ), but it still doesn't deal with the orientations. I'll have to use something like GEGL or libpano13. Or perhaps hack an intermediate step that uses execl to run MMPS / nona / ImageMagick. Maybe libpano13 is way to go : I could generate the cubemaps on the fly from rectilinear files.
Cheers!
Update: here's the MMPS bash script to convert from a rectilinear image to v-strip (in OpenGL order and orientation) :
FYI, I found some test images ( https://www.terathon.com/wiki/index.php/Importing_a_Texture ) and the v-strip is in OpenGL order and orientation, so maybe that's typical.