Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

playmesumch00ns

Invisible textures!?

This topic is 6064 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

Hi, writing a simple model loader/viewer with not very much OpenGL experience: most of what I know comes from NeHe''s excellent tuts. I got me a simple cube, drawn & lit, and now I want to texture it. So I load up a TGA and build the textures, only no texture on the cube. Can anyone explain what is going on please?
  
typedef struct {
	//pointer to image data (up to 32 bit)

	GLubyte *imageData;
	//image colour depth in bits per pixel

	GLuint bpp;
	
	GLuint width;
	GLuint height;

	GLuint texID;
} TextureImage;


//storage for one texture

TextureImage textures[1];


bool loadTGA(TextureImage* texture, char* filename) {

									//File loading stuff goes in here


//...

//...

			

	// Build A Texture From The Data

	glGenTextures(1, &texture[0].texID);					// Generate OpenGL texture IDs


	glBindTexture(GL_TEXTURE_2D, texture[0].texID);			// Bind Our Texture

	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);	// Linear Filtered

	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);	// Linear Filtered

	
	if (texture[0].bpp==24)									// Was The TGA 24 Bits

	{
		type=GL_RGB;										// If So Set The ''type'' To GL_RGB

	}

	glTexImage2D(GL_TEXTURE_2D, 0, type, texture[0].width, texture[0].height, 0, type, GL_UNSIGNED_BYTE, texture[0].imageData);



return true;
}




bool init(void) {

	if (!loadTGA(&textures[0], "crate.tga"))
		return false;

	

	GLfloat mat_specular[] =	{1.0, 1.0, 1.0, 1.0};
	GLfloat mat_shininess[] =	{ 50.0 };
	GLfloat light_position[] =	{1.0, 1.0, 1.0, 0.0 };
	GLfloat white_light[] =		{1.0, 1.0, 1.0, 1.0};
	glClearColor(0.0, 0.0, 0.0, 0.0);
	glShadeModel(GL_SMOOTH);
	
	glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
	glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
	glBindTexture(GL_TEXTURE_2D, textures[0].texID);
	glLightfv(GL_LIGHT0, GL_POSITION, light_position);
	glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light);
	glLightfv(GL_LIGHT0, GL_SPECULAR, white_light);

	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	glEnable(GL_DEPTH_TEST);

	return true;	


}


void display(void) {
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	//glutSolidSphere(1.0, 20, 16);


	//save previous settings, in this case camera settings

	glPushMatrix();

	//xrot += 3;

	//yrot += 3;


	glTranslatef(0.0, 0.0, zpos);

	glRotatef(xrot, 1.0, 0.0, 0.0);
	glRotatef(yrot, 0.0, 1.0, 0.0);

	
	
	glCallList(mdlPtr);

	//discard the modelling transformations

	glPopMatrix();

	glutSwapBuffers();

	//glFlush();

}
  
Any help much appreciated =] ch00ns

Share this post


Link to post
Share on other sites
Advertisement

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!