I can find tutorials about mapping textures to polygons specifying vertices etc. but nothing regarding how to apply a texture to a cube (or other stuff) drawn with glut (glutSolidCube).
I am doing something like:
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, decal); glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, repeat); glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, repeat); glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, nearest); glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, nearest); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexImage2D(GL_TEXTURE_2D, 0, 4, myImageWidth, myImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid *)myImage); //... glEnable(GL_TEXTURE_2D); //now draw the cube glutSolidCube(N);
Doing this I get the texture to apply to the cube but the whole cube gets the color of the first byte in the texture!
Is there any way of mapping a texture to a solid cube (and other solids) when using glutSolidCube?
No, since
glutSolidCube()does not generate texture coordinates. Fortunately, though,glutSolidCube()is easy to implement yourself and add texture coordinates. Here’s the source code toglutSolidCube()and associated functions, from http://www.opengl.org/resources/libraries/glut/:Just add in some calls to the glTexCoord* family of functions. NeHe has a good tutorial on how to get started with texture mapping with OpenGL.