intro.bbdoc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. The graphics module provides the ability to create and 'flip' graphics objects.
  2. A graphics object represents a rectangular area you can render to. However, the graphics module
  3. does not provide any commands for actual rendering - this is left to other modules such as
  4. #max2D to implement.
  5. The graphics module maintains 2 'current' objects - the current graphics driver and the currect
  6. graphics object. To change the current graphics driver, use #SetGraphicsDriver. To change the
  7. current graphics object, use #SetGraphics.
  8. To create a graphics object, use either #Graphics or #CreateGraphics. The kind of graphics
  9. object created will depend upon the current graphics driver. For example, the following code:
  10. {{
  11. SetGraphicsDriver GLGraphicsDriver()
  12. Local g:TGraphics=CreateGraphics( 640,480,32,60,GRAPHICS_BACKBUFFER )
  13. }}
  14. Will create an OpenGL graphics object.
  15. You can 'select' this object for rendering using:
  16. {{
  17. SetGraphics g 'we can now execute OpenGL code
  18. glClearColor .5,0,1,1 'tada!
  19. glClear 'yes!
  20. Flip 'must do this as the graphics is double buffered
  21. }}
  22. One you have finished with a graphics object, use #CloseGraphics to close it.
  23. #Graphics and #CreateGraphics both accept the following parameters: @width, @height, @depth,
  24. @hertz and @flags.
  25. The @width and @height parameters specify the dimensions of the graphics, in pixels.
  26. The @depth parameter selects a pixel bit depth. This value can be 0, 16, 24 or 32 depending
  27. on the graphics modes available. A depth of 0 can be used to select 'windowed mode' graphics,
  28. while non-0 depths select 'fullscreen' graphics.
  29. The @hertz parameter selects a refresh rate, which refers to the number of times the screen
  30. refreshes per second. The refresh rates available depend on the graphics modes available,
  31. which differ from graphics card to graphics card. Note that creating graphics with an
  32. unsupported refresh rate will not fail - instead, a default refresh rate will be used.
  33. The #Graphics command can be used to achieve a fixed refresh rate. When using #Flip to
  34. present such graphics, BlitzMax will guarantee the desired refresh rate is honored regardless
  35. of the available hardware's capabilities. This is achieved by using software timing
  36. techniques when necessary.
  37. The @flags parameter can be any combination of the following:
  38. [ @Flags | @Meaning
  39. * GRAPHICS_BACKBUFFER | Create graphics with a back buffer
  40. * GRAPHICS_ALPHABUFFER | Create graphics with an alpha buffer
  41. * GRAPHICS_DEPTHBUFFER | Create graphics with a depth buffer
  42. * GRAPHICS_STENCILBUFFER | Create graphics with a stencil buffer
  43. * GRAPHICS_ACCUMBUFFER | Create graphics with an accumulation buffer
  44. ]
  45. Flags can be combined with the | (or) operator. For example, GRAPHICS_BACKBUFFER|GRAPHICS_DEPTHBUFFER
  46. can be used to create graphics which has both a back buffer and a depth buffer.
  47. Graphics created with the GRAPHICS_BACKBUFFER flag must be 'flipped' after you have finished
  48. rendering using #Flip.