Archived

This topic is now archived and is closed to further replies.

texturing makes my quad black?

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

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;
}
 

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites