Sign in to follow this  
blake_

Trying to load a Bitmap for a Texture.. Visual problems? (OpenGL)

Recommended Posts

After reading about glaux had memory leaks I decided to write my own function to load bitmaps and create a texture out of them... HLOCAL LMem = NULL; BITMAP Bm; BITMAPINFO Bmi; Bmpfile[TexPos] = LoadImage(NULL, (LPCSTR)Bmp, IMAGE_BITMAP, NULL, NULL, LR_LOADFROMFILE); if (!Bmpfile[TexPos]) { Error("Failed to open specified texture."); return FALSE; } GetObject(OGLDef.Bmpfile[TexPos], sizeof(BITMAP), &Bm); Bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); Bmi.bmiHeader.biWidth = Bm.bmWidth; Bmi.bmiHeader.biHeight = Bm.bmHeight; Bmi.bmiHeader.biPlanes = 1; Bmi.bmiHeader.biBitCount = Bm.bmBitsPixel; Bmi.bmiHeader.biCompression = BI_RGB; Bmi.bmiHeader.biSizeImage = ((Bm.bmWidth * Bm.bmBitsPixel + 31) & ~31) / 8 * Bm.bmHeight; Bmi.bmiHeader.biXPelsPerMeter = 0; Bmi.bmiHeader.biYPelsPerMeter = 0; Bmi.bmiHeader.biClrUsed = 0; Bmi.bmiHeader.biClrImportant = 0; LMem = LocalAlloc(LMEM_FIXED, Bmi.bmiHeader.biSizeImage); SecureZeroMemory(LMem, Bmi.bmiHeader.biSizeImage); GetDIBits(hDC, (HBITMAP)Bmpfile[TexPos], 0, Bm.bmHeight, LMem, &Bmi, DIB_RGB_COLORS); glGenTextures(1, &TexId[TexPos]); glBindTexture(GL_TEXTURE_2D, TexId[TexPos]); glTexImage2D(GL_TEXTURE_2D, 0, 3, Bm.bmWidth, Bm.bmHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, LMem); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); if (TexPos < 3) TexPos++; LocalFree(LMem); return TRUE; } But, when I get to the part of applying the texture to my QUAD, its all very messed up. The first screen shot is the actual bitmap, the second screen shot is what the texture looks like when applied onto my QUAD.. How do I fix this? http://img244.imageshack.us/my.php?image=frontyw4.png http://img244.imageshack.us/my.php?image=errorai4.png

Share this post


Link to post
Share on other sites
If anyone wants to help me tackle this I provided a link to my project.. It's compiled with Visual C++ 2008 on Windows XP Pro SP2. Files included:

front.bmp // Bitmap (Texture)
OpenGL_New.cpp // C++ file
OpenGL_Start.vcproj // VC++ 2008 Project
OpenGL_Start.exe

http://www.megafileupload.com/en/file/63302/OpenGL3D-rar.html

Anyways, thanks for any help...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this