Skip to main content
gamedev.net
🔒 Locked

md2 texturing problem

Started by Genjix Mar 22, 2005 at 12:47 PM 0 replies 250+ views
Original Post
Genjix
Genjix
i am parsing an md2 file, and everything works fine, except texturing. on frame 0, the object is perfect. then after that frame, it turns green (green shaded texture).

void InitGL()
{
	glShadeModel(GL_SMOOTH);
	glClearColor(0 , 0 , 0 , 0);
	glClearDepth(40);
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_DEPTH_TEST);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(60 , 800/600 , 1 , 200);

	glMatrixMode(GL_MODELVIEW);
}



void LoadTexture(int texture_id , const char *tex)
{
	SDL_Surface *texture = IMG_Load(tex);

	if(texture)
        {
		/* create texture */
		glGenTextures(1, &texture_id);

		glBindTexture(GL_TEXTURE_2D, texture_id);

		/* load in texture */
		glTexImage2D(	GL_TEXTURE_2D , 0 , 3 ,
				texture->w , texture->h , 0 , GL_BGR,
				GL_UNSIGNED_BYTE , texture->pixels);

		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		
		SDL_FreeSurface(texture);
	}
	else
	{
		cerr << "error : loading texture " << tex << "\n";
	}
}



        // when drawing model, using opengl commands
	glBindTexture(GL_TEXTURE_2D, texture_id);
        // ...


i think it might be something im doing with opengl (not model parsing - lighting?), but I've looked back on some specifications and tutorials, and can't see where im going wrong. Thanks for your time.
Genjix
Genjix
whoops! i have this function to draw some test pyramids. spot the error.
void DrawPyramid(float tx , float ty , float tz,		 float rx , float ry , float rz){	glPushMatrix();		glTranslatef(tx , ty , tz);	glRotatef(rx , 1 , 0 , 0);	glRotatef(ry , 0 , 1 , 0);	glRotatef(rz , 0 , 0 , 1);	glBegin(GL_TRIANGLES);		glColor3f(0,0,1);	// back of ship		glVertex3f(-1,0,-1);		glVertex3f(1,0,-1);		glVertex3f(0,1,-1);		glColor3f(0,0,1);	// right side		glVertex3f(0,1,-1);		glVertex3f(1,0,-1);		glColor3f(1,0,0);		glVertex3f(0,0,2);				glColor3f(0,0,1);	// left side		glVertex3f(0,1,-1);		glVertex3f(-1,0,-1);		glColor3f(1,0,0);		glVertex3f(0,0,2);				glColor3f(0,1,0);	// bottom		glVertex3f(-1,0,-1);		glVertex3f(1,0,-1);		glVertex3f(0,0,2);	glEnd();	glPopMatrix();}

        // load identity matrix, position camera .etc	model.Draw();	DrawPyramid(0,0,6,0,0,0);	DrawPyramid(60,0,-200,0,0,0);	// swap buffer




































i made calls to glColor3f(0,1,0) on last loop :)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.