Jump to content
  • Advertisement
Sign in to follow this  
hannibar

texture drawing

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

I have a problem in my program. I can't seem to use textures. I can load the texture without problem, but it won't draw. I only get a white square. Can anyone see what I am doing wrong ? Here is the relevant code :
Texture *loadTexture(char *filename){
	Texture *tex = 0;
	int t[1];

	if (STR_endsWith(filename, ".tga")){
		tex = initTexture();
		LIST_append(G->texture, tex);

		if (loadTGA(tex, filename)){
			glGenTextures(1, t);
			tex->texID = t[0];
			printf("texture id : %d\n",t[0]);

			glTexImage2D (GL_TEXTURE_2D, 0, tex->bpp/8, tex->width, tex->height, 0, tex->type, GL_UNSIGNED_BYTE, tex->imageData);
			glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
			glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
			glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
			glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

			MEM_freeN(tex->imageData);
			tex->imageData = 0;
		}
		else{
			LIST_removeLast(G->texture);
			freeTexture(tex);
		}
	}

	return tex;
}
void initGL(void){
glShadeModel(GL_SMOOTH);
glClearColor (0.8f, 0.5f, 0.2f, 1.0f);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_SCISSOR_TEST);
glClearDepth(1.0f);
}
//somewhere in the drawcode
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
tex = G->texture->first;
glBindTexture(GL_TEXTURE_2D, tex->texID);
glBegin(GL_QUADS);
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	glTexCoord2f(0.0f, 0.0f);	glVertex2i(0, 0);
	glTexCoord2f(1.0f, 0.0f);	glVertex2i(64, 0);
	glTexCoord2f(1.0f, 1.0f);	glVertex2i(64, 64);
	glTexCoord2f(0.0f, 1.0f);	glVertex2i(0, 64);
glEnd();
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
Thanks in advance.

Share this post


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

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