English
Source / code snippets

OpenGL transparente PNG-Textures

 

Sven
Bader
example with EXE and Bilddatei:

Download

yet have I for transparente Textures Davids .tex stature uses: [...] 
I had me one Exe-Droplet built and a Header for not quadratische Textures built. The next logische step would been, the stature too yet To pack but here have I aborted and wished PNG another chance give.

I use The Prospeed function "ImportPng", I The DLL ohnehin already in my proposition use. The Pointer shows on unkomprimierte RGBA data, The I before yet turn must (The position not The Farbwerte).

Who without Prospeed try would like, ought to time here in the Forum look: [...] 

see helpful for Formatbestimmung of Bilddaten is incidentally too these Website rawpixels.net:  [...] 

self-contained of Texturformat need it too yet something work, there itself Depth-Test and Alphatransparenz here something to be at war with. in the principle should one everything first Z-sort. with Kompletter transparency has one but no Problems, sofern one these by Schwellenwert in the glAlphaFunc erzwingt

without Fix, according to Sorting are some pages correctly and some are missing:



with Fix (but abgeschnittener Semi-transparency):
oGL("glAlphaFunc", ~GL_GREATER, 0.90)
oGL("glEnable",~GL_ALPHA_TEST)



Very helped has me thereby this Posting: [...] 

not transparente PNGs can XProfan self with a Zweizeiler create:
hPic& = Create("HPIC",-1,"firefox.png")
textureHandle& = oGL("GetTextureBMP", hPic&, 2)

here my function with Beispielcode thatswhy around. Nachholfbedarf stick here yet in the Fehlerhandling and there's for may part Unsicherheiten what the enable of reaches angeht, which address changed watts.
declare prospeed&
declare texture%[5]
declare xrot!, yrot!, zrot!
declare xpos!, xspeed!, ypos!, yspeed!, zpos!, zspeed!
prospeed&=usedll("ProSpeed.dll")
DEF ImportPng(4) !"ProSpeed","ImportPng"
DEF FreePng(1) !"ProSpeed","FreePng"

