• Advertisement


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

Loading multiple textures

This topic is 5997 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

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)

    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 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

    Erase baImageData                   ''Puisque la texture existe déja detruit la
    Exit Function
    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

Share this post

Link to post
Share on other sites
A while ago I was a dedicated VB programmer and I did some OpenGL work in VB. Go to http://www.planet-source-code.com/vb/ and do a ''Quick Search'' (Located at top of page) for "OpenGL TGA" and you should come up with a submission I made on PSC which demonstrated loading uncompressed .TGA files in VB. If memory serves then I put all the code in a handy little class too :-) You should find the class easy to use, and all you have to do is create several instances of the class to load multiple textures. Also, the way the code is structured you should find it easy to modify the code to load .BMP files (Or any other file format for that matter). Or did I add .BMP file support too?... I can''t remember, just check it out :-)

Share this post

Link to post
Share on other sites
Oh yeah I forgot to add - if you have any problems either using my code or with code you have written, drop me an email (thegilb@hotmail.com) and I will be glad to help further :-)

Share this post

Link to post
Share on other sites
Hey thanks, Ill check ur code when i get home tonight and ill send u my code to see if u can figure it out.


Share this post

Link to post
Share on other sites

  • Advertisement