PDA

View Full Version : texturing importing/mapping



snowfell
08-07-2008, 11:59 AM
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?


bool ImportBMP(char *filename, int num_list)
{
if (filename == NULL)
{
return false;
}

texture_obj[num_list] = LoadImage(NULL,filename,IMAGE_BITMAP,0,0,LR_LOADFR OMFILE);

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_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,0,0,0,GL_RGB,G L_UNSIGNED_BYTE,texture_obj);

return true;
}

Zengar
08-07-2008, 12:23 PM
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 :)

snowfell
08-08-2008, 03:59 PM
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.

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_R GB,GL_UNSIGNED_BYTE,texture_obj);
}

Zengar
08-08-2008, 06:06 PM
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...