View Full Version : Texturing Quadrics
I am making a bunch of quadric spheres that need to be textured. The problem is that the texture sometimes rotates with the camera, sometimes it is upside down, and there is a huge mess. I am trying to bind a texture of a person's face onto a ball, so it is asymmetrical from top to bottom. I'm pretty sure some strange call to glTexEnvf or glEnable or glTexParamteri would fix it, but I couldn't find one that works. Can anyone please help me?
Originally posted by while(fork()):
I am making a bunch of quadric spheres that need to be textured. The problem is that the texture sometimes rotates with the camera...
I am trying to bind a texture of a person's face onto a ball, so it is asymmetrical from top to bottom. I'm pretty sure some strange call to glTexEnvf or glEnable or glTexParamteri would fix it, but I couldn't find one that works.
I don't see the problem. If your texture is a shot of the whole face, then there should be no need to call any sort of GL function. Just generate the texcoords and here you are.
I am pretty sure I didn't understand the problem.
When I try to generate the texture coordinates, the front half of the face is the texture I want, but the back of the face is the same texture inverted. Basically, the front side of the sphere has a face and the back side has an upside-down face. I want to be able to cover the entire sphere with a single texture.
11-07-2003, 04:23 PM
I think you may have to rotate prior to do this.
Here is an example from a solar system project that may help:
GLubyte * loadTexture (char *fileName, int width, int height, int depth)
GLubyte *raw_bitmap, *reversed_bitmap;
int byteSize, textureSize;
byteSize = sizeof(GLubyte);
textureSize = width * height * depth * byteSize;
texFile = fopen(fileName, "rb");
if (texFile == NULL)
printf ("Texture %s not found\n", fileName);
raw_bitmap = (GLubyte *) malloc (textureSize);
reversed_bitmap = (GLubyte *) malloc (textureSize);
if ((raw_bitmap == NULL) | | (reversed_bitmap == NULL))
printf("Cannot allocate memory for texture %s\n", fileName);
fread (raw_bitmap , width * height * depth, 1 , texFile );
/* need to reverse the texture horizontally here */
int i, j, k;
for (i=0; i<height;i++)
for (j=0; j<width*depth;j+=depth)
reversed_bitmap[i*width*depth + (j+k)] =
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
Sorry, if that wasn't useful. Am learning. Good luck.
11-07-2003, 04:28 PM
Let me know if you would like to see the draw code too.
I fixed the problem. You have to make the top half of the texture the front and the bottom half the upside down of the back. Thank you for posting.
11-18-2003, 12:21 AM
I also learnt that when I generated a sphere, I also had to setup a camera angle. It turned out that my camera was positioned smack bang in the middle of the sphere I'd created, and I was effectively looking outward and through the bottom of the sphere! Everything thus appeared inverted.
The problem was easily rectified by creating a camera positioned back on the z plane. A transform would also have fixed the problem.
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.