SHARE
TWEET

Untitled

AmyRot Dec 4th, 2018 132 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;;I do not know who originally did the drawtexture code. Whoever you are, YOU ROCK!!! YOU SAVED MY WHOLE LIFE! NOT KIDDING!
  2. ;;Below is the original text of the drawtexture file. The only change I made to the original code is that I fixed a memory leak in alpharect, by using a global slate instead of a local slate. you can have that free of charge
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12. ;NOTE: This lib has leftover junk because it's been stripped of some functions I've remade better seperately
  13.  
  14.  
  15.  
  16. Global yrat#,guicam,desktopmesh,flaggy,GLcursoralpha#=1,GLcursorhidden=0
  17. Global glcamoffset=30000
  18. Global GLInited
  19. Const GLEnabled=1 ;so apps know if they can use these commands!!
  20. Const GLLibPresent=1 ;so apps know if they can use these commands!!
  21. Global masktext=1
  22. Global DrawTextureMesh,DrawTexturePiv
  23. Global DrawTextureMeshhidden
  24. Global lastalph#=1
  25. Global lastfilter=1
  26. Const DrawTextureMethod=1
  27. Global quadded ;remember if last drawtexture command was for a quad, so it can return the UV to 0-1 instead of the custom range
  28. Dim quadgridx(513,513)
  29. Dim quadgridy(513,513)
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38. ;TEXT PLATES
  39. Const TextAlphaFlag=2 ;2 for smooth, 4 for sharp
  40. Global texplates,maxtexplates=300
  41. Dim texplate(maxtexplates)
  42. Dim texplateimg(maxtexplates)
  43. Dim texplatew(maxtexplates)
  44. Dim texplateh(maxtexplates)
  45. Dim texplatetime(maxtexplates)
  46. Dim texplatefontfullw(maxtexplates)
  47. Dim texplatefontw(maxtexplates)
  48. Dim texplatefonth(maxtexplates)
  49. Dim texplatetext$(maxtexplates)
  50. Dim texplatefilter(maxtexplates)
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73. Function X3D#(x):Return betweengl(-1,1,Float(x)/(Float(GraphicsWidth()))):End Function
  74. Function Y3D#(y):If yrat=0 Then yrat#=Float(GraphicsHeight())/Float(GraphicsWidth())
  75. Return -betweengl(-yrat,yrat,Float(y)/(Float(GraphicsHeight()))):End Function
  76. Function directionGL#(EnX#,EnY#,OtX#,OtY#)
  77. If OtX#>EnX# And EnY#>=OtY# Then Return ATan((OtX#-EnX#)/(EnY#-OtY#))
  78. If OtX#>=EnX# And OtY#>EnY# Then Return 90+ATan((OtY#-EnY#)/(OtX#-EnX#))
  79. If EnX#>OtX# And OtY#>=EnY# Then Return 180+ATan((EnX#-OtX#)/(OtY#-EnY#))
  80. If EnX#>=OtX# And EnY#>OtY# Then Return 270+ATan((EnY#-OtY#)/(EnX#-OtX#))
  81. End Function
  82. Function distanceGL#(x1#,y1#,x2#,y2#):Return Sqr((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)):End Function
  83.  
  84.  
  85.  
  86.  
  87. Function DrawTexture(tex,x,y,alph#=1,filter=1,r=255,g=255,b=255,ang#=0,sx=0,sy=0,scx#=1,scy#=1,axisx=-1,axisy=-1,includerescaleposition=1,includerescalescale=1)
  88. If GLInited=0 Then InitGL
  89. If includerescaleposition=1
  90. x=x*rescalerx
  91. y=y*rescalery
  92. EndIf
  93. If includerescalescale=1
  94. sx=sx*rescalerx
  95. sy=sy*rescalery
  96. EndIf
  97. If axisx=-1 And axisy=-1 Then DrawTextureRaw tex,x,y,alph,filter,r,g,b,ang,sx,sy,scx,scy:Return
  98. If sx=0 Then sx=TextureWidth(tex)
  99. If sy=0 Then sy=TextureHeight(tex)
  100. If axisx=-1 Then axisx=sx/2
  101. If axisy=-1 Then axisy=sy/2
  102. x1=x+(axisx)    ;center of rotation
  103. y1=y+(axisy)
  104. x2=x+(sx/2) ;center of texture
  105. y2=y+(sy/2)
  106. dir#=directionGL(x1,y1,x2,y2):dis#=distanceGL(x1,y1,x2,y2)
  107. x=x1+(anglex2(dir+ang)*dis)
  108. y=y1+(angley2(dir+ang)*dis)
  109. x=x-(sx/2)
  110. y=y-(sy/2)
  111. DrawTextureRaw tex,x,y,alph,filter,r,g,b,ang,sx,sy,scx,scy,axisx,axisy
  112. End Function
  113.  
  114.  
  115.  
  116. Function DrawTextureRAW(tex,x,y,alph#=1,filter=1,r=255,g=255,b=255,ang#=0,sx=0,sy=0,scx#=1,scy#=1,axisx=-1,axisy=-1);,axisx=-1,axisy=-1)
  117. If tex=0 Then RuntimeError "Texture doesn't exist."
  118. ;DrawTextureMethod=1
  119. dtox=x:dtoy=y
  120. If sx=0 Then sx=TextureWidth(tex)
  121. If sy=0 Then sy=TextureHeight(tex)
  122. If camera<>0 Then HideEntity camera
  123. If cam<>0 Then HideEntity cam
  124.  
  125. If DrawTextureMethod=2 Then
  126. If ang<>0 Or scx<>1 Or scy<>1 Then
  127. If axisx=0 Then tx=x-(sx*.5) Else tx=axisx
  128. If axisy=0 Then ty=y-(sy*.5) Else ty=axisy
  129. dis#=distanceGL#(dtox,dtoy,tx,ty)
  130. If (scx*sx)=(scy*sy) Then ank=-45 Else ank=directionGL(dtox,dtoy,tx,ty)
  131. x=x+anglex2(ang+ank)*dis*scx
  132. y=y+angley2(ang+ank)*dis*scy
  133. x=x+(sx*.5)
  134. y=y+(sy*.5)
  135. EndIf
  136. EndIf
  137.  
  138. If DrawTextureMeshhidden=1 Then
  139. DrawTextureMeshhidden=0
  140. ShowEntity DrawTextureMesh
  141. msh=DrawTextureMesh
  142. srf=GetSurface(msh,1)
  143. xx#=X3D(x)
  144. yy#=Y3D(y)
  145. w#=X3D#(x+sx)-xx
  146. h#=Y3D#(y+sy)-yy
  147. VertexCoords srf,0,0,0,0
  148. VertexCoords srf,1,w,0,0
  149. VertexCoords srf,2,0,h,0
  150. VertexCoords srf,3,w,h,0
  151.     If quadded Then ;return texcoords to normal after the drawtexturequad command has messed with them
  152.     lo#=.0056-.0008
  153.     hi#=1.0033
  154.     VertexTexCoords srf,0,lo,lo
  155.     VertexTexCoords srf,1,hi,lo
  156.     VertexTexCoords srf,2,lo,hi
  157.     VertexTexCoords srf,3,hi,hi
  158.     EndIf
  159. Else
  160. datex=DrawTextureMesh
  161. msh=CreateMesh():srf=CreateSurface(msh)
  162. DrawTextureMesh=msh
  163. xx#=X3D(x)
  164. yy#=Y3D(y)
  165. w#=X3D#(x+sx)-xx
  166. h#=Y3D#(y+sy)-yy
  167. lo#=.0056-.0008
  168. hi#=1.0033
  169. v1=AddVertex(srf,0,0,0,lo,lo)
  170. v2=AddVertex(srf,w,0,0,hi,lo)
  171. v3=AddVertex(srf,0,h,0,lo,hi)
  172. v4=AddVertex(srf,w,h,0,hi,hi)
  173. AddTriangle srf,v1,v2,v3
  174. AddTriangle srf,v4,v3,v2
  175. EntityFX msh,1
  176. EntityOrder msh,-1
  177. EndIf
  178.  
  179. If DrawTexturePiv=0 Then DrawTexturePiv=CreatePivot():EntityParent msh,DrawTexturePiv,1
  180.  
  181. PositionEntity DrawTexturePiv,xx,yy+glcamoffset,0,1:PositionEntity msh,0,0,0,0
  182.  
  183. EntityTexture msh,tex,0,0
  184. If lastalph#<>alph# Then EntityAlpha msh,alph#:lastalph#=alph#
  185. If lastfilter<>filter Then EntityBlend msh,filter:lastfilter=filter
  186. EntityColor msh,r,g,b
  187.  
  188. If DrawTextureMethod=1 Then
  189. If scx<>1 Or scy<>1 Or ang<>0 Then PositionMesh msh,-(w/2),-(h/2),0
  190. If scx<>1 Or scy<>1 Then ScaleMesh msh,scx,scy,1
  191. If ang<>0 Then RotateMesh msh,0,0,-ang
  192. If scx<>1 Or scy<>1 Or ang<>0 Then PositionMesh msh,(w/2)*1,(h/2)*1,0
  193. EndIf
  194.  
  195. If DrawTextureMethod=2 Then If scx<>1 Or scy<>1 Then ScaleMesh msh,scx,scy,1
  196. If DrawTextureMethod=2 Then If ang<>0 Then RotateMesh msh,0,0,-ang
  197.  
  198. If DrawTextureMethod=3 Or DrawTextureMethod=4 Then
  199. RotateEntity msh,0,0,-ang
  200. ScaleEntity msh,scx,scy,1
  201. MoveEntity msh,-(w/2)*scx,-(h/2)*scy,0
  202. TranslateEntity DrawTexturePiv,(w/2)*scx,(h/2)*scy,0
  203. EndIf
  204.  
  205. If DrawTextureMethod=4 Then
  206. oxx=xx:oyy=yy
  207. If ang<>0 Or scx<>1 Or scy<>1 Then
  208. xx=xx-(w*scx*.5)
  209. yy=yy-(h*scy*.5)
  210. dis#=distanceGL(oxx,oyy,xx,yy)
  211. If scx=scy Then ank=-45 Else ank=directionGL(oxx,oyy,xx,yy)
  212. xx=xx+anglex2(ang+ank)*dis
  213. yy=yy+angley2(ang+ank)*dis
  214. xx=xx+(w*scx)
  215. yy=yy+(h*scy)
  216. PositionEntity DrawTexturePiv,xx,yy,0,1
  217. EndIf
  218. EndIf
  219.  
  220. If drawtexturecrunchy=0
  221.  ShowEntity guicam:RenderWorld:UpdateGL:HideEntity guicam
  222. Else
  223.  RenderWorld:UpdateGL
  224. EndIf
  225. ;;If msh<>0 Then FreeEntity msh ;I, kate, put this in
  226. If camera<>0 Then ShowEntity camera
  227. If cam<>0 Then ShowEntity cam
  228. End Function
  229.  
  230. Global drawtexturecrunchy=0
  231. Function crunchymodeon()
  232. ShowEntity guicam
  233. drawtexturecrunchy=1
  234. End Function
  235. Function crunchymodeoff()
  236. HideEntity guicam
  237. drawtexturecrunchy=0
  238. End Function
  239.  
  240. Function AngleX2#(aa#):Return Cos(aa-90):End Function
  241. Function AngleY2#(aa#):Return Sin(aa-90):End Function
  242.  
  243.  
  244.  
  245. Function UpdateGL()
  246. If DrawTextureMesh<>0 Then If DrawTextureMeshhidden=0 Then DrawTextureMeshhidden=1:HideEntity DrawTextureMesh
  247. End Function
  248.  
  249.  
  250.  
  251. Function InitGL()
  252. glinited=1
  253. guicam=CreateCamera()
  254. PositionEntity guicam,0,glcamoffset,-1
  255. CameraRange guicam,1,20000
  256. CameraProjMode guicam,2
  257. CameraZoom guicam,1
  258. ;AmbientLight 255,255,255
  259. CameraClsMode guicam,0,0
  260. ;Dither 0
  261. End Function
  262. InitGL()
  263.  
  264.  
  265. Global whitetex=CreateTexture(2,2,1+2)
  266. Function setupwhitetexture()
  267. oldybuf=GraphicsBuffer()
  268. SetBuffer TextureBuffer(whitetex)
  269. rrr=ColorRed()
  270. ggg=ColorGreen()
  271. bbb=ColorBlue()
  272. Color 255,255,255
  273. Rect 0,0,2,2,1
  274. SetBuffer oldybuf
  275. Color rrr,ggg,bbb
  276. End Function
  277. setupwhitetexture()
  278.  
  279. Function AlphaRect(x,y,w,h,a#=.5,filt=1,angl#=0,includerescaleposition=0,includerescalescale=0)
  280. ;;If whitetex=0 Then
  281. ;;EndIf
  282. If includerescaleposition=1
  283. x=x*rescalerx
  284. y=y*rescalery
  285. EndIf
  286. If includerescalescale=1
  287. sx=sx*rescalerx
  288. sy=sy*rescalery
  289. EndIf
  290. DrawTexture whitetex,x,y,a,filt,ColorRed(),ColorGreen(),ColorBlue(),angl,w,h,1,1
  291. End Function
  292.  
  293.  
  294. Function betweenglgl#(v1#,v2#,t#):dif#=v2-v1:Return v1+(dif*t):End Function
  295.  
  296.  
  297. Function Limglgl#(vl#,lw#,up#) ; A.K.A - Clamp
  298. If vl<lw Then Return lw
  299. If vl>up Then Return up
  300. Return vl:End Function
  301.  
  302.  
  303. Function ARGBglgl(A,R,G,B):Return RGBAglgl(r,g,b,a):End Function
  304.  
  305. Function RGBAglgl(R,G,B,A=255):If a<0 Then Return (R*256*256)+(g*256)+b
  306. Return A Shl 24 Or R Shl 16 Or G Shl 8 Or B Shl 0:End Function
  307.  
  308.  
  309.  
  310.  
  311. Function GLTriangle(x1#,y1#,x2#,y2#,x3#,y3#,fill=0)
  312. If fill=0 Then Line x1,y1,x2,y2:Line x2,y2,x3,y3:Line x3,y3,x1,y1:Return
  313. If x2<x1 Then x#=x2:y#=y2:x2=x1:y2=y1:x1=x:y1=y
  314. If x3<x1 Then x#=x3:y#=y3:x3=x1:y3=y1:x1=x:y1=y
  315. If x3<x2 Then x#=x3:y#=y3:x3=x2:y3=y2:x2=x:y2=y
  316. If x1<>x3 Then slope1#=(y3-y1)/(x3-x1)
  317. length#=x2-x1
  318. If length<>0 Then slope2#=(y2-y1)/(x2-x1):For x=0 To length:Line x+x1,x*slope1+y1,x+x1,x*slope2+y1:Next
  319. y=length*slope1+y1:length=x3-x2
  320. If length<>0 Then slope3#=(y3-y2)/(x3-x2):For x=0 To length:Line x+x2,x*slope1+y,x+x2,x*slope3+y2:Next
  321. End Function
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330. Function glLim#(vl#,lw#,up#) ; A.K.A - Clamp
  331. If vl<lw Then Return lw
  332. If vl>up Then Return up
  333. Return vl:End Function
  334.  
  335.  
  336.  
  337.  
  338.  
  339.  
  340.  
  341.  
  342. Function BetweenGL#(v1#,v2#,t#):dif#=v2-v1
  343. Return v1+(dif*t)
  344. End Function
  345.  
  346. Function TexLine(dx1,dy1,dx2,dy2,th=5,tex,ignorecolour=0)
  347. dis#=distancegl(dx1,dy1,dx2,dy2)
  348. dir#=directiongl(dx1,dy1,dx2,dy2)-90
  349. bx=betweengl(dx1,dx2,.5)
  350. by=betweengl(dy1,dy2,.5)
  351. dnx=dx1:dny=dy1:dnx=dnx+(anglex2(dir)*(th/2)):dny=dny+(angley2(dir)*(th/2))
  352. If ignorecolour=0 Then DrawTexture tex,  dnx,dny,    1,1,  ColorRed(),ColorGreen(),ColorBlue(),  dir,   dis,th,   1,1,    0,0
  353. If ignorecolour<>0 Then DrawTexture tex,  dnx,dny,    1,1,  255,255,255,  dir,   dis,th,   1,1,    0,0
  354. End Function
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362.  
  363. Function DrawTextureQuad(tex,x1,y1,x2,y2,x3,y3,x4,y4,alph#=1,filter=1,r=255,g=255,b=255,ulo#=0,vlo#=0,uhi#=1,vhi#=1)
  364. quadded=1
  365. ;pass the cordinates in this order:
  366. ;  1----2
  367. ;  :    :
  368. ;  :    :
  369. ;  3----4
  370. If tex=0 Then RuntimeError "Texture doesn't exist."
  371. If GLInited=0 Then InitGL
  372. dtox=x:dtoy=y
  373. If sx=0 Then sx=TextureWidth(tex)
  374. If sy=0 Then sy=TextureHeight(tex)
  375. If camera<>0 Then HideEntity camera
  376. If cam<>0 Then HideEntity cam
  377. xx#=0
  378. yy#=0
  379. vx1#=x3d(x1)
  380. vy1#=y3d(y1)
  381. vx2#=x3d(x2)
  382. vy2#=y3d(y2)
  383. vx3#=x3d(x3)
  384. vy3#=y3d(y3)
  385. vx4#=x3d(x4)
  386. vy4#=y3d(y4)
  387.  
  388. If DrawTextureMeshhidden=1 Then ;reposition mesh
  389. DrawTextureMeshhidden=0
  390. ShowEntity DrawTextureMesh
  391. msh=DrawTextureMesh
  392. srf=GetSurface(msh,1)
  393. VertexCoords srf,0,vx1,vy1,0
  394. VertexCoords srf,1,vx2,vy2,0
  395. VertexCoords srf,2,vx3,vy3,0
  396. VertexCoords srf,3,vx4,vy4,0
  397. VertexTexCoords srf,0,ulo,vlo
  398. VertexTexCoords srf,1,uhi,vlo
  399. VertexTexCoords srf,2,ulo,vhi
  400. VertexTexCoords srf,3,uhi,vhi
  401. Else
  402. datex=DrawTextureMesh           ;create mesh in the first place
  403. msh=CreateMesh():srf=CreateSurface(msh)
  404. DrawTextureMesh=msh
  405.  
  406. ;baselo#=.0056-.0008
  407. ;basehi#=1.0033
  408. ;xlo#=betweengl(baselo,basehi,ulo)
  409. ;ylo#=betweengl(baselo,basehi,vlo)
  410. ;xhi#=betweengl(baselo,basehi,uhi)
  411. ;yhi#=betweengl(baselo,basehi,vhi)
  412. xlo#=ulo
  413. ylo#=vlo
  414. xhi#=uhi
  415. yhi#=vhi
  416.  
  417. v1=AddVertex(srf,vx1,vy1,0,xlo,ylo)
  418. v2=AddVertex(srf,vx2,vy2,0,xhi,ylo)
  419. v3=AddVertex(srf,vx3,vy3,0,xlo,yhi)
  420. v4=AddVertex(srf,vx4,vy4,0,xhi,yhi)
  421.  
  422. AddTriangle srf,v1,v2,v3
  423. AddTriangle srf,v4,v3,v2
  424. EntityFX msh,1
  425. EntityOrder msh,-1
  426. EndIf
  427. If DrawTexturePiv=0 Then DrawTexturePiv=CreatePivot():EntityParent msh,DrawTexturePiv,1
  428. PositionEntity DrawTexturePiv,xx,yy+glcamoffset,0,1:PositionEntity msh,0,0,0,0
  429. EntityTexture msh,tex,0,0
  430. If lastalph#<>alph# Then EntityAlpha msh,alph#:lastalph#=alph#
  431. If lastfilter<>filter Then EntityBlend msh,filter:lastfilter=filter
  432. EntityColor msh,r,g,b
  433. ShowEntity guicam:RenderWorld:UpdateGL:HideEntity guicam
  434. If camera<>0 Then ShowEntity camera
  435. If cam<>0 Then ShowEntity cam
  436. End Function
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449. ;draw an interpolated quad!
  450. Function DrawTextureQuadGrid(tex,x1,y1,x2,y2,x3,y3,x4,y4,A#=1,filter=1,rd=255,gr=255,bl=255,steps=5)
  451. ;pass the cordinates in this order:
  452. ;  1----2
  453. ;  :    :
  454. ;  :    :
  455. ;  3----4
  456. steps=steps+1
  457. If steps<3 Then steps=3
  458. If steps>512 Then steps=512
  459.  
  460. For x=1 To steps        ;get the grid positions
  461. For y=1 To steps
  462. twx#=Float(x-1)/Float(steps-1)
  463. twy#=Float(y-1)/Float(steps-1)
  464. dxup=betweengl(x1,x2,twx)
  465. dyup=betweengl(y1,y2,twx)
  466. dxdn=betweengl(x3,x4,twx)
  467. dydn=betweengl(y3,y4,twx)
  468. dxlf=betweengl(x1,x3,twy)
  469. dylf=betweengl(y1,y3,twy)
  470. dxrt=betweengl(x2,x4,twy)
  471. dyrt=betweengl(y2,y4,twy)
  472. quadgridx(x,y)=betweengl(dxlf,dxrt,twx)
  473. quadgridy(x,y)=betweengl(dyup,dydn,twy)
  474. Next
  475. Next
  476.  
  477.  
  478. For x=1 To steps-1      ;draw in the quad segments
  479. For y=1 To steps-1
  480. dx1=quadgridx(x,y)
  481. dy1=quadgridy(x,y)
  482. dx2=quadgridx(x+1,y)
  483. dy2=quadgridy(x+1,y)
  484. dx3=quadgridx(x,y+1)
  485. dy3=quadgridy(x,y+1)
  486. dx4=quadgridx(x+1,y+1)
  487. dy4=quadgridy(x+1,y+1)
  488. u1#=Float(x-1) / Float(steps-1)
  489. v1#=Float(y-1) / Float(steps-1)
  490. u2#=Float(x-0) / Float(steps-1)
  491. v2#=Float(y-0) / Float(steps-1)
  492. DrawTextureQuad tex,dx1,dy1,dx2,dy2,dx3,dy3,dx4,dy4,a,filter,rd,gr,bl,u1#,v1#,u2#,v2#
  493. Next
  494. Next
  495.  
  496.  
  497. End Function
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505.  
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513. Function TextureText(x,y,tx$,cx=0,cy=0,a#=1,filter=1,shadow=0,angle#=0,scalex#=1,scaley#=1,axisx=0,axisy=0)
  514. startred=ColorRed():startgreen=ColorGreen():startblue=ColorBlue()
  515.         If shadow Then
  516.         Color 0,0,0
  517.         TextureText x-2,y+3,tx$,cx,cy,a*.6,1,0,angle#,scalex#,scaley#,axisx,axisy
  518.         EndIf
  519. tw=gettexturesize(StringWidth(tx))
  520. th=gettexturesize(StringHeight(tx))
  521.  
  522. fontw=FontWidth()
  523. fonth=FontHeight()
  524. fontfullw=StringWidth(tx)
  525. If cx Then x=x-((fontfullw/2)*scalex)
  526. If cy Then y=y-((fonth/2)*scaley)
  527.         For t=1 To texplates ;see if the exact plate already exists
  528.         If texplate(t)<>0 Then
  529.         If texplatew(t)=tw And texplateh(t)=th Then
  530.         If texplatefontfullw(t)=fontfullw Then
  531.         If texplatefontw(t)=fontw And texplatefonth(t)=fonth Then
  532.         If texplatefilter(t)=filter Then
  533.         If texplatetext(t)=tx Then
  534.         clearplate=0
  535.         daplate=t
  536.         Goto drawplate
  537.         EndIf
  538.         EndIf
  539.         EndIf
  540.         EndIf
  541.         EndIf
  542.         EndIf
  543.         Next
  544. If texplates=maxtexplates Then ;no space left, so find a plate to replace
  545.     ms=MilliSecs()
  546.     For t=1 To texplates ;find a suitable existing plate thats been disused for at least 2 minutes
  547.     If texplate(t)<>0 Then
  548.     If texplatew(t)=tw And texplateh(t)=th Then
  549.     If texplatefilter(t)=filter Then
  550.     If ms-texplatetime(t)<120000 Then
  551.     clearplate=1
  552.     daplate=t
  553.     Goto makeplate
  554.     EndIf
  555.     EndIf
  556.     EndIf
  557.     EndIf
  558.     Next
  559. oldest=0:time=0 ;find the oldest and most disused plate
  560. For t=1 To texplates
  561. If texplatetime(t)>time Then oldest=t:time=texplatetime(t)
  562. Next
  563. If oldest=0 Then Color startred,startgreen,startblue:Text x,y,tx,cx,cy:Return ;couldn't find the oldest one for some reason so give up
  564. daplate=oldest
  565. If texplate(daplate)<>0 Then FreeTexture texplate(daplate):texplate(daplate)=0
  566. If texplateimg(daplate)<>0 Then FreeImage texplateimg(daplate):texplateimg(daplate)=0
  567. Goto updateplate
  568. EndIf
  569.                             texplates=texplates+1:daplate=texplates ;none found so make new one
  570.             .updateplate
  571.             texplate(daplate)=CreateTexture(tw,th,1+((filter=1)*textalphaflag)+16+32)
  572.             If filter=1 Then texplateimg(daplate)=CreateImage(tw,th)
  573. .makeplate
  574. buf=GraphicsBuffer()
  575.     If filter=2 Then ;add filter is simple
  576.     SetBuffer TextureBuffer(texplate(daplate))
  577.     If clearplate Then Color 0,0,0:Rect 0,0,tw,th,1
  578.     Color 255,255,255
  579.     Text 0,0,tx
  580.     SetBuffer buf
  581.     EndIf
  582. ;       If filter=2 Then ;multiply filter is simple (having problems with this)
  583. ;       SetBuffer TextureBuffer(texplate(daplate))
  584. ;       If clearplate Then Color 255,255,255:Rect 0,0,tw,th,1
  585. ;       Color startted,startgreen,startblue
  586. ;       Text 0,0,tx
  587. ;       SetBuffer buf
  588. ;       EndIf
  589.     If filter=1 Then ;normal filter requires a bit extra messing around with images cos blitz complicates it by not allowing text on alpha-capable textures
  590.     SetBuffer ImageBuffer(texplateimg(daplate))
  591.     If clearplate Then Color 0,0,0:Rect 0,0,tw,th,1
  592.     Color 255,255,255
  593.     Text 0,0,tx
  594.     SetBuffer buf
  595.     LockBuffer ImageBuffer(texplateimg(daplate))
  596.     LockBuffer TextureBuffer(texplate(daplate))
  597.     For dx=0 To tw-1
  598.     For dy=0 To th-1
  599.     hue=ReadPixelFast(dx,dy,ImageBuffer(texplateimg(daplate)))
  600.     cred=(hue And $00FF0000) Shr 16
  601.     calp=cred
  602.     hue=calp Shl 24 Or 255 Shl 16 Or 255 Shl 8 Or 255
  603.     WritePixelFast dx,dy,hue,TextureBuffer(texplate(daplate))
  604.     Next
  605.     Next
  606.     UnlockBuffer ImageBuffer(texplateimg(daplate))
  607.     UnlockBuffer TextureBuffer(texplate(daplate))
  608.     EndIf
  609. .drawplate
  610. texplatew(daplate)=tw
  611. texplateh(daplate)=th
  612. texplatefontfullw(daplate)=fontfullw
  613. texplatefontw(daplate)=fontw
  614. texplatefonth(daplate)=fonth
  615. texplatetext(daplate)=tx
  616. texplatefilter(daplate)=filter
  617. texplatetime(daplate)=MilliSecs()
  618. If filter=2 Then filter=3
  619. drawtexture texplate(daplate),x,y,a,filter,startred,startgreen,startblue,angle#,0,0,scalex#,scaley#,axisx,axisy
  620. Color startred,startgreen,startblue
  621. End Function
  622.  
  623.  
  624.  
  625. Function GetTextureSize(s) ;returns the smallest texture size that will encompass the given size.
  626. power=2^18:oldpower=power
  627. Repeat
  628. If s=>power Then Return oldpower
  629. oldpower=power:power=power/2
  630. Until power=1
  631. Return 1
  632. End Function
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top