# Visual Basic > Visual Basic 6 and Earlier >  [RESOLVED] how can load png image texture in opengl?

## Black_Storm

i using this code for load texture in open gl but problem now is about load images with transparent background like as png,i found some samples in other langauage but in vb6 ?

my sample code for load texture like  :



```
Public Function LoadTextureS(ByVal Filename As String, ByVal Index As Long) As Boolean


    Dim F As Long 'Dateihandle
    Dim BmpFile As BITMAPFILEHEADER 'Fileheader-Struktur einer Bitmap
    Dim BmpInfo As BITMAPINFOHEADER 'Info-Struktur einer Bitmap
    Dim BmpRGB() As RGBQUAD 'RGB Struktur = 4 Byte = 3 Farben und 1 Reserve
    Dim BmpImageSize As Long 'Größe der Bitmap in Byte
    Dim BmpPixelSize As Integer 'Größe der Daten eines Pixels in Byte
    Dim BmpImageData() As Byte 'Array für die eigentlichen Bitmapdaten
    
    F = FreeFile 'freie Dateinummer abholen
    Open Filename For Binary As #F 'Bitmap im Binär-Modus öffnen
    
    Get #F, , BmpFile 'Fileheader-Struktur / brauchen wir aber nicht!
    Get #F, , BmpInfo 'Struktur der Bitmap


    If (BmpInfo.biBitCount < 24) Then
        ReDim BmpRGB(BmpInfo.biClrUsed) 'anpassen des Arrays
        Get #F, , BmpRGB 'einlesen der Farbdaten
        
    End If
    
    BmpPixelSize = BmpInfo.biBitCount / 8 'Anzahl der Bytes für Farbe je Pixel
    
    BmpImageSize = BmpInfo.biWidth * BmpInfo.biHeight * BmpPixelSize 'Gesamtgröße der Bitmap
    ReDim BmpImageData(BmpImageSize) 'Array an Gesamtgröße der Bitmap anpassen
    
    Get #F, , BmpImageData 'einlesen der Bitmap und schon haben wir die Daten für OpenGL im Speicher
    
    Close #F
    
    glGenTextures 1, Texture(Index)  'kreiert eine Textur
    glBindTexture glTexture2D, Texture(Index) 'Zuweisung: die Textur ist 2D
    
    glTexImage2D glTexture2D, 0, 3, BmpInfo.biWidth, BmpInfo.biHeight, 0, tiBGRExt, GL_UNSIGNED_BYTE, BmpImageData(0)
    
    
    glTexParameteri glTexture2D, tpnTextureMinFilter, GL_LINEAR
    glTexParameteri glTexture2D, tpnTextureMagFilter, GL_LINEAR
    
    Erase BmpImageData 'Speicher freigen
    Erase BmpRGB
    
End Function
```

i enabled rgba mode to like this :


```
glTexImage2D glTexture2D, 0, 3, W, H, 0, GL_RGBA, GL_UNSIGNED_BYTE, TextureImg(0, 0, 0)
```

and enabled blend mode too like this :



```
 glEnable (GL_BLEND)
 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
 Call LoadTextureS(App.Path & "\mauer.bmp", 1)
```

----------


## baka

OpenGL seems to accept DDS files.
why not use that format instead of BMP/PNG?
I mean, it should be possible to convert any format into DDS files.
did u look into it?

----------


## Black_Storm

do you have any sample in vb6 about DirectDraw Surface (dds) with opengl? , i  working on drawing on canvas and save as png and then i need to show it like as png with layered window  in opengl,that capture png and save as png solved now i have a png file and i like use it in opengl.

i am working with this module about load png too 



```
glEnable (GL_BLEND)
glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA


' 1 or 2 is index of texture till n
' -1 is orginal pixel without need apply remove special color for example rgb(0,0,0)=0 or vbBlack if need remove black color from image.
' or -1 is used for png to keep transparency orginal format
' true or false for flip vertical image if necessary


Call specialloadtextures(App.Path & "\1.png", 1, -1, True)
Call specialloadtextures(App.Path & "\2.png", 2, -1, True)
'Call specialloadtextures(App.Path & "\mauer.bmp", 3, -1)
'Call specialloadtextures(App.Path & "\wolken.bmp", 4, -1)
'Call specialloadtextures(App.Path & "\3.jpg", 5, -1)
'Call specialloadtextures(App.Path & "\1.png", 6, -1)




TextureAddFromFile is a function used with gdiplus and dib functions
Sub specialloadtextures(ByVal Filename As String, ByVal index As Long, transparentcolor As Long, Optional needreveresarray As Boolean = False)

' this TextureAddFromFile is a function from a module about read images like as png,bmp,jpg and etc and support appy remove special color  too.
    Dim gTexturePlancher As Long
    gTexturePlancher = TextureAddFromFile(Filename, index, transparentcolor, needreveresarray)
End Sub


' and then i can use indexed textures like this
glBindTexture GL_TEXTURE_2D, Texture(1)
glBindTexture GL_TEXTURE_2D, Texture(2)
```

so i can rotate or etc about that binded texture on objects and its work good like this output :



but problem is about when i run in vb6 (runtime) its work good but after make exe it jst show emtpy window like this :


i attached a demo exe with png files for test,maybe problem is from my pc,i dont know how can solve this code.whats your idea?

demo.zip

----------


## Black_Storm

i solved that problem,it was been about loadpicture command ,in office this command can load png images too but in vb6 it not worked good and needed to change to load with gdiplus


i found another module too for work TNG images too and so i can load png or tng(all format bits like as 8,16,32 and support transparency) and some other images too




```
'Call specialloadtextures(App.Path & "\1.png", 1, -1, True)
'Call specialloadtextures(App.Path & "\2.png", 2, -1, True)
'Call specialloadtextures(App.Path & "\3.tga", 1, -1, True)
'Call specialloadtextures(App.Path & "\4.tga", 2, -1, True)
'Call specialloadtextures(App.Path & "\1.bmp", 1, -1)
'Call specialloadtextures(App.Path & "\2.bmp", 2, -1)
'Call specialloadtextures(App.Path & "\1.jpg", 2, -1)
```

i resolved this thread and now i have some problem about how can add save as png function in class attached in this thread:

*how can add save as png function to this attached class for layered canvas*

----------

