Textures from DIB

Started by
0 comments, last by _BladeRunner_ 22 years, 1 month ago
hi| i want to load bitmaps and to create a texture of them. but my code generates color mistakes in the texture. heres my loading code: int CTextureGL::CreateFromBMP(char *strFile) { FILE *fh =NULL; HBITMAP hBitmap =NULL; ZeroMemory(&m_dataDIB, sizeof(DIBSECTION)); if(!strFile) return CTEXTURE_INVALID_FILE; // try to access file fh =fopen(strFile, "r"); if(!fh) { LogFile.error("CTextureGL::CreateFromBMP() unable to access file.", CTEXTURE_INVALID_FILE); return CTEXTURE_INVALID_FILE; } // prepare file for reading fclose(fh); // open and load image file hBitmap =(HBITMAP)LoadImage(NULL, strFile, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE); if(!hBitmap) { LogFile.error("CTextureGL::CreateFromBMP() unable to load image file.", CTEXTURE_INVALID_IMAGEFILE); fh =NULL; return CTEXTURE_INVALID_IMAGEFILE; } // retrieve information about image if(!GetObject(hBitmap, sizeof(DIBSECTION), &m_dataDIB)) { LogFile.error("CTextureGL::CreateFromBMP() unable to retrieve image information. ", CTEXTURE_INVALID_IMAGEFILE); fh =NULL; hBitmap =NULL; return CTEXTURE_INVALID_IMAGEFILE; } // allocate texture memory m_texture =new GLuint[1]; // generate texture ID glGenTextures(1, m_texture); // if(!glIsTexture(m_texture[0])) // LogFile.error("CTextureGL::CreateFromBMP() no texture generated.", 0); // select texture ID glBindTexture(GL_TEXTURE_2D, m_texture[0]); // convert image to texture glTexImage2D(GL_TEXTURE_2D, 0, // 3, // color components 64, 64, // texture width, height 0, // border width GL_RGB, // color format GL_BYTE, // data format m_dataDIB.dsBm.bmBits); // pointer to image data // set texture filtering glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // done LogFile.message("CTextureGL::CreateFromBMP() texture created."); return CTEXTURE_SUCCESS; } ===== i think the problem is the specified data format. but which do i have to choose??
Advertisement
try GL_UNSIGNED_BYTE instead of GL_BYTE

cheers..

tip: try putting source in between and [ / s o u r c e ] when posting next time <img src="wink.gif" width=15 height=15 align=middle> <br><br>edit: inserted spaces in source to show up here..<br>———–<br>my quote is under construction<br><br>Edited by - mentat on March 12, 2002 11:14:39 AM
-----------my quote is under construction

This topic is closed to new replies.

Advertisement