Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Using GDIplus with OpenGL

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using GDIplus with OpenGL

    GDIplus enables you to create bitmaps from JPEG and PNG files.
    These can be used as textures in real time 3d graphics using
    Opengl.

    This code extract shows how to convert a jpeg, and other formats to an
    OpenGL texture that can be mapped onto 3d objects.

    You can get the full source code and demo from:
    MovingTerrain
    http://www.forum.it-berater.org/index.php?topic=87.0

    Code:
    TYPE colorARGB32
     blue  AS BYTE
     green AS BYTE
     red   AS BYTE
     alpha AS BYTE
    END TYPE
    
    UNION pix4
     whole  AS DWORD
     colors AS colorARGB32
    END UNION
    
    
    FUNCTION SetTexture(biwidth AS DWORD , biHeight AS DWORD, ref AS DWORD) AS LONG
     DIM p AS BYTE PTR
     p=STRPTR(pixmap(ref))
     glBindTexture GL_TEXTURE_2D, mapref(ref)    ' Bind Texture
     glTexParameterf GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR
     glTexParameterf GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST
     '             target      level components width height  border format   datatype      ptr to image data
     glTexImage2D GL_TEXTURE_2D, 0,      4, biWidth, biHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, @p
    END FUNCTION
    
    FUNCTION GDIP_GetTexMap (img AS STRING, ref AS DWORD ) AS STRING
       LOCAL hStatus AS LONG
       LOCAL pBitmap AS DWORD
       LOCAL pStream AS DWORD
       LOCAL pStreamo AS DWORD
       LOCAL pThumb  AS DWORD
       LOCAL strFileName AS STRING
       LOCAL pix AS pix4
       DIM thumf AS STRING:thumf=UCODE$("thumb.png")
       DIM cParamList AS EncoderParameters
       DIM cParam AS EncoderParameter
       cParamList.Count=0
       strFileName = UCODE$(img)
       hStatus = GdipLoadImageFromFile(strFileName, pBitmap)
       hStatus = GdipGetImageThumbnail ( pBitMap, 256, 256, pThumb, 0, 0 )
       ' hstatus=GdiPlusSaveImageToFile (pThumb,"thumb.png","image/png")
       hStatus = GdipImageRotateFlip(pThumb,%RotateNoneFlipY) 'invert
       'MSGBOX STR$(hstatus)
       DIM w AS DWORD PTR
       pixmap(ref)=NUL$(4*256*256)
       w=STRPTR(pixmap(ref))
       DIM x AS DWORD, y AS DWORD
       FOR y=0 TO 255
        FOR x=0 TO 255
         GdipBitmapGetPixel(pThumb, x, y, pix.whole)
         SWAP pix.colors.red, pix.colors.blue
         @w=pix.whole: INCR w
        NEXT
       NEXT
       SetTexture(256,256,ref)
       IF pBitmap THEN GdipDisposeImage(pBitmap)
       IF pThumb  THEN GdipDisposeImage(pThumb)
       FUNCTION = "ok"
    END FUNCTION
    ------------------
    Charles
    oxygenbasic.org
Working...
X