求解释VB OpenGL纹理载入的原理~~急

代码如下:
Public Function LoadGLTextures() As Boolean
'Load up desired bitmaps and convert them into textures
'that can be used by OpenGL

Dim sFile As String
Dim bmFile As BITMAPFILEHEADER
Dim bmInfo As BITMAPINFOHEADER
Dim bmRGB() As RGBQUAD
Dim iFile As Integer
Dim lImageSize As Long
Dim iPixelSize As Integer
Dim baImageData() As Byte

On Error GoTo ERR_H

'Set the filename
sFile = App.Path & "\" & TEXTURE_FILE

iFile = FreeFile

Open sFile For Binary As iFile

'Read in the headers
Get #iFile, , bmFile
Get #iFile, , bmInfo

'Determine how many colors are used
If (bmInfo.biBitCount < 24) Then
'Less than 24 bits per pixel are used, so read in the color table
ReDim bmRGB(bmInfo.biClrUsed)

Get #iFile, , bmRGB
End If

'Determine how big the image is
iPixelSize = bmInfo.biBitCount / 8

lImageSize = bmInfo.biWidth * bmInfo.biHeight * iPixelSize

ReDim baImageData(lImageSize)

'Read in the image data
Get #iFile, , baImageData

Close #iFile

'Allocate space for the texture "ptr" in the array
ReDim gaTextures(1)

'Allocate the texture for OpenGL
glGenTextures 1, gaTextures(0)

'Typical Texture Generation Using Data From The Bitmap
glBindTexture glTexture2D, gaTextures(0)

'Generate The Texture
glTexParameteri glTexture2D, tpnTextureMagFilter, GL_LINEAR ' Linear Filtering
glTexParameteri glTexture2D, tpnTextureMinFilter, GL_LINEAR ' Linear Filtering
glTexImage2D glTexture2D, 0, 3, bmInfo.biWidth, bmInfo.biHeight, _
0, tiBGRExt, GL_UNSIGNED_BYTE, baImageData(0)

'Whew! Return success if we got this far
LoadGLTextures = True

EXIT_H:
Erase baImageData 'since the texture is already created, free the bitmap data
Exit Function

ERR_H:
MsgBox Err.Description
LoadGLTextures = False
Resume EXIT_H
End Function

没有具体看到位图文件怎么录入VB,进一步贴到图形上。求解释该过程。
最新回答
浮华沧桑

2024-10-22 06:33:43

fen ne?