Original Post
Im trying to load multiple textures with opengl under VB. Dont tell me to use c++ instead. This is for a school project!
Now once i load more then 6 or 7 tiles the game crashes.
first off i load the BMP filenames from a txt file
FichierLibre = FreeFile
Open App.Path & "\Data\Liste.cfg" For Input As FichierLibre
Do While Not EOF(FichierLibre)
Nb_Textures = Nb_Textures + 1
ReDim Preserve TabBMP(Nb_Textures)
Input #FichierLibre, TabBMP(Nb_Textures - 1)
Loop
Close FichierLibre
then in initGL i load the gltextures
If PremiereInitialisation Then
For I = 0 To Nb_Textures - 1
If Not LoadGLTextures(I) Then
InitGL = False
Exit Function
End If
Next I
PremiereInitialisation = False
End If
note that PermiereInitialisation is used to decide weither or not its the first time i load the textures.
And here is the modified version of loadgltextures
Public Function LoadGLTextures(ByVal Indice As Integer) As Boolean ''Convertit les BMP en textures pour 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
''sFile = App.Path & "\" & TEXTURE1
sFile = App.Path & "\Data\" & TabBMP(Indice)
iFile = FreeFile
Open sFile For Binary As iFile
''Lit l''entête du BMP
Get iFile, , bmFile
Get iFile, , bmInfo
''Détermine le nombre de couleurs utilisées
If (bmInfo.biBitCount < 24) Then
ReDim bmRGB(bmInfo.biClrUsed)
Get iFile, , bmRGB
End If
''Détermine la grosseur de l''image
iPixelSize = bmInfo.biBitCount / 8
lImageSize = bmInfo.biWidth * bmInfo.biHeight * iPixelSize
ReDim baImageData(lImageSize)
''Lit l''image
Get iFile, , baImageData
Close iFile
''ReDim gaTextures(1)
If PremiereInitialisation Then ReDim gaTextures(Nb_Textures)
''Positionne la texture pour OpenGL
''glGenTextures 1, gaTextures(0)
glGenTextures Indice, gaTextures(Indice)
''glBindTexture glTexture2D, gaTextures(0)
glBindTexture glTexture2D, gaTextures(Indice)
''Génère la texture
glTexParameteri glTexture2D, tpnTextureMagFilter, GL_LINEAR
glTexParameteri glTexture2D, tpnTextureMinFilter, GL_LINEAR
glTexImage2D glTexture2D, 0, 3, bmInfo.biWidth, bmInfo.biHeight, _
0, tiBGRExt, GL_UNSIGNED_BYTE, baImageData(0)
Erase baImageData
LoadGLTextures = True ''Aucune Erreur
EXIT_H:
Erase baImageData ''Puisque la texture existe déja detruit la
Exit Function
ERR_H:
MsgBox Err.Description
LoadGLTextures = False
Resume EXIT_H
End Function
Please if anyone can find the bug, i would greatly appreciate it. I need some sleep!
Thanx in advance
|RiZeUp