Proc FlipImage

    Parameters mem&, bytes&, w&, bytesperpixel&
    Declare source#,dest#,bytes2&,step&
    step& = bytesperpixel& * w&
    Dim source#, bytes&
    Dim dest#, bytes&
    source# = mem&
    bytes& = bytes& -step&

    While (bytes& > -1)

        Char dest#, bytes2& = Char$(source#, bytes&, step&)
        bytes&  = bytes& - step&
        bytes2& = bytes2& + step&

    EndWhile

    Dispose source#
    return addr(dest#)

ENDPROC

Proc oGL_LoadPng

    Parameters textureName$
    Declare fSiz&, bytesRead&,iWidth&,iHeight&,txID&,mem#, return%,array&,maskarray&
    Declare pnghandle&,bytes&,Test#,bytesperpixel&,temp&,temp#
    oGL("Color",1,1,1,0.5)
    textureName$ = textureName$
    return% = fileexists(textureName$)

    If (return%)

        pnghandle&=ImportPng(addr(textureName$),addr(iWidth&),addr(iHeight&),addr(fSiz&))

        If (pnghandle&)

            Dim mem#, fSiz&
            temp& =  mem#'necessary?
            mem# = pnghandle&
            temp# = temp&'necessary?
            Dispose temp#'necessary?
            bytesperpixel& = fSiz& / (iWidth& * iHeight&)
            'unfortunately necessary or one save on the head:
            mem# = FlipImage(mem#,fSiz&,iWidth&,bytesperpixel&)
            txID&=0
            ogl("glGenTextures",1, addr(txID&))
            ogl("glBindTexture",~GL_TEXTURE_2D, txID&)
            Case bytesperpixel&  = 4 : ogl("glEnable",~GL_ALPHA_TEST)'RGBA
            ogl("glTexEnvi",~GL_TEXTURE_ENV, ~GL_TEXTURE_ENV_MODE, ~GL_MODULATE)
            ogl("glTexParameteri",~GL_TEXTURE_2D, ~GL_TEXTURE_MAG_FILTER, ~GL_LINEAR)
            ogl("glTexParameteri",~GL_TEXTURE_2D, ~GL_TEXTURE_MIN_FILTER, ~GL_LINEAR_MIPMAP_LINEAR)
            ogl("glMatrixMode",~GL_PROJECTION)

            If bytesperpixel&  = 4

                ogl("gluBuild2DMipmaps",~GL_TEXTURE_2D, ~GL_RGBA, iWidth&, iHeight&, ~GL_RGBA, ~GL_UNSIGNED_BYTE, mem#)

            Elseif bytesperpixel&  = 3

                ogl("gluBuild2DMipmaps",~GL_TEXTURE_2D, ~GL_RGB, iWidth&, iHeight&, ~GL_RGB, ~GL_UNSIGNED_BYTE, mem#)

            Endif

            'FreePng(pnghandle&) 'don't, there otherwise twice with dispose
            Dispose mem#

        Endif

    Endif

    Return txID&

Endproc

Proc DrawGLScene

    declare id&
    oGL("Clear")
    oGL("Color", 1, 1,1,1)
    oGL("glDisable", ~GL_CULL_FACE)'reverses draw, is really already activate
    'oGL("glEnable", ~GL_SAMPLE_ALPHA_TO_ONE)
    'without this ploy would one by the halbtransparenten Flächen according to Winkel, others Flächen time see or not
    'everything what less deckend is as 90% becomes integrally cut, these reaches make then no Proleme
    'https://stackoverflow.com/questions/5984887/opengl-z-sorting-transparency
    oGL("glAlphaFunc", ~GL_GREATER, 0.90)
    oGL("glEnable",~GL_ALPHA_TEST)
    oGL("Move", xpos!, ypos!, zpos!)
    oGL("Rotate", xrot!, yrot!, zrot!)
    oGL("Texture", texture%[0], 1)
    oGL("Cuboid", 1, 1,1)
    oGL("Show")
    xrot! = xrot! + xspeed!
    yrot! = yrot! + yspeed!
    zrot! = zrot! + zspeed!

Endproc

' Hauptprogramm
' -------------
declare hWnd&, end%
CLS 0
oGL("Init", %hWnd, 0.7,0.7,0.7,0)
oGL("Posmode", 1)
oGL("Blendmode", 1)
texture%[0] = oGL_loadPNG("firefox.png")'oGL("LoadTextureBMP","tex3.bmp",3)
texture%[1] = oGL("LoadTextureBMP","tex.bmp",3)
yspeed! = 0.5
xrot! = 35
yrot! = 45
zpos! = -2
Ende% = 0
setTimer 10' max. 100 Frames /sek.

WhileNot end%

    WaitInput

    If IsKey(27)     : end% = 1

    ElseIf Iskey(39) : yspeed! = yspeed! + .1

    ElseIf Iskey(37) : yspeed! = yspeed! - .1

    ElseIf Iskey(40) : xspeed! = xspeed! + .1

    ElseIf Iskey(38) : xspeed! = xspeed! - .1

    ElseIf Iskey(33) : zpos! = zpos! - .1

    ElseIf Iskey(65) : xpos! = xpos! - .1

    ElseIf Iskey(68) : xpos! = xpos! + .1

    ElseIf Iskey(83) : ypos! = ypos! - .1

    ElseIf Iskey(87) : ypos! = ypos! + .1

    ElseIf Iskey(34) : zpos! = zpos! + .1

    EndIf

    DrawGLScene()

EndWhile

killTimer
freedll prospeed&
End

147 kB
Bezeichnung:fixed
Hochgeladen:08/16/21
Downloadcounter59
Download
143 kB
Bezeichnung:unfixed
Hochgeladen:08/16/21
Downloadcounter63
Download
344 kB
Bezeichnung:Beispiel mit EXE und Bilddatei
Hochgeladen:08/16/21
Downloadcounter65
Download
 
08/16/21  
 



Zum Quelltext


Topictitle, max. 100 characters.
 

Systemprofile:

no Systemprofil laid out. [anlegen]

XProfan:

 Posting  Font  Smilies  ▼ 

Please register circa a Posting To verfassen.
 

Topic-Options

1.565 Views

Untitledvor 0 min.
H.Brill10/29/23
Sven Bader12/22/22
Ernst05/29/22
p.specht11/18/21
More...

Themeninformationen

this Topic has 1 subscriber:

Sven Bader (1x)


Admins  |  AGB  |  Applications  |  Authors  |  Chat  |  Privacy Policy  |  Download  |  Entrance  |  Help  |  Merchantportal  |  Imprint  |  Mart  |  Interfaces  |  SDK  |  Services  |  Games  |  Search  |  Support

One proposition all XProfan, The there's!


My XProfan
Private Messages
Own Storage Forum
Topics-Remember-List
Own Posts
Own Topics
Clipboard
Log off
 Deutsch English Français Español Italia
Translations

Privacy Policy


we use Cookies only as Session-Cookies because of the technical necessity and with us there no Cookies of Drittanbietern.

If you here on our Website click or navigate, stimmst You ours registration of Information in our Cookies on XProfan.Net To.

further Information To our Cookies and moreover, How You The control above keep, find You in ours nachfolgenden Datenschutzerklärung.


all rightDatenschutzerklärung
i want none Cookie