load unregular bitmap (vb)

Started by
2 comments, last by ClassifiedOne 21 years, 2 months ago
Hi, There are quite a few tutorials on using OpenGL with VB. But every tutorial used regular (i mean same width and heigt and it must be a power of 2) bitmaps. Now I found some interesting c++ code which displays a md2 file with a texture map. But this bitmap file was sized 432x142. The texture is created with glubuild2dmipmaps, which has (among other) a parameter "bitmap-data". Now how do I fill this bitmap-data? How can I load a 432x142 bitmap in Visual Basic, so that I can pass it to glubuild2dmipmaps? So I need some function like auxdibimageload() in vb. Thanks ClassifiedOne [edited by - ClassifiedOne on February 9, 2003 1:00:09 PM]
Advertisement
glubuildmipmaps first rescales the image to a power of 2 size
perhaps use devil (openil) for loading images
http://openil.sourceforge.net

http://uk.geocities.com/sloppyturds/kea/kea.html
http://uk.geocities.com/sloppyturds/gotterdammerung.html
Well, loading a bitmap yourself and making it a texture with gluBuild2DMipmaps (if that's what you're asking for, I'm not 100% that it is) in VB is simple. Code below...


    Dim BitmapHeader As BITMAPFILEHEADERDim BitmapInfo As BITMAPINFOHEADERDim BitmapBits() As GLubyteDim BitmapBitsize As Long ' Open the file to begin with...Open "C:\MyBitmap.bmp" For Binary As #1 ' Get the file's header and info...Get #1, , BitmapHeaderGet #1, , BitmapInfo ' Calculate the size of the image...BitmapBitsize = ((BitmapInfo.biHeight * BitmapInfo.biWidth) * (BitmapInfo.biBitCount / 8)) - 1 ' Allocate some space for the image...ReDim BitmapBits(BitmapBitsize) ' Read in the bitmap's bits...Get #1, , BitmapBits ' Generate a new texture object, then' bind it so that we can use it...glGenTextures 1, uiTexObjectglBindTexture glTexture2D, uiTexObject ' Set up any texture parameters (note' the fourth parameter)...glTexParameteri glTexture2D, tpnTextureWrapS, GL_REPEATglTexParameteri glTexture2D, tpnTextureWrapT, GL_REPEATglTexParameteri glTexture2D, tpnTextureMagFilter, GL_LINEARglTexParameteri glTexture2D, tpnTextureMinFilter, GL_LINEAR_MIPMAP_LINEARglTexEnvi tetTextureEnv, tenTextureEnvMode, tepModulate ' "Define" the texture...gluBuild2DMipmaps glTexture2D, 3, BitmapInfo.biWidth, BitmapInfo.biHeight, _    tiBGRExt, GL_UNSIGNED_BYTE, ByVal VarPtr(BitmapBits(0)) ' Don't forget to close the file...Close #1    

This code assumes that the file is a 24-bit bitmap (hence GLubyte), but you can modify it a little to open files of all bitsizes...

EDIT: Stupid source box ...


Coding Stuff ->  [ iNsAn1tY Games | DarkVertex | How To Do CSG | Direct3D Vs. OpenGL | Google ]
Fun Stuff    ->  [ Evil T-Shirts | Stick-Based Comedy | You're Already Here | The Best Film Reviews ]

[edited by - iNsAn1tY on February 9, 2003 11:26:07 PM]
My opinion is a recombination and regurgitation of the opinions of those around me. I bring nothing new to the table, and as such, can be safely ignored.[ Useful things - Firefox | GLee | Boost | DevIL ]
Thank you for your code, it works fine. I had a similar one, but it crashed (guess I passed some wrong GL parameter).

What would I have to modify if I wanted to load a 256 color bitmap?

Well it is not so important to me, but if you have some code to post, i''d apreciate it!

This topic is closed to new replies.

Advertisement