Source / code snippets | | | | | Juhu Transparente Textures - its me been successful
TGAs can a 4 layer (transparentslayer) imply - XProfan can but from this TGAs no Textures produce which too yet transparent are.
For which?
walls with holes? One ball with rauer surface? Highmap via Bitmap?
or: 2D-Sprites by OGL?
light and Partikeleffekte?
now building I yet one two tools to that Save this TGAs - and then can also eachone what with begin. |
| | | | |
| | | Something like goes so... CompileMarkSeparation {$cleq}
cls
ogl(init,%hwnd,0.0,0.0,0.0,1)
ogl(posmode,1)
int tex.spaceShip=ogl.loadtex(spaceship.tex)
int tex.background=ogl(loadtexturebmp,tile4.bmp,3)
float x,y,xpos,ypos,f=1.6,fps=50,speed=0.5,wxpos,wypos
long fpsc,fpstme=gettickcount+200,ompos
while 1
fpsc+
if fpstme<gettickcount
fpstme:=fpstme+200
fps:=fpsc
fpsc:=0
endif
case mousepressed : break
oGL(Clear)
ogl(move,0,0,-3)
ogl(push)
ogl(texture,tex.background,10)
ogl(move,x-3,y-3,0)
ogl(quad,8,8)
ogl(pop)
ogl(rotate,0,0,mousex)
ogl(texture,tex.spaceShip,1)
ogl(quad,0.5,0.5)
ogl(show)
wypos:=sin((mousex+90)*0.01745329)
wxpos:=cos((mousex+90)*0.01745329)
xpos:=xpos+(wxpos-xpos)/(fps*10)
ypos:=ypos+(wypos-ypos)/(fps*10)
y:=y-ypos/(fps/speed)
x:=x-xpos/(fps/speed)
case y>f : y:=y-f
case y<f : y:=y+f
case x>f : x:=x-f
case x<f : x:=x+f
wend
end
proc ogl.LoadTEX(string fileName)
casenot fileexists(fileName) : return false
long fSiz:=filesize(fileName)
case (fSiz<4) : return false
mem mem:=fSiz
long bytesRead:=blockread(fileName,mem,0,fSiz)
casenot (bytesRead==fSiz) : return false
long iWidth=sqrt(fSiz4)
long txID=0
ogl(glGenTextures,1,addr(txID))
ogl(glBindTexture,GL_TEXTURE_2D,txID);
ogl(glEnable,GL_ALPHA_TEST)
ogl(glAlphaFunc,GL_GREATER, 0.1)
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)
ogl(gluBuild2DMipmaps,GL_TEXTURE_2D, GL_RGBA, iWidth, iWidth, GL_RGBA, GL_UNSIGNED_BYTE, mem)
dispose mem
return txID
href='./../../references-fonction/XProfan/endproc/'>endproc
CompileMarkSeparation {$cleq}
const appver=0.0.1
const apptitle=tga2texture4XProfan +appver
const Error=File lying not in the right stature to.
windowtitle apptitle
cls
string inputfile=spaceship.tga,outputfile=del$(inputfile,len(inputfile)-len(substr$(inputfile,-1,.)),len(substr$(inputfile,-1,.))+1)+.tex
print if(LoadTGA(inputfile)==true,OK,Error)
waitkey
end
proc LoadTGA(string fileName)
casenot fileexists(fileName) : return false
long fSiz:=filesize(fileName)
case (fSiz<18) : return false/*headerSize*/
mem mem:=fSiz
long bytesRead:=blockread(fileName,mem,0,fSiz)
casenot (bytesRead==fSiz) : return false
int FileType:=byte(mem,0)
int ColorMapType:=byte(mem,1)
int ImageType:=byte(mem,2)
long XX:=byte(mem,12)+byte(mem,13)*256
long YY:=byte(mem,14)+byte(mem,15)*256
long BPP:=byte(mem,16)
long ImageInfo:=byte(mem,17)
long ImageSize:=XX*YY*(BPP8)
print FileType,fileType
print ColorMapType,ColorMapType
print ImageType,ImageType
print Width,XX
print Height,YY
print BPP,BPP
print ImageSize,ImageSize
casenot (ImageType==2) : return false//isnt 32bit rgb uncompressed
casenot (ColorMapType==0) : return false//no support for colormapped tgas
casenot (BPP==32) : return false//only support 32bit colordepth
long x,y,front,back,i,c
int r,g,b,a
yy-
xx-
mem pdata=ImageSize
for y:=yy downto 0 do begin
for x=0 to xx do begin
c:=i*4+18
b:=byte(mem,c)
g:=byte(mem,c+1)
r:=byte(mem,c+2)
a:=byte(mem,c+3)
c:=i*4
//setpixel x,y,rgb(r,g,b)
byte pdata#,c=r
byte pdata#,c+1=g
byte pdata#,c+2=b
byte pdata#,c+3=(r+g+b)3
i+
end
locate 9,1
print 100-(y/yy*100);% konvertiert
end
dispose mem
blockwrite outputfile,pdata,0,ImageSize
dispose pdata
return true
endproc
I denk time the Topic is so slay.
(except for eingefilterte Textures but the can itself Yes so eachone yourself building) |
| | | | |
| | | og sources again maginal revised but I denk the wars... |
| | | | |
| | Frank Abbing | nicer effect! will be I sure time sometime benefit. |
| | | | |
| | | circa from 2 BMPs a .tex to create where the 2. BMP the Stencil is: CompileMarkSeparation {$cleq}
const appver=0.0.1
const apptitle=bmpbmp2texture4xprofan +appver
const fehler=Datei liegt nicht im richtigen Format vor.
windowtitle apptitle
cls
string inputStencil=C:\b.bmp,inputfile=c:\a.bmp,outputfile=del$(inputfile,len(inputfile)-len(substr$(inputfile,-1,.)),len(substr$(inputfile,-1,.))+1)+.tex
print if(bmpbmp2tex(inputfile,inputStencil)==true,OK,fehler)
waitkey
end
proc bmpbmp2tex(string fileName,fileNameStencil)
casenot fileexists(fileName) : return false
casenot fileexists(fileNameStencil) : return false
mcls 1,1
startpaint -1
loadbmp fileName,0,0;0
endpaint
case bmpx<>bmpy : return false
mcls bmpx*2,bmpy,0
startpaint -1
loadbmp fileName,0,0;0
loadbmp fileNameStencil,bmpx,0;0
endpaint
long ImageSize:=bmpx*bmpy*4
long x,y,front,back,i,c,xx=bmpx,yy=bmpy
int r,g,b,a
yy-
xx-
mem pdata=ImageSize
for y:=0 to yy do begin
startpaint -1
for x=0 to xx do begin
c:=getpixel(x,y)
r:=getRvalue(C)
g:=getGvalue(C)
b:=getBvalue(C)
a:=getrvalue(getPixel(x+xx+1,y))
c:=i*4
//setpixel x,y,rgb(r,g,b)
byte pdata#,c=r
byte pdata#,c+1=g
byte pdata#,c+2=b
byte pdata#,c+3=a
i+
end
endpaint
locate 4,1
print (y/yy*100);% konvertiert
end
blockwrite outputfile,pdata#,0,ImageSize
dispose pdata
return true
endproc
|
| | | | |
| | | this time with gefiltertem shadow... |
| | | | |
| | | .tex as highmap To xpgl: CompileMarkSeparation'URL: https://xprofan.com/intl/de/quelltexte/juhu-opengl-texturen-tga-transparente/#n
cls
const step=1
const divi=5
string inputfile="ballmap.tex",outputfile=del$(inputfile,len(inputfile)-len(substr$(inputfile,-1,".")),len(substr$(inputfile,-1,"."))+1)+".xpgl"
casenot fileexists(inputfile) : end
long fsiz=filesize(inputfile)
long mapxx=sqrt(fsiz/4),mapyy=mapxx
mem hmap=(mapxx*mapyy)
clear hmap
locate 2,1
print sizeOf(hMap)
mem mem=fsiz
blockread(inputfile,mem,0,fSiz)
long x,y,i=0
fsiz-
whileloop 0,(mapxx*mapyy)-1,step
byte hmap#,loop=byte(mem,loop*4+3)
locate 1,1
print loop
wend
print "loadin"
mapxx=mapxx\step
mapyy=mapyy\step
long fh=assign(outputfile)
rewrite fh
print #fh&,"Q;VC;";mapxx*mapyy-mapxx-mapyy
float p1,p2,p3,p4
string col,col1="0.5,0.5,0.5,1",col2="1,1,1,1"
float ex,ey
for y=0 to mapyy-1 do begin
for x=0 to mapxx-1 do begin
if col==col1
col=col2
else
col=col1
endif
p1=byte(hmap,y*mapxx+x) /divi
p2=byte(hmap,y*mapxx+(x+1)) /divi
p3=byte(hmap,(y+1)*mapxx+(x+1)) /divi
p4=byte(hmap,(y+1)*mapxx+x) /divi
ex=x-(mapxx/2)
ey=y-(mapyy/2)
print #fh&,ex,",",ey,",",p1 ,";"+col
print #fh&,ex+1,",",ey,",",p2 ,";"+col
print #fh&,ex+1,",",ey+1,",",p3 ,";"+col
print #fh&,ex,",",ey+1,",",p4 ,";"+col
end
if col==col1
col=col2
else
col=col1
endif
locate 3,1
print y
end
close fh
print "ok"
waitkey
dispose mem
dispose hmap
end
|
| | | | |
| | funkheld | Hmmm.., here comes The Error Message "Variable twice declared : HMAP&" at kompilieren with XPSE.
greeting |
| | | | |
| | funkheld |
{$cleq} const appver="0.0.1" const apptitle="tga2texture4XProfan "+appver const fehler="Datei lying not right stature to." windowtitle apptitle cls string inputfile="spaceship.tga",outputfile=del$(inputfile,len(inputfile)-len(substr$(inputfile,-1,".")),len(substr$(inputfile,-1,"."))+1)+".tex" print if(LoadTGA(inputfile)==true,"OK",Error) waitkey .........
I have now with different Programs one TGA created. it comes always The Fehlermledung "Falsches Format".
What is it with you for a TGA and welchem Program have you got it created ?
Thank you.
greeting |
| | | | |
| | | funkheld (19.11.12)
Hmmm.., here comes The Error Message "Variable twice declared : HMAP&" at kompilieren with XPSE.
greeting
my Error -
in the code fehlte one Rautezeichen -
habs korrigiert: CompileMarkSeparation'URL: https://xprofan.com/intl/de/quelltexte/juhu-opengl-texturen-tga-transparente/?q=21905&pg=-1#21905
cls
const step=1
const divi=5
string inputfile="ballmap.tex",outputfile=del$(inputfile,len(inputfile)-len(substr$(inputfile,-1,".")),len(substr$(inputfile,-1,"."))+1)+".xpgl"
casenot fileexists(inputfile) : end
long fsiz=filesize(inputfile)
long mapxx=sqrt(fsiz/4),mapyy=mapxx
mem hmap=(mapxx*mapyy)
clear hmap
locate 2,1
print sizeOf(hMap)
mem mem=fsiz
blockread(inputfile,mem,0,fSiz)
long x,y,i=0
fsiz-
whileloop 0,(mapxx*mapyy)-1,step
byte hmap#,loop=byte(mem,loop*4+3)
locate 1,1
print loop
wend
print "loadin"
mapxx=mapxx\step
mapyy=mapyy\step
long fh=assign(outputfile)
rewrite fh
print #fh&,"Q;VC;";mapxx*mapyy-mapxx-mapyy
float p1,p2,p3,p4
string col,col1="0.5,0.5,0.5,1",col2="1,1,1,1"
float ex,ey
for y=0 to mapyy-1 do begin
for x=0 to mapxx-1 do begin
if col==col1
col=col2
else
col=col1
endif
p1=byte(hmap,y*mapxx+x) /divi
p2=byte(hmap,y*mapxx+(x+1)) /divi
p3=byte(hmap,(y+1)*mapxx+(x+1)) /divi
p4=byte(hmap,(y+1)*mapxx+x) /divi
ex=x-(mapxx/2)
ey=y-(mapyy/2)
print #fh&,ex,",",ey,",",p1 ,";"+col
print #fh&,ex+1,",",ey,",",p2 ,";"+col
print #fh&,ex+1,",",ey+1,",",p3 ,";"+col
print #fh&,ex,",",ey+1,",",p4 ,";"+col
end
if col==col1
col=col2
else
col=col1
endif
locate 3,1
print y
end
close fh
print "ok"
waitkey
dispose mem
dispose hmap
end
|
| | | | |
| | | funkheld (19.11.12)
What is it with you for a TGA and welchem Program have you got it created ?
it must itself circa a unkomprimierte rgba-TGA-File deal -
can z.B. with IrfanView Save. |
| | | | |
| | Sven Bader | if it someone need, I have whom 2 BMP To TEX Konverter in natves Profan Translated.
UPDATE 15.07. the Originalcode has Textures on the head set (or I had something wrong Translated)
windowtitle "2abmpbmp2texture4xprofan"
cls
Set("Decimals",2)
declare inputStencil$,inputfile$,outputfile$,front&,back&,i&,ImageSize&
declare r%,g%,b%,a%,c&,x&,y&,xx&,yy&
declare pdata#
inputStencil$ = "demo_alpha.bmp"
inputfile$ = "demo.bmp"
outputfile$ = del$(inputfile$,len(inputfile$)-len(substr$(inputfile$,-1,".")),len(substr$(inputfile$,-1,"."))+1)+".tex"
print if(bmpbmp2tex(inputfile$,inputStencil$)," OK"," Fehler")
waitkey
end
Proc bmpbmp2tex
parameters fileNameTexture$, fileNameStencil$
casenot fileexists(fileNameTexture$) : return 0
casenot fileexists(fileNameStencil$) : return 0
mcls 1,1
startpaint -1
loadbmp fileNameTexture$,0,0;0
endpaint
case %bmpx<>%bmpy : return 0
mcls %bmpx*2,%bmpy,0
startpaint -1
loadbmp fileNameTexture$,0,0;0
loadbmp fileNameStencil$,%bmpx,0;0
endpaint
ImageSize&= %bmpx * %bmpy * 4
xx& = %bmpx - 1
yy& = %bmpy - 1
dim pdata#, ImageSize&
WhileLoop 0,yy&
y& = yy& - &loop
startpaint -1
WhileLoop 0,xx&
x& = &loop
c& = getpixel(x&,y&)
r% = getRvalue(c&)
g% = getGvalue(c&)
b% = getBvalue(c&)
a% = getRvalue(getPixel(x& + xx& + 1,y&))
c& = i& * 4
byte pdata#,c& = r%
byte pdata#,c& + 1= g%
byte pdata#,c& + 2= b%
byte pdata#,c& + 3= a%
inc i&
EndWhile
endpaint
locate 2, 2
print st$(100 - y& / yy& * 100) ; "% konvertiert "
EndWhile
blockwrite outputfile$,pdata#,0,ImageSize&
dispose pdata#
return 1
Endproc
|
| | | | |
|
Zum QuelltextTopic-Options | 17.601 Views |
Themeninformationenthis Topic has 4 subscriber: |
|