Jump to content
  • Advertisement


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


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);
	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);


	return true;	


void display(void) {
	//glutSolidSphere(1.0, 20, 16);

	//save previous settings, in this case camera settings


	//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);


	//discard the modelling transformations




Any help much appreciated =] ch00ns

Share this post

Link to post
Share on other sites

  • 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!