Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: texturing importing/mapping

  1. #1
    Junior Member Newbie
    Join Date
    May 2008
    Location
    Manheim, Pa
    Posts
    23

    texturing importing/mapping

    I have just begun to start working on the texture related part of opengl and C++, and now I am having some issues getting it to work correctly. My goal here is a simple way of importing a bmp file, storing it in the program itself, then use that texture on 3d objects. I was able to put the following together, the problem is that it does work. When I try to run the following I get a invalid conversion from void to gluint, or something like that. I tried a few tricks to fix this but no luck so far. Any ideas how I can finish off this function?

    Code :
    bool ImportBMP(char *filename, int num_list)
    {
         if (filename == NULL)
         {
              return false;
         }
     
         texture_obj[num_list] = LoadImage(NULL,filename,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
     
         if (texture_obj[num_list] == NULL)
         {
              return false;
         }
     
         glGenTextures(num_list,&texture_obj);
         glBindTexture(GL_TEXTURE_2D,texture_obj);
         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,0,0,0,GL_RGB,GL_UNSIGNED_BYTE,texture_obj);
     
         return true;
    }

  2. #2
    Senior Member OpenGL Pro Zengar's Avatar
    Join Date
    Sep 2001
    Location
    Germany
    Posts
    1,932

    Re: texturing importing/mapping

    Now please read the documentation on Win32 LoadImage and OpenGL glTexImage2D functions and tell us what you are doing wrong... if you can't find the mistake, I suggest you go back to your basic programming classes

  3. #3
    Junior Member Newbie
    Join Date
    May 2008
    Location
    Manheim, Pa
    Posts
    23

    Re: texturing importing/mapping

    Ok I think I have a better understanding of what I need to do here but I don't have the answer I needed yet. I know that their is a handle for imported images, but I am having issues finding out how to use this handle to correctly a bitmap. Now I know that the last argument in glTexImage2d is incorrect but I don't know how to fix it.

    I did a bit of twicking but still not right. This function crashes the program when run. I believe thats due to the incorrect last argument in glTexImage2d.
    Code :
    bool ImportBMP(char *filename, int num_list, int width, int height)
    {
         HANDLE texture_obj;
     
         texture_obj = LoadImage(NULL,filename,IMAGE_BITMAP,width,height,LR_LOADFROMFILE);
     
         glGenTextures(1,&texture_lib[num_list]);
         glBindTexture(GL_TEXTURE_2D,texture_lib[num_list]);
         glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
         glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT); 
         glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,128,128,0,GL_RGB,GL_UNSIGNED_BYTE,texture_obj);
    }

  4. #4
    Senior Member OpenGL Pro Zengar's Avatar
    Join Date
    Sep 2001
    Location
    Germany
    Posts
    1,932

    Re: texturing importing/mapping

    Yes it is. LoadImage returns a bitmap handle, while TexImage wants a pointer to texel data. So you have to get the pointer to the bitmap data first. Now, it is at least 8 years I last used GDI, so my memory is a bit rusty, but I guess you have to use GetDIBits function to do this. There should be also an alternative way, by getting memory pointer to the resource directly and loading it yourself, but you'll have to ask some win32 specialists. At this point, your question is completely OpenGL unrelated, it is a question about how to access bitmap data under win32. Hope I could give you some pointers...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •