texturing makes my quad black?

Started by
3 comments, last by clayasaurus 20 years, 4 months ago
hello i have a problem when i call this

texture(FONT_TEX, "font.png", false);
 
the call this

drawquad()
{
   glColor3f(r,g,b);
   glBegin(GL_POLYGON)
   glVertex2f(...) 
   glVertex2f(...);
   glVertex2f(...);
   glVertex2f(...);
   glEnd(); 
}
 
and go into ortho and draw my quad it appears just black without color (if i set the clear color to a non-black color) , however when i don''t call my texture() function then my quad will appear with color. why does calling my texture function make my quad black?

bool war::texture(int tnum, char *texname, bool clamp)
{
	SDL_Surface *s = pngLoad(texname);

	glBindTexture(GL_TEXTURE_2D,tnum);
	glPixelStorei(GL_UNPACK_ALIGNMENT,1);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, clamp ? GL_CLAMP_TO_EDGE : GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, clamp ? GL_CLAMP_TO_EDGE : GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); //NEAREST);
	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
	if(gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, s->w, s->h, GL_RGB, GL_UNSIGNED_BYTE, s->pixels))
	{
		cout << "texture " << tnum << " fatal: could not build mipmaps for this texture" << endl;
		return false;
	}

	SDL_FreeSurface(s);
	return true;
}
 
Advertisement
i''ve narrowed it down to where if i don''t call gluBuild2dMipmaps() there''s color in my quad again but it messes up my texture. i''m not sure why this is and am still searching for an answer somewhere.
quote:Original post by clayasaurus
drawquad(){   glColor3f(r,g,b);   glBegin(GL_POLYGON)   glVertex2f(...)    glVertex2f(...);   glVertex2f(...);   glVertex2f(...);   glEnd(); } 



You need to specify texture coordinates when drawing a textured primitive, basically. For example, this *should* work:

drawquad(){   glColor3f(r,g,b);   glBegin(GL_POLYGON)   glTexCoord2f(0.0f, 0.0f);   glVertex2f(...);   glTexCoord2f(1.0f, 0.0f);   glVertex2f(...);   glTexCoord2f(1.0f, 1.0f);   glVertex2f(...);   glTexCoord2f(0.0f, 1.0f);   glVertex2f(...);   glEnd(); }

I dont know how you''ve got your primitives set up, but you should see something outta that.. make sure you got texturing turned on with glEnable(GL_TEXTURE_2D) aswell.

Are you trying to texture the polygon or just color it? If you''re having difficulty coloring it, make sure that you call glDisable(GL_TEXTURE_2D) first.
thanks all, i didn''t know i had to disable GL_TEXTURE_2D if i just wanted to draw a colored poly. works now.

This topic is closed to new replies.

Advertisement