Results 1 to 6 of 6

Thread: again textureloading...

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2003
    Posts
    26

    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

  2. #2
    Senior Member Regular Contributor
    Join Date
    Dec 2002
    Location
    Poland
    Posts
    234

    Re: again textureloading...

    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...

    Code :
    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]);
     
    [B]			glTexImage2D(GL_TEXTURE_2D,0,sizeof(*(bitmap.data32)),bitmap.infoheader->biWidth,bitmap.infoheader->biHeight,0,GL_RGBA,GL_UNSIGNED_BYTE,bitmap.data32); [/B]
     
    			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,&amp;texture[tex_pos]);
    				glBindTexture(GL_TEXTURE_2D, texture[tex_pos]);
     
    [B]				glTexImage2D(GL_TEXTURE_2D,0,sizeof(*(bitmap.data32)),bitmap.infoheader->biWidth,bitmap.infoheader->biHeight,0,GL_RGB,GL_UNSIGNED_BYTE,bitmap.data32); [/B]
     
    				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...

    Code :
    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).]

  3. #3
    Senior Member Frequent Contributor
    Join Date
    Apr 2003
    Posts
    680

    Re: again textureloading...

    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

  4. #4
    Junior Member Newbie
    Join Date
    Jul 2003
    Posts
    26

    Re: again textureloading...

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    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 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

  5. #5
    Junior Member Newbie
    Join Date
    Jul 2003
    Posts
    26

    Re: again textureloading...

    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

  6. #6
    Senior Member Regular Contributor
    Join Date
    Dec 2002
    Location
    Poland
    Posts
    234

    Re: again textureloading...

    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'

Similar Threads

  1. textureloading
    By apocalexiz in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 08-08-2003, 07:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean