C/C++ code to generate texture coordinates for a curved surface

user664303
  • C/C++ code to generate texture coordinates for a curved surface user664303

    I have a triangular mesh of a surface curved in two directions, e.g. a sphere. It is therefore not possible to roll this surface flat (essentially specifying a mapping to U,V texture coordinates) without distorting some of the triangles. Does anyone know of a C++ library that can take the mesh as input and produce as output suitable U,V texture coordinates for each mesh vertex, such that the resulting implied texture map distorts the triangles as little as possible?

    EDIT: An example of this process is described in this paper - "Least Squares Conformal Maps for Automatic Texture Atlas Generation". I'm basically after an implementation of that, or something which does the same thing.

  • If you are using OpenGL, gluSphere does it for i.e. a sphere. Make sure to read the part with gluQuadricTexture at the bottom of the page.

  • I use UNITY although you'll have to get used to the LUA scripting in it. But manipulating geometric objects is pretty smooth with it. Hope that helps.

  • My suggestion is to have an artist make the mesh and have them play around with UV mapping it. Tools like Max and Maya have advanced projection capabilities, as well as the ability for an artist to eyeball it until it looks right.

  • So, it sounds like you don't actually want a texture atlas per se, but instead just a generalized technique for performing a UV unmapping of an arbitrary mesh. Unwrapping can be used to create texture atlases, but not all texture atlases are UV unwrappings, which I why I bring up the distinction.

    Unwrapping is a mesh parameterization problem. Specialized solutions exist for simple cases, such as spheres, but arbitrary polygonal meshes are non-trivial. That said, it is a solvable problem because most modelling tools have the capability to do this kind of unwrapping. For example, you can check out Blender's documentation on unwrapping for example (in fact, were you particularly adventurous you could even poke around in Blender's source code to check out their implementations -- but that's probably crazy talk). There's also this tool.

    Blender uses the Least-Squares Conformal unwrapping technique, which you can find several academic papers on. This paper is one of the better ones. There is also the Angle-Based Flattening technique, which is related (though older, I believe).

    This page may also be of some utility. In particular, on that page you can find the OpenNL library which provides a C++ implementation of an iterative LSCM solver (it's the only one I know of outside of perhaps a few papers that might include a pseudocode implementation).

Tags
c++ textures 3d-meshes
Related questions and answers
  • _TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glPushMatrix(); // push 3 glTranslatef(0,0,height); // spherical texture generation // this piece of code doesn't work as I intended glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); GLUquadric *tub = gluNewQuadric(); gluQuadricTexture(tub, GL_TRUE); gluDisk(tub

  • it up correctly.. heres the code: void BulletifyContinent(GLMmodel* mesh,float x,float y,float z,float scale) { btTriangleMesh* trimesh = new btTriangleMesh(); for(int t=0;t<mesh->numtriangles;++t) { GLuint index0 =3*mesh->triangles[t].vindices[0]; GLuint index1 =3*mesh->triangles[t].vindices[1]; GLuint index2 =3*mesh->triangles[t].vindices[2...; *v2 *= scale; trimesh->addTriangle( *v0, *v1, *v2 ); ///trimesh->addTriangle(mesh->triangles[t].vindices[0]*100,mesh->triangles[t].vindices[1]*100,mesh->triangles[t

  • I am making a game using OpenGL, with SDL_Image employed to load the textures. When drawn on screen, there's no alpha -- in an exact square around the opaque contents of the texture, black is drawn...); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glLoadIdentity(); ...here is my image loading function... SDL_Surface *loadImage (const char *filename, bool alpha = true) { SDL_Surface* loadedImage = NULL; SDL_Surface* zoomedImage = NULL; SDL_Surface* optimizedImage = NULL; loadedImage = IMG_Load(filename); if (loadedImage != NULL) { zoomedImage = zoomSurface

  • I'm creating an FPS game. I'm writing my own game engine. So far all the backend stuff is going great. I'd like to support md2 as the native file format for 3D Objects, but I also want to use skeletal meshes. Does anyone know if the md2 file format supports skeletal meshes? In-case you need to know, I'm going to use blender as my Mesh creation tool and C++ as my programming language... Thanks... you some help on writing a parser (see bottom of link), but the example doesn't support lighting and texture mapping (the second set of example code allows for animation). Thanks @Neverender

  • working of windows/linux/osx), I have a toggle to toggle between using the FBO(post-processing) and not. The shaders are working, but it seems the FBO didn't load the texture unit bound to it. The following is the init code for the FBO and it's texture: glGenTextures(1,&fboimg); glBindTexture(GL_TEXTURE_2D,fboimg); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexImage2D

  • tile being rendered, but I'm getting a blurred mess :S. My rendering code: glBindTexture(GL_TEXTURE_2D, texture); float texscale = 1.0f / (float)tileWidth; sourceX = sourceX / (float)tileSheetWidth...: LoadImage(string filename, bool loadingTileSheet) { SDL_Surface *LoadedImage = NULL; GLuint texture; Uint32 rmask, gmask, bmask, amask; LoadedImage = IMG_Load(filename.c_str..., bmask, amask); SDL_BlitSurface(LoadedImage, NULL, image, NULL); glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D, texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL

  • I have a 2D tile map, where each tile is marked as blocking or non-blocking. Each tile is 16x16 pixels and sub-tile movement is possible. I'm attempting to generate a navigation mesh from this data, at run-time, using C++. Is there any well known library that can be used to generate a navigation mesh, given a 2D tile map? Alternatively, is there any algorithm that can be used to intelligently generate a navigation mesh from the tile data? As far as I can tell, all of the popular solutions are aimed at 3D maps and don't perform well when given the simplified case of a 2D map.

  • glEnableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); First of all, does it look right? Second, I get access violation error "Unhandled exception at 0x01455626 in Graphics...]); glVertexPointer(3, GL_FLOAT, 0, &vertices[0]); glDrawArrays(GL_TRIANGLES, 0, vertices.size()/3); glDisableClientState(GL_VERTEX_ARRAY); // disable vertex arrays glDisableClientState(GL_TEXTURE... at the same time: glBegin(GL_TRIANGLES); for(int i = 0; i < numTriangles; i++) { MD2Triangle* triangle = triangles + i; for(int j = 0; j < 3; j++) { MD2Vertex* v1

  • Is it possible to use OpenGL purely with C instead of C++? I am wanting to make sure there won't be any problems with my using C and not C++. OpenGL does not depend on any C++ libraries right?