CreateTexture ( width,height[,flags][,frames] )
Parameters
|
width - width of the texture, in pixels height - height of the texture, in pixels flags (optional) - texture flags, added together; 0 (default): 1: colour 2: alpha 4: masked - areas coloured 0,0,0 are not drawn 8: mipmapped 16: clamp u - no horizontal tiling 32: clamp v - no vertical tiling 64: spherical environment map 128: cubic environment map 256: store texture in vram (no effect on the modern renderer) 512: force high colour textures (no effect on the modern renderer) frames (optional) - number of animation frames the texture has; 1 (default) |
Description
|
Creates a blank texture and returns its handle. Use it when a game draws its own texture at runtime - a scoreboard, a minimap, graffiti, procedural patterns. Draw into it with SetBuffer TextureBuffer(texture), using the normal 2D commands, then apply it with EntityTexture or BrushTexture. For big or frequent updates, drawing to an image first and using CopyRect onto the texture buffer is usually quickest. Flags can be added together: 3 (1+2) gives a texture with colour and alpha. Alpha (2) enables real translucency from the texture's alpha channel; masked (4) is the cheaper cut-out style where pure black pixels vanish. Mipmapped (8) generates smaller versions used at distance so the texture doesn't shimmer. The clamp flags stop the texture wrapping - important when you scale or scroll a texture and don't want edge bleeding. Flag 128 makes a cubic environment map: draw its six faces via SetCubeFace for real-time reflections. Flags 256 and 512 are kept for compatibility with old code; the modern renderer always uses 32-bit textures in GPU memory. On the modern renderer the texture is created at exactly the size you ask for - no rounding to power-of-2 sizes. Textures created here are not affected by TextureFilter, which only applies to textures loaded from files. See also: LoadTexture, LoadAnimTexture, TextureBuffer, EntityTexture, SetCubeFace, FreeTexture. |
Example
; CreateTexture Example ; --------------------- Graphics3D 640,480,0,2 SetBuffer BackBuffer() camera=CreateCamera() light=CreateLight() RotateEntity light,45,45,0 cube=CreateCube() PositionEntity cube,0,0,5 ; Create an empty 256x256 texture (optional flags and frame count omitted) tex=CreateTexture(256,256) ; Point 2D drawing commands at the texture and draw a message on it SetBuffer TextureBuffer(tex) ClsColor 255,255,255 Cls font=LoadFont("arial",24) SetFont font Color 30,30,30 Text 8,8,"This texture" Text 8,48,"was made with" Color 0,0,255 Text 8,88,"CreateTexture()" Color 30,30,30 Text 8,128,"and drawn on" Text 8,168,"with 2D commands" ; Back to drawing on the screen, with the default text colour SetBuffer BackBuffer() Color 255,255,255 ; Apply the hand-drawn texture to the cube EntityTexture cube,tex While Not KeyDown(1) TurnEntity cube,0,1,0 ; Arrow keys move the camera If KeyDown(200) Then MoveEntity camera,0,0,0.1 If KeyDown(208) Then MoveEntity camera,0,0,-0.1 If KeyDown(203) Then TurnEntity camera,0,1,0 If KeyDown(205) Then TurnEntity camera,0,-1,0 RenderWorld Text 0,0,"Arrows: camera Esc: exit" Flip Wend End
Index