Sign in to follow this  
hannibar

texture drawing

Recommended Posts

hannibar    122
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this