Jump to content

  • Log In with Google      Sign In   
  • Create Account


Invisible textures!?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 playmesumch00ns   Members   -  Reputation: 190

Like
Likes
Like

Posted 17 October 2001 - 01:04 AM

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

Sponsor:

#2 playmesumch00ns   Members   -  Reputation: 190

Like
Likes
Like

Posted 17 October 2001 - 01:47 AM

OoOoOps.

forgot to glEnable(GL_TEXTURE_2D);

dOH!

#3 MENTAL   Members   -  Reputation: 382

Like
Likes
Like

Posted 18 October 2001 - 12:33 AM

*sigh*

MENTAL




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS