PDA

View Full Version : again textureloading...



apocalexiz
08-09-2003, 06:52 AM
hy there

now i wrote my own bmp loader (only 24/32 bit uncompressed...) w/o any error checking http://www.opengl.org/discussion_boards/ubb/wink.gif

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 http://www.opengl.org/discussion_boards/ubb/smile.gif 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 http://www.opengl.org/discussion_boards/ubb/smile.gif cause...iam very new to the topic 3d etc.

bye

apo

Orzech
08-09-2003, 10:31 AM
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,&amp;texture[tex_pos]);
glBindTexture(GL_TEXTURE_2D, texture[tex_pos]);

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

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,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,&amp;texture[tex_pos]);
glBindTexture(GL_TEXTURE_2D, texture[tex_pos]);

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

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,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).]

JanHH
08-09-2003, 09:17 PM
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

apocalexiz
08-09-2003, 10:31 PM
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.data3 2)),bitmap.infoheader->biWidth,bitmap.infoheader->biHeight,0,GL_RGBA,GL_UNSIGNED_BYTE,bitmap.data32) ; glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

no thats oke...read again http://www.opengl.org/discussion_boards/ubb/wink.gif i resize it to rgba http://www.opengl.org/discussion_boards/ubb/smile.gif and copy the data in data24 to data32 http://www.opengl.org/discussion_boards/ubb/smile.gif

but ive changed the second error...my problem is the same http://www.opengl.org/discussion_boards/ubb/wink.gif it wont work...and i dont know why...i looking over my code again and again...i cant see any error...*damn*

bye

apo

apocalexiz
08-09-2003, 10:37 PM
uh...what a ugly post...sorry http://www.opengl.org/discussion_boards/ubb/wink.gif follow the link
http://rafb.net/paste/results/Z1793014.html

oke again...as u can see i call malloc twice http://www.opengl.org/discussion_boards/ubb/smile.gif one time for the 24bit data and the second for the 32bit data http://www.opengl.org/discussion_boards/ubb/smile.gif (calulating a resize value) and than copying the 24bit data to the 32bit data http://www.opengl.org/discussion_boards/ubb/smile.gif this is all ok...ive tested it

bye

apo

Orzech
08-09-2003, 11:55 PM
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'