Jump to content
  • Advertisement
Sign in to follow this  
b1gjo3

gluSphere texture mapping help

This topic is 3690 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Here are some snippets of all my code involving textues, i just cant seem to get the darn texture drawn on the sphere
GLUquadricObj* q;
const int numTextures = 1;
AUX_RGBImageRec* TextureImage[numTextures];	// Create Storage Space For The Texture
GLuint texture[numTextures];

AUX_RGBImageRec* LoadBMP(char *Filename)				// Loads A Bitmap Image
{
	FILE *File=NULL;									// File Handle

	if (!Filename)										// Make Sure A Filename Was Given
	{
		return NULL;									// If Not Return NULL
	}

	fopen_s(&File, Filename,"r");							// Check To See If The File Exists

	if (File)											// Does The File Exist?
	{
		fclose(File);									// Close The Handle

#ifdef _UNICODE
		return auxDIBImageLoad(ConvertCharToWide(Filename));				// Load The Bitmap And Return A Pointer
#endif

#ifdef _MBCS
		return auxDIBImageLoad(Filename);
#endif
	}

	return NULL;										// If Load Failed Return NULL
}

int LoadSolarSystem()
{
    glEnable(GL_TEXTURE_2D);

    int Status=FALSE;

    memset(TextureImage,0,sizeof(void *)*numTextures);				
    if ( (TextureImage[0]=LoadBMP("earthTexture.bmp")) )
	{   
		Status=TRUE;				
		glGenTextures(numTextures, &texture[0]);					
		for (int loop = 0; loop < numTextures; loop++)				
		{
			glBindTexture(GL_TEXTURE_2D, texture[loop]);
			glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[loop]->sizeX, TextureImage[loop]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[loop]->data);
			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
		}
		for (int loop = 0; loop < numTextures; loop++)					
		{
			if (TextureImage[loop])				
			{
				if (TextureImage[loop]->data)			
				{
					free(TextureImage[loop]->data);		
				}
				free(TextureImage[loop]);			
			}
		}
	}

	q = gluNewQuadric();		
	gluQuadricDrawStyle(q, GLU_FILL);
	gluQuadricTexture(q, GL_TRUE);						

	glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
	glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
	return Status;							
}

void ThreeDSolarSystem(float xOrig, float yOrig, float zOrig, VirtualEye eye, bool backwards)
{
//....

	//earth
	glPushMatrix();
	glColor3f(0.25f, 0.5f, 0.75f);
	glTranslatef(xOrig, yOrig, zOrig);
	glRotatef(multiplier*threeDrot[3], 0, 1, 0);
	glTranslatef(7.0f, 0, 0);
	glRotatef(multiplier*planet_spin[2], 0, 1, 0);
	glBindTexture(GL_TEXTURE_2D, texture[0]);
	gluSphere(q, 0.4, 50, 50);
	glPopMatrix();

//....
}

what are some common mistakes that people tend to forget, or what is wrong with my code. thanks

Share this post


Link to post
Share on other sites
Advertisement
q = gluNewQuadric();
gluQuadricDrawStyle(q, GLU_FILL);
gluQuadricTexture(q, GL_TRUE);
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);



You are calling gluQuadricTexture(q, GL_TRUE); which generates the texcoords.
I'm not sure why you are calling
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP)
since you aren't enabling it.

Also, isn't there an example somewhere for you to try?

Share this post


Link to post
Share on other sites
there are tons of examples, but I think there is probably something very small wrong with the whole project that im overlooking. So if i get rid of those 2 lines it should be expected to work?

[Edited by - b1gjo3 on November 3, 2008 9:36:04 AM]

Share this post


Link to post
Share on other sites
i got it working finally, but for some reason my textures are being drawn sideways? I have an earth texture and the polar caps are showing on the left and right sides, when they should be on top and bottom.

what could be going wrong now?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!