• Advertisement
Sign in to follow this  

Texture Mapped Quad Problem???

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

Im using c++ and win32. When i load an image into my game and create a texture out of it, map it to a quad and draw it the color comes out dark. texture Loading function:
bool CreateTexture(UINT &texture, LPSTR strFileName)
{
	if(!strFileName) 
		return false;
	tImage *pImage = NULL;
	if(strstr(strFileName, ".tga"))
	{
		pImage = LoadTGA(strFileName);
	}
	else
		return false;
	if(pImage == NULL)								
		return false;
	glGenTextures(1, &texture);
	glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
	glBindTexture(GL_TEXTURE_2D, texture);
	int textureType = GL_RGB;
	if(pImage->channels == 4)
		textureType = GL_RGBA;
	gluBuild2DMipmaps(GL_TEXTURE_2D, pImage->channels, pImage->sizeX, 
					  pImage->sizeY, textureType, GL_UNSIGNED_BYTE, pImage->data);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
	if (pImage)										// If we loaded the image
	{
		if (pImage->data)							// If there is texture data
		{
			free(pImage->data);						// Free the texture data, we don't need it anymore
		}
		free(pImage);								// Free the image structure
	}
	return true;
}

My drawing:
glEnable(GL_TEXTURE_2D);
glEnable(GL_COLOR_MATERIAL);
glBindTexture(GL_TEXTURE_2D, texarray);
glBegin(GL_QUADS);	
  glTexCoord2f(1.0f, 1.0f);
  glVertex2f(400,500);		    // Top Left
  glTexCoord2f(0.0f, 1.0f);
  glVertex2f(720,500);	    // Top Right
  glTexCoord2f(0.0f, 0.0f);
  glVertex2f(720,175);	    // Bottom Right    
  glTexCoord2f(1.0f, 0.0f);
  glVertex2f(400,175);			// Bottom Left
glEnd();
glDisable(GL_TEXTURE_2D);

I only have depth testing enabled this is the result of the image. its very dark and the picture is on the right http://gamedevza.dyndns.org/img.jpg How can i get the color to be right?

Share this post


Link to post
Share on other sites
Advertisement
I've just started with OpemGL, so I'm probably wrong, but have you tried to remove glEnable(GL_COLOR_MATERIAL);?

Share this post


Link to post
Share on other sites
Here's my reply to your previous thread:
Quote:
Original post by hahaha
If i texture map a quad, its a lot faster than glDrawPixels...Ive got a question though. If i use glDrawPixels the color of the image is perfect. If i texture map a quad the color is wrong. I enable GL_COLOR_MATERIAL,disable lighting,enable depth test. Any ideas why the color is wrong?


Do you mean color is 'wrong', as in, RGB is mixed up? (ie: The blue channel swaps with the red?), or do you mean, the colors appear imperfect (Maybe the image is being forced to 16 bit instead of 24/32 bit), or do you mean that maybe the pixel colors are being mixed because of the mipmaps?

Screenshots help (Just use photobucket or something).


And my Reply to this one:
Try setting glColor4f(1.0f,1.0f,1.0f,1.0f), right before you draw the quad.

~Zix

Share this post


Link to post
Share on other sites
You seem not to save the return value (GLint) of the gluBuild2DMipmaps anywhere.
The gluBuild2DMipmaps function returns the texture handle which is passed as a parameter to glBindTexture();

I suggest that you make your texture loading function to return the texture handle instead of bool. And if stuff goes wrong, you can return for instance -1.

Share this post


Link to post
Share on other sites
Quote:
Original post by pieslice
You seem not to save the return value (GLint) of the gluBuild2DMipmaps anywhere.
The gluBuild2DMipmaps function returns the texture handle which is passed as a parameter to glBindTexture();

I suggest that you make your texture loading function to return the texture handle instead of bool. And if stuff goes wrong, you can return for instance -1.


That's wrong, gluBuild2DMipmaps function returns a GLInt of the error code (0 means success). See gluBuild2dMipmaps reference page

You have to get texture ID using glGenTextures() function, or by managing it yourself. (He's doing it correctly by using glGenTextures(1, &texture);

The fact that his texture is showing up, but is darker than it should be, means there is an OpenGL coloring problem, or a texture loading/Initialization problem, not an ID problem.

Hope that clears things up,
~Zix

Share this post


Link to post
Share on other sites
Quote:
Original post by zix99
Here's my reply to your previous thread:
Quote:
Original post by hahaha
If i texture map a quad, its a lot faster than glDrawPixels...Ive got a question though. If i use glDrawPixels the color of the image is perfect. If i texture map a quad the color is wrong. I enable GL_COLOR_MATERIAL,disable lighting,enable depth test. Any ideas why the color is wrong?


Do you mean color is 'wrong', as in, RGB is mixed up? (ie: The blue channel swaps with the red?), or do you mean, the colors appear imperfect (Maybe the image is being forced to 16 bit instead of 24/32 bit), or do you mean that maybe the pixel colors are being mixed because of the mipmaps?

Screenshots help (Just use photobucket or something).


And my Reply to this one:
Try setting glColor4f(1.0f,1.0f,1.0f,1.0f), right before you draw the quad.

~Zix


Thanks setting glColor4f(1.0f,1.0f,1.0f,1.0f) worked!

Share this post


Link to post
Share on other sites
Quote:
Original post by zix99
That's wrong, gluBuild2DMipmaps function returns a GLInt of the error code (0 means success). See gluBuild2dMipmaps reference page

You have to get texture ID using glGenTextures() function, or by managing it yourself. (He's doing it correctly by using glGenTextures(1, &texture);

The fact that his texture is showing up, but is darker than it should be, means there is an OpenGL coloring problem, or a texture loading/Initialization problem, not an ID problem.

Hope that clears things up,
~Zix


My bad.
Been using texture manager for so long I didn't remember gluBuild2Dmipmaps from the heart!
Texture manager is one of those things that you have to write only once and you can reuse if very efficiently.

Share this post


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

  • Advertisement