b3dglsdlgraphics.bmx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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: SDL GLGraphics backend for B3D.
  25. End Rem
  26. Module b3d.b3dglsdlgraphics
  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 b3d.Openb3d
  32. Import SDL.GLSDLmax2d
  33. Rem
  34. bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=Graphics3D">Online doc</a>
  35. about: The flags argument sets the graphics buffers (back, alpha, depth, stencil and accum).
  36. The usecanvas argument is set to true if using maxgui with a canvas context.
  37. End Rem
  38. Function Graphics3D( width%, height%, depth%=0, Mode%=0, rate%=60, flags%=-1, usecanvas%=False )
  39. 'OpenLibrary()
  40. Select flags ' buffer values: back=2, alpha=4, depth=8, stencil=16, accum=32
  41. Case -1 flags=GRAPHICS_BACKBUFFER|GRAPHICS_ALPHABUFFER|GRAPHICS_DEPTHBUFFER|GRAPHICS_STENCILBUFFER|GRAPHICS_ACCUMBUFFER
  42. Case -2 flags=GRAPHICS_BACKBUFFER|GRAPHICS_ALPHABUFFER ' 2+4
  43. Case -3 flags=GRAPHICS_BACKBUFFER|GRAPHICS_DEPTHBUFFER ' 2+8
  44. Case -4 flags=GRAPHICS_BACKBUFFER|GRAPHICS_STENCILBUFFER ' 2+16
  45. Case -5 flags=GRAPHICS_BACKBUFFER|GRAPHICS_ACCUMBUFFER ' 2+32
  46. Default flags=GRAPHICS_BACKBUFFER
  47. End Select
  48. SetGraphicsDriver( GLMax2DDriver(),flags ) ' mixed 2d/3d
  49. If usecanvas ' using a canvas context
  50. GraphicsResize( width,height )
  51. Else ' create gfx context
  52. Graphics( width,height,depth,rate,flags )
  53. EndIf
  54. glewInit() ' required for ARB funcs
  55. ' save the Max2D settings for later - by Oddball
  56. glPushAttrib(GL_ALL_ATTRIB_BITS)
  57. glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS)
  58. glMatrixMode(GL_MODELVIEW)
  59. glPushMatrix()
  60. glMatrixMode(GL_PROJECTION)
  61. glPushMatrix()
  62. glMatrixMode(GL_TEXTURE)
  63. glPushMatrix()
  64. glMatrixMode(GL_COLOR)
  65. glPushMatrix()
  66. Graphics3D_( width,height,depth,Mode,rate )
  67. glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL,GL_SEPARATE_SPECULAR_COLOR)
  68. glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,GL_TRUE)
  69. glClearDepth(1.0)
  70. End Function
  71. Rem
  72. bbdoc: Draw text, does not need Max2D.
  73. End Rem
  74. Function Text( x%, y%, str$ )
  75. ' set active texture to texture 0 so gldrawtext will work correctly
  76. glActiveTextureARB(GL_TEXTURE0)
  77. glClientActiveTextureARB(GL_TEXTURE0)
  78. glDisable(GL_LIGHTING)
  79. glColor3f(1.0,1.0,1.0)
  80. ' enable blend to hide text background
  81. glEnable(GL_BLEND)
  82. GLDrawText( str,x,y )
  83. glDisable(GL_BLEND)
  84. glEnable(GL_LIGHTING)
  85. ' disable texture 2D - needed as gldrawtext enables it, but doesn't disable after use
  86. glDisable(GL_TEXTURE_2D)
  87. End Function