Jump to content
  • Advertisement

Archived

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

pablo83

loading bmp texture : strange ID returned

This topic is 5197 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, My bmp loader return me a big texture ID, like 1073838576, and i think my programm doesn't work because of that. I have tested others bmp loader and the ID is 1 or 2 Can you explain me why ? Thank you
#include "main.h"
#pragma pack(1)		

int num;

struct FILE_HEADER
{
	char Magic[2];
	int FileSize;
	short Reserved0;
	short Reserved1;
	int Offset;
};

struct INFO_HEADER
{
	int Size;
	int Width;
	int Height;
	short Planes;
	short Count;
	int Compression;
	int SizeImage;
	int XpelsPM;
	int YpelsPM;
	int ClrUsed;
	int ClrImportant;
};

struct RGB
{
	unsigned char Blue;
	unsigned char Green;
	unsigned char Red;
};

int loadBmp(char *filename)
{

	FILE *bmpFile;
	struct FILE_HEADER file_header;
	struct INFO_HEADER info_header;
	struct RGB rgb;
	unsigned char *texture_mem;
	int nom[1];
	

	bmpFile = fopen(filename, "rb");	
	
	if (bmpFile == NULL)
	{
		printf("loadBmp : read error %s\n", filename);
		exit(1);
	}

	fread(&file_header, sizeof(file_header), 1, bmpFile);
	fread(&info_header, sizeof(info_header), 1, bmpFile);

	if ((file_header.Magic[0] != 'B') || (file_header.Magic[1] != 'M'))
	{
		fclose(bmpFile);
		printf("loadBmp : wrong bmp magic %s\n", filename);
		exit(1);
	}
	
	
	if ((info_header.Width % 2 != 0 )||( info_header.Height % 2 != 0))
	{
		fclose(bmpFile);
		printf("loadBmp : H or/and W error %s\n", filename);
	}


	
	if (info_header.Count != 24)
	{
		fclose(bmpFile);
		printf("loadBmp : not a 24bpp bmp file %s\n", filename);
		exit(1);
	}
		
	
	if (info_header.Compression != 0)
	{
		fclose(bmpFile);
		printf("loadBmp : bmp file use compression\n", filename);
		exit(1);
	}
		
	
	info_header.SizeImage = ( info_header.Width * info_header.Height * 3);
	
	texture_mem = (unsigned char *) malloc(info_header.SizeImage);
//	


	int a;
	for(a = 0; a < (info_header.SizeImage /3) ; a+=3)
	{
		fread(&rgb, sizeof(rgb), 1, bmpFile);
		texture_mem[a] = rgb.Red;
		texture_mem[a+1] = rgb.Green;
		texture_mem[a+2] = rgb.Blue;
	}

	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
	glGenTextures(1, nom);
	glBindTexture(GL_TEXTURE_2D, nom[0]);
	
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

	glTexImage2D(GL_TEXTURE_2D,
		     0,
		     GL_RGB,
		     info_header.Width, info_header.Height,
		     0,
		     GL_RGB,
		     GL_UNSIGNED_BYTE,
		     texture_mem);

	free(texture_mem);
	return nom[0];

	
	
}
When i use it, i have this :
printf("ID:%i\n", loadBmp("damier.bmp"));

output : IDID:1073838576

 
[edited by - pablo83 on March 5, 2004 6:52:29 AM]

Share this post


Link to post
Share on other sites
Advertisement
My code looks something like this:


GLuint textureHandle;

glGenTextures(1, &textureHandle);


Is it because you are using an ''int'' instead of a ''GLuint''?


- onebeer

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!