again textureloading...

hy there

now i wrote my own bmp loader (only 24/32 bit uncompressed…) w/o any error checking

my problem is…i loaded the bmp…generated the texture and tried to put it on a cube…but the cube always appears white…my texture is 128x128 24bit…i resized it to 32 and swapped the r and b values…

i tested the bmp loader on serveal bitmaps(reading out the information) the results where correct (comparing to the hexeditor)

if anyone is interested to help me out follow the link
http://www.rafb.net/paste/results/q1971234.html

the code isnt very well and beautiful (i think so)

but i would also prefer good hints on common errors cause…iam very new to the topic 3d etc.

bye

apo

Hi

Honestly I didn’t look very carefully at your code but I found something which may be called “suspicious”. Meaby it’s only because I didn’t spend enough time reading the code but…

if(bitmap.infoheader->biBitCount == 24)
{
bitmap.data24=malloc(size);
readBMPdata(filename,bitmap.data24,NULL,size/sizeof(*(bitmap.data24)),bitmap.fileheader->bfOffBits);

  	resize = size+(size/sizeof(*(bitmap.data24)));
  	bitmap.data32 = malloc(resize);

  	for(ctr=0; ctr < (resize/ sizeof(*(bitmap.data32)));++ctr)
  		{
  			bitmap.data32[ctr].r = bitmap.data24[ctr].b;
  			bitmap.data32[ctr].g = bitmap.data24[ctr].g;
  			bitmap.data32[ctr].b = bitmap.data24[ctr].r;
  			bitmap.data32[ctr].a = 0;
  		}

  	glGenTextures(1,&texture[tex_pos]);
  	glBindTexture(GL_TEXTURE_2D, texture[tex_pos]);

glTexImage2D(GL_TEXTURE_2D,0,sizeof(*(bitmap.data32)),bitmap.infoheader->biWidth,bitmap.infoheader->biHeight,0,GL_RGBA,GL_UNSIGNED_BYTE,bitmap.data32);

  	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
  	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
  }
  else if(bitmap.infoheader->biBitCount == 32)
  	{
  		bitmap.data32=malloc(size);
  		readBMPdata(filename,NULL,bitmap.data32,size/sizeof(*(bitmap.data24)),bitmap.fileheader->bfOffBits);

  		for(ctr=0; ctr < (((bitmap.fileheader->bfSize) - (bitmap.fileheader->bfOffBits)) / sizeof(*(bitmap.data32)));++ctr)
  		{
  			help = bitmap.data32[ctr].b;
  			bitmap.data32[ctr].b = bitmap.data32[ctr].r;
  			bitmap.data32[ctr].r = help;
  		}

  		glGenTextures(1,&texture[tex_pos]);
  		glBindTexture(GL_TEXTURE_2D, texture[tex_pos]);

glTexImage2D(GL_TEXTURE_2D,0,sizeof(*(bitmap.data32)),bitmap.infoheader->biWidth,bitmap.infoheader->biHeight,0,GL_RGB,GL_UNSIGNED_BYTE,bitmap.data32);

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

It seems that you are assigning 32-bit image (RGBA) to GL_RGB texture and 24-bit image (RGB) to GL_RGBA one. I am not sure. Just trying to help…

And something different…

glFlush();
glutSwapBuffers();

… you don’t have to call glFLush really. ASFAIK glutSwapBuffers() is enough.

OK. Good luck!

[This message has been edited by Orzech (edited 08-09-2003).]

this is indeed right, you are using 32 bit for the texture and only GL_RGB as parameter. this surely won’t work. also, you better should not assign 0 to the alpha vaules, as this is completely transparent, but rather 1.0 (or 255).

Jan

if(bitmap.infoheader-&gt;biBitCount == 24)		{			bitmap.data24=malloc(size);			readBMPdata(filename,bitmap.data24,NULL,size/sizeof(*(bitmap.data24)),bitmap.fileheader-&gt;bfOffBits);			resize = size+(size/sizeof(*(bitmap.data24)));			bitmap.data32 = malloc(resize);			for(ctr=0; ctr &lt; (resize/ sizeof(*(bitmap.data32)));++ctr)				{					bitmap.data32[ctr].r = bitmap.data24[ctr].b;					bitmap.data32[ctr].g = bitmap.data24[ctr].g;					bitmap.data32[ctr].b = bitmap.data24[ctr].r;					bitmap.data32[ctr].a = 0;				}			glGenTextures(1,&texture[tex_pos]);			glBindTexture(GL_TEXTURE_2D, texture[tex_pos]);			glTexImage2D(GL_TEXTURE_2D,0,sizeof(*(bitmap.data32)),bitmap.infoheader-&gt;biWidth,bitmap.infoheader-&gt;biHeight,0,GL_RGBA,GL_UNSIGNED_BYTE,bitmap.data32); 			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

no thats oke…read again i resize it to rgba and copy the data in data24 to data32

but ive changed the second error…my problem is the same it wont work…and i dont know why…i looking over my code again and again…i cant see any error…damn

bye

apo

uh…what a ugly post…sorry follow the link
http://rafb.net/paste/results/Z1793014.html

oke again…as u can see i call malloc twice one time for the 24bit data and the second for the 32bit data (calulating a resize value) and than copying the 24bit data to the 32bit data this is all ok…ive tested it

bye

apo

Eee… I’ll tell you that I don’t see any point why are you doing it that way. You can load BMP much simpler.
Anyway, why don’t you just use RGB for 24 bits and RGBA for 32 bits?

See ya’