glodd2d.bmx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. SuperStrict
  2. Rem
  3. bbdoc: Graphics/OpenGL Odd2D
  4. about:
  5. The OpenGL Odd2D module provides an OpenGL driver for #Odd2D.
  6. End Rem
  7. Module ODD.GLOdd2D
  8. ModuleInfo "Version: 1.03"
  9. ModuleInfo "Author: David Williamson"
  10. ModuleInfo "License: Public Domain"
  11. Import ODD.Odd2D
  12. Import BRL.GLMax2D
  13. Private
  14. Global _driver:TGLOdd2DDriver
  15. Public
  16. Type TOGLImageFrame Extends TImageFrame
  17. Field glif:TGLImageFrame
  18. Method Draw( x0#,y0#,x1#,y1#,tx#,ty#,sx#,sy#,sw#,sh# )
  19. Local rot:Float=GetRotation()
  20. Local sclx:Float,scly:Float
  21. GetScale sclx,scly
  22. SetRotation rot-_odd2dDriver.tform_scr_rot
  23. SetScale sclx*_odd2dDriver.tform_scr_zoom,scly*_odd2dDriver.tform_scr_zoom
  24. _odd2dDriver.TransformPoint tx,ty
  25. tx:+_odd2dDriver.focus_x+_odd2dDriver.border_x
  26. ty:+_odd2dDriver.focus_y+_odd2dDriver.border_y
  27. glif.Draw x0,y0,x1,y1,tx,ty,sx,sy,sw,sh
  28. SetRotation rot
  29. SetScale sclx,scly
  30. End Method
  31. Method DrawPoly( xyuv:Float[],handle_x:Float,handle_y:Float,origin_x:Float,origin_y:Float )
  32. If xyuv.length<12 Or (xyuv.length Mod 4<>0) Return
  33. Local x:Float, y:Float, u:Float, v:Float
  34. glif.Draw 0,0,0,0,0,0,0,0,0,0 'KLUDGE - Note to Mr. Sibly please make EnableTex public
  35. glBegin GL_POLYGON
  36. For Local i:Int=0 Until xyuv.length Step 4
  37. x=xyuv[i+0]-handle_x
  38. y=xyuv[i+1]-handle_y
  39. u=xyuv[i+2]*glif.uscale
  40. v=xyuv[i+3]*glif.vscale
  41. glTexCoord2f u,v
  42. glVertex2f x*_driver.m2d_ix+y*_driver.m2d_iy+origin_x,x*_driver.m2d_jx+y*_driver.m2d_jy+origin_y
  43. Next
  44. glEnd
  45. End Method
  46. Function CreateFromPixmap:TOGLImageFrame( pixmap:TPixmap,flags:Int )
  47. Local frame:TOGLImageFrame=New TOGLImageFrame
  48. frame.glif=TGLImageFrame(GLMax2DDriver().CreateFrameFromPixmap(pixmap,flags))
  49. Return frame
  50. End Function
  51. End Type
  52. Type TGLOdd2DDriver Extends TOdd2DDriver
  53. Method Create:TGLOdd2DDriver()
  54. _m2ddriver=GLMax2DDriver()
  55. InitFields
  56. If Not _m2ddriver Then Return Null Else Return Self
  57. End Method
  58. ' Method GraphicsModes:TGraphicsMode[]() Abstract
  59. Method AttachGraphics:TMax2DGraphics( widget:Byte Ptr, flags:Long )
  60. Local g:TGLGraphics=GLGraphicsDriver().AttachGraphics( widget,flags )
  61. If g Return TMax2DGraphics.Create( g,Self )
  62. End Method
  63. Method CreateGraphics:TGraphics( width:Int, height:Int ,depth:Int, hertz:Int, flags:Long, x:Int, y:Int )
  64. Local g:TGLGraphics=GLGraphicsDriver().CreateGraphics( width,height,depth,hertz,flags,x,y )
  65. If g Return TMax2DGraphics.Create( g,Self )
  66. End Method
  67. Method CreateRenderImageFrame:TImageFrame(width:UInt, height:UInt, flags:Int)
  68. ' TODO
  69. End Method
  70. Method SetBackBuffer()
  71. ' TODO
  72. End Method
  73. Method SetRenderImageFrame(RenderImageFrame:TImageFrame)
  74. ' TODO
  75. End Method
  76. ' Method SetGraphics( g:TGraphics ) Abstract
  77. ' Method Flip( sync ) Abstract
  78. Method CreateFrameFromPixmap:TOGLImageFrame( pixmap:TPixmap, flags:Int )
  79. Return TOGLImageFrame.CreateFromPixmap(pixmap,flags)
  80. End Method
  81. Method SetBlend( blend:Int )
  82. Super.SetBlend blend
  83. Select m2d_blend
  84. Case MOD2XBLEND
  85. glEnable GL_BLEND
  86. glBlendFunc GL_DST_COLOR,GL_SRC_COLOR
  87. glDisable GL_ALPHA_TEST
  88. End Select
  89. End Method
  90. ' Method SetAlpha( alpha# ) Abstract
  91. ' Method SetColor( red,green,blue ) Abstract
  92. ' Method SetClsColor( red,green,blue ) Abstract
  93. ' Method SetViewport( x,y,width,height ) Abstract
  94. ' Method SetTransform( xx#,xy#,yx#,yy# ) Abstract
  95. ' Method SetLineWidth( width# ) Abstract
  96. ' Method Cls() Abstract
  97. ' Method Plot( x#,y# ) Abstract
  98. ' Method DrawLine( x0#,y0#,x1#,y1#,tx#,ty# ) Abstract
  99. ' Method DrawRect( x0#,y0#,x1#,y1#,tx#,ty# ) Abstract
  100. ' Method DrawOval( x0#,y0#,x1#,y1#,tx#,ty# ) Abstract
  101. ' Method DrawPoly( xy#[],handlex#,handley#,originx#,originy# ) Abstract
  102. ' Method DrawPixmap( pixmap:TPixmap,x,y ) Abstract
  103. ' Method GrabPixmap:TPixmap( x,y,width,height ) Abstract
  104. ' Method SetResolution( width#,height# ) Abstract
  105. Method DrawPolyImage( xyuv#[],iframe:TImageFrame,handlex#,handley#,originx#,originy# )
  106. TOGLImageFrame(iframe).DrawPoly xyuv,handlex,handley,originx,originy
  107. End Method
  108. Method ToString:String()
  109. Return "OpenGL Odd2D Driver"
  110. End Method
  111. End Type
  112. Rem
  113. bbdoc: Get OpenGL Odd2D Driver
  114. about:
  115. The returned driver can be used with #SetGraphicsDriver to enable OpenGL Odd2D
  116. rendering.
  117. End Rem
  118. Function GLOdd2DDriver:TGLOdd2DDriver()
  119. If Not _driver Then
  120. _driver=New TGLOdd2DDriver.Create()
  121. EndIf
  122. Return _driver
  123. End Function