b3dglgraphics.bmx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. ' Copyright (c) 2014 Mark Mcvittie, Bruce A Henderson
  2. '
  3. ' This software is provided 'as-is', without any express or implied
  4. ' warranty. In no event will the authors be held liable for any damages
  5. ' arising from the use of this software.
  6. '
  7. ' Permission is granted to anyone to use this software for any purpose,
  8. ' including commercial applications, and to alter it and redistribute it
  9. ' freely, subject to the following restrictions:
  10. '
  11. ' 1. The origin of this software must not be misrepresented; you must not
  12. ' claim that you wrote the original software. If you use this software
  13. ' in a product, an acknowledgment in the product documentation would be
  14. ' appreciated but is not required.
  15. '
  16. ' 2. Altered source versions must be plainly marked as such, and must not be
  17. ' misrepresented as being the original software.
  18. '
  19. ' 3. This notice may not be removed or altered from any source
  20. ' distribution.
  21. '
  22. SuperStrict
  23. Rem
  24. bbdoc: GLGraphics backend for B3D.
  25. End Rem
  26. Module b3d.b3dglgraphics
  27. ModuleInfo "Version: 1.00"
  28. ModuleInfo "License: zlib/libpng"
  29. ModuleInfo "Copyright: 2014 Mark Mcvittie, Bruce A Henderson"
  30. ModuleInfo "History: 1.00 Initial Release"
  31. Import brl.systemdefault
  32. Import b3d.Openb3d
  33. Import BRL.GLMax2d
  34. Rem
  35. bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=Graphics3D">Online doc</a>
  36. about: The flags argument sets the graphics buffers (back, alpha, depth, stencil and accum).
  37. The usecanvas argument is set to true if using maxgui with a canvas context.
  38. End Rem
  39. Function Graphics3D( width%, height%, depth%=0, Mode%=0, rate%=60, flags%=-1, usecanvas%=False )
  40. 'OpenLibrary()
  41. Select flags ' buffer values: back=2, alpha=4, depth=8, stencil=16, accum=32
  42. Case -1 flags=GRAPHICS_BACKBUFFER|GRAPHICS_ALPHABUFFER|GRAPHICS_DEPTHBUFFER|GRAPHICS_STENCILBUFFER|GRAPHICS_ACCUMBUFFER
  43. Case -2 flags=GRAPHICS_BACKBUFFER|GRAPHICS_ALPHABUFFER ' 2+4
  44. Case -3 flags=GRAPHICS_BACKBUFFER|GRAPHICS_DEPTHBUFFER ' 2+8
  45. Case -4 flags=GRAPHICS_BACKBUFFER|GRAPHICS_STENCILBUFFER ' 2+16
  46. Case -5 flags=GRAPHICS_BACKBUFFER|GRAPHICS_ACCUMBUFFER ' 2+32
  47. Default flags=GRAPHICS_BACKBUFFER
  48. End Select
  49. SetGraphicsDriver( GLMax2DDriver(),flags ) ' mixed 2d/3d
  50. If usecanvas ' using a canvas context
  51. GraphicsResize( width,height )
  52. Else ' create gfx context
  53. Graphics( width,height,depth,rate,flags )
  54. EndIf
  55. _b3dDriver.GraphicsInit()
  56. Graphics3D_( width,height,depth,Mode,rate )
  57. End Function
  58. Rem
  59. bbdoc: Draw text, does not need Max2D.
  60. End Rem
  61. Function Text( x%, y%, str$ )
  62. ' set active texture to texture 0 so gldrawtext will work correctly
  63. If THardwareInfo.VBOSupport 'SMALLFIXES hack to keep non vbo GFX from crashing
  64. glActiveTextureARB(GL_TEXTURE0)
  65. glClientActiveTextureARB(GL_TEXTURE0)
  66. EndIf
  67. glDisable(GL_LIGHTING)
  68. glColor3f(1.0,1.0,1.0)
  69. ' enable blend to hide text background
  70. glEnable(GL_BLEND)
  71. GLDrawText str,x,y
  72. glDisable(GL_BLEND)
  73. glEnable(GL_LIGHTING)
  74. ' disable texture 2D - needed as gldrawtext enables it, but doesn't disable after use
  75. glDisable(GL_TEXTURE_2D)
  76. End Function