Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

load unregular bitmap (vb)

This topic is 5578 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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 BITMAPFILEHEADER
Dim BitmapInfo As BITMAPINFOHEADER
Dim BitmapBits() As GLubyte
Dim 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, , BitmapHeader
Get #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, uiTexObject
glBindTexture glTexture2D, uiTexObject

' Set up any texture parameters (note
' the fourth parameter)...
glTexParameteri glTexture2D, tpnTextureWrapS, GL_REPEAT
glTexParameteri glTexture2D, tpnTextureWrapT, GL_REPEAT
glTexParameteri glTexture2D, tpnTextureMagFilter, GL_LINEAR
glTexParameteri glTexture2D, tpnTextureMinFilter, GL_LINEAR_MIPMAP_LINEAR
glTexEnvi 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]

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!