CreateTexture.htm 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <html>
  2. <head>
  3. <title>Blitz3D Docs</title>
  4. <link rel=stylesheet href=../css/commands.css type=text/css>
  5. </head>
  6. <body>
  7. <h1>CreateTexture ( width,height[,flags][,frames] )</h1>
  8. <h1>Parameters</h1>
  9. <table>
  10. <tr>
  11. <td>
  12. width - width of texture <br />
  13. height - height of texture <br />
  14. <br />
  15. flags (optional) - texture flag: <br />
  16. 1: Color (default) <br />
  17. 2: Alpha <br />
  18. 4: Masked <br />
  19. 8: Mipmapped <br />
  20. 16: Clamp U <br />
  21. 32: Clamp V <br />
  22. 64: Spherical environment map <br />
  23. 128: Cubic environment map <br />
  24. 256: Store texture in vram <br />
  25. 512: Force the use of high color textures <br />
  26. <br />
  27. frames (optional) - no of frames texture will have. Defaults to 1.
  28. </td>
  29. </tr>
  30. </table>
  31. <h1>Description</h1>
  32. <table>
  33. <tr>
  34. <td>
  35. Creates a texture and returns its handle. <br />
  36. <br />
  37. Width and height are the size of the texture. Note that the actual texture size may be different from the width and height requested, as different types of 3D hardware support different sizes of texture. <br />
  38. <br />
  39. The optional flags parameter allows you to apply certain effects to the texture. Flags can be added to combine two or more effects, e.g. 3 (1+2) = texture with color and alpha maps. <br />
  40. <br />
  41. Here some more detailed descriptions of the flags: <br />
  42. <br />
  43. 1: Color - colour map, what you see is what you get. <br />
  44. <br />
  45. 2: Alpha - alpha map. If an image contains an alpha map, this will be used to make certain areas of the texture transparent. Otherwise, the colour map will be used as an alpha map. With alpha maps, the dark areas always equal high-transparency, light areas equal low-transparency. <br />
  46. <br />
  47. 4: Masked - all areas of a texture coloured 0,0,0 will not be drawn to the screen. <br />
  48. <br />
  49. 8: Mipmapped - low detail versions of the texture will be used at high distance. Results in a smooth, blurred look. <br />
  50. <br />
  51. 16: Clamp u - Any part of a texture that lies outsides the U coordinates of 0-1 will not be drawn. Prevents texture-wrapping. <br />
  52. <br />
  53. 32: Clamp v - Any part of a texture that lies outsides the v coordinates of 0-1 will not be drawn. Prevents texture-wrapping. <br />
  54. <br />
  55. 64: Spherical environment map - a form of environment mapping. This works by taking a single image, and then applying it to a 3D mesh in such a way that the image appears to be reflected. When used with a texture that contains light sources, it can give some meshes such as a teapot a shiny appearance. <br />
  56. <br />
  57. 128: Cubic environment map - a form of environment mapping. Cube mapping is similar to spherical mapping, except it uses six images each representing a particular 'face' of an imaginary cube, to give the appearance of an image that perfectly reflects its surroundings. <br />
  58. <br />
  59. When creating cubic environment maps with the CreateTexture command, cubemap textures *must* be square 'power of 2' sizes. See the <a class=small href=../3d_commands/SetCubeFace.htm>SetCubeFace</a> command for information on how to then draw to the cubemap. <br />
  60. <br />
  61. When loading cubic environments maps into Blitz using LoadTexture, all six images relating to the six faces of the cube must be contained within the one texture, and be laid out in a horizontal strip in the following order - left, forward, right, backward, up, down. The images comprising the cubemap must all be power of two sizes. <br />
  62. <br />
  63. Please note that not some older graphics cards do not support cubic mapping. In order to find out if a user's graphics card can support it, use <a class=small href=../3d_commands/GfxDriverCaps3D.htm>GfxDriverCaps3D</a> . <br />
  64. <br />
  65. 256: Store texture in vram. In some circumstances, this makes for much faster dynamic textures - ie. when using CopyRect between two textures. When drawing to cube maps in real-time, it is preferable to use this flag. <br />
  66. <br />
  67. 512: Force the use of high color textures in low bit depth graphics modes. This is useful for when you are in 16-bit color mode, and wish to create/load textures with the alpha flag - it should give better results. <br />
  68. <br />
  69. Once you have created a texture, use SetBuffer TextureBuffer to draw to it. However, to display 2D graphics on a texture, it is usually quicker to draw to an image and then copy it to the texturebuffer, and to display 3D graphics on a texture, your only option is to copy from the backbuffer to the texturebuffer.
  70. <br>
  71. <br>
  72. See also: <a class=small href=LoadTexture.htm>LoadTexture</a>, <a class=small href=LoadAnimTexture.htm>LoadAnimTexture</a>.
  73. </td>
  74. </tr>
  75. </table>
  76. <h1><a href=../3d_examples/CreateTexture.bb>Example</a></h1>
  77. <table>
  78. <tr>
  79. <td>
  80. ; CreateTexture Example <br />
  81. ; --------------------- <br />
  82. <br />
  83. Graphics3D 640,480 <br />
  84. SetBuffer BackBuffer() <br />
  85. <br />
  86. camera=CreateCamera() <br />
  87. <br />
  88. light=CreateLight() <br />
  89. RotateEntity light,90,0,0 <br />
  90. <br />
  91. cube=CreateCube() <br />
  92. PositionEntity cube,0,0,5 <br />
  93. <br />
  94. ; Create texture of size 256x256 <br />
  95. tex=CreateTexture( 256,256 ) <br />
  96. <br />
  97. ; Set buffer - texture buffer <br />
  98. SetBuffer TextureBuffer( tex ) <br />
  99. <br />
  100. ; Clear texture buffer with background white color <br />
  101. ClsColor 255,255,255 <br />
  102. Cls <br />
  103. <br />
  104. ; Draw text on texture <br />
  105. font=LoadFont( "arial",24 ) <br />
  106. SetFont font <br />
  107. Color 0,0,0 <br />
  108. Text 0,0,"This texture" <br />
  109. Text 0,40,"was created using" : Color 0,0,255 <br />
  110. Text 0,80,"CreateTexture()" : Color 0,0,0 <br />
  111. Text 0,120,"and drawn to using" : Color 0,0,255 <br />
  112. Text 0,160,"SetBuffer TextureBuffer()" <br />
  113. <br />
  114. ; Texture cube with texture <br />
  115. EntityTexture cube,tex <br />
  116. <br />
  117. ; Set buffer - backbuffer <br />
  118. SetBuffer BackBuffer() <br />
  119. <br />
  120. While Not KeyDown( 1 ) <br />
  121. <br />
  122. pitch#=0 <br />
  123. yaw#=0 <br />
  124. roll#=0 <br />
  125. <br />
  126. If KeyDown( 208 )=True Then pitch#=-1 <br />
  127. If KeyDown( 200 )=True Then pitch#=1 <br />
  128. If KeyDown( 203 )=True Then yaw#=-1 <br />
  129. If KeyDown( 205 )=True Then yaw#=1 <br />
  130. If KeyDown( 45 )=True Then roll#=-1 <br />
  131. If KeyDown( 44 )=True Then roll#=1 <br />
  132. <br />
  133. TurnEntity cube,pitch#,yaw#,roll# <br />
  134. <br />
  135. RenderWorld <br />
  136. Flip <br />
  137. <br />
  138. Wend <br />
  139. <br />
  140. End
  141. </td>
  142. </tr>
  143. </table>
  144. <br>
  145. <a target=_top href=../index.htm>Index</a><br>
  146. <br>
  147. Click <a href=http://www.blitzbasic.co.nz/b3ddocs/command.php?name=CreateTexture&ref=comments target=_blank>here</a> to view the latest version of this page online</body>
  148. </html>