Problem with textures when loading 3ds file

Hi
I’ve read some tutorials and tried to write a 3ds file loader. It should support models and textures, but the textures doesn’t appear. I don’t think it’s the loader that is the problem. Maybe the problem is in this area:

void createTextures(UINT textureArray[], LPSTR fileName, int textureID)
{
	AUX_RGBImageRec *pBitmap = NULL;

	if (!fileName) return;
	pBitmap = auxDIBImageLoad(fileName);

	if (pBitmap == 0) exit(0);

	glGenTextures(1, &textureArray[textureID]);
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
	glBindTexture(GL_TEXTURE_2D, textureArray[textureID]);

	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);

    gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pBitmap->sizeX, pBitmap->sizeY, GL_RGB, GL_UNSIGNED_BYTE, pBitmap->data);
	if (pBitmap)
	{
		if (pBitmap->data)
		{
			free(pBitmap->data);
		}
        free(pBitmap);
	}
}  

I’ve tried to check with glGetError() but it always returns invalid operation so I don’t know if it really creates the texture.
The whole source is here .

Thanks in advance

Wazaa

i can’t offer much help, but just in case, have you checked that you’re loading textures after a rendering context has been created? textures in gl can’t be built until this is done, if i’m not mistaken. i used to do this absentmindedly all the time.

edit: i just checked your engine. you’re loading the model prior to creating an opengl window. that’s the problem. just move that code below and you should be fine.

Here’s the one I use:

bool LoadBMPfile (TCHAR *FileName, GLuint Texture_ID)
			{
			AUX_RGBImageRec		*pTexture		= NULL;

			pTexture			= auxDIBImageLoad (FileName);

			if					(!pTexture) return false;

			glTexImage2D			(GL_PROXY_TEXTURE_2D, 0, 3, pTexture->sizeX, pTexture->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);

			glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &pTexture->sizeX);	// Ensure hardware can handle texture

			if	(pTexture->sizeX == 0)
				{
				CString			ErrorText;
				ErrorText.Format("BMP Texture File: %s is too large, or texture dimensions are not a Power of 2", FileName);
				AfxMessageBox	(ErrorText, MB_OK);
				free			(pTexture->data);
				free			(pTexture);
				return			false;
				}
			else
				{
				glBindTexture	(GL_TEXTURE_2D, Texture_ID);

				glTexEnvi		(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,	GL_MODULATE);

				glTexParameterf	(GL_TEXTURE_2D,	GL_TEXTURE_WRAP_S,		GL_REPEAT);
				glTexParameterf	(GL_TEXTURE_2D,	GL_TEXTURE_WRAP_T,		GL_REPEAT);
				glTexParameterf	(GL_TEXTURE_2D,	GL_TEXTURE_MAG_FILTER,	GL_NEAREST);
				glTexParameterf	(GL_TEXTURE_2D,	GL_TEXTURE_MIN_FILTER,	GL_NEAREST);

				glPixelStorei	(GL_UNPACK_ALIGNMENT,	1);
				glPixelStorei	(GL_UNPACK_ROW_LENGTH,	0);
				glPixelStorei	(GL_UNPACK_SKIP_ROWS,	0);
				glPixelStorei	(GL_UNPACK_SKIP_PIXELS,	0);

				glTexImage2D	(GL_TEXTURE_2D, 0, 3, pTexture->sizeX, pTexture->sizeY, 0,  GL_RGB, GL_UNSIGNED_BYTE, pTexture->data);

				free			(pTexture->data);
				free			(pTexture);

				return			true;
				}
			}

hope it helps

Thanks a lot!
Now it works perfectly :slight_smile:

The Wazaa