Skip to content

CreateTexture

Narta Xaymar Dirks edited this page Oct 27, 2026 · 15 revisions
Blitz3D

CreateTexture

CreateTexture:Int32 width:Int32, height:Int32, flags:Int32=0, frames:Int32=1
Parameter Type Default Description
width Int32 required Width in pixels.
height Int32 required Height in pixels.
flags Int32 0 Sum of the flags above. Defaults to 1.
frames Int32 1 Number of animation frames. Defaults to 1.

Returns: A texture handle.

Description

Makes an empty texture of the given size and returns its handle. Fill it by drawing on its buffer: call SetBuffer with TextureBuffer and use the normal 2D commands, then switch back to the back buffer and put the texture on something with EntityTexture or a brush.

The flags are added together, so 1 + 2 is a color texture that also has an alpha channel:

Flag Meaning
1 Color, the default.
2 Alpha. Dark texels are see-through, bright texels are solid.
4 Masked. Texels that are exactly black are not drawn.
8 Mipmapped. Distant surfaces use smaller, blurrier copies, which are made again from the picture after you draw on the texture. The flag picks the default way the copies are blended; SetTextureSampler with a sampler from CreateSampler can change that, for example the mip mode, the level bias or anisotropic filtering.
16 Clamp U. Coordinates outside 0 to 1 repeat the edge texel instead of tiling. A sampler set with SetTextureSampler overrides this.
32 Clamp V. The same for the vertical direction. A sampler set with SetTextureSampler overrides this.
64 Spherical environment map.
128 Cubic environment map.
256 Keep the texture in video memory. This is always the case, there are no textures that only live on the CPU.
512 Use a high color format even in low color modes. This is always the case: a texture is at least 8 bits per channel with alpha (R8G8B8A8), or a compatible block compressed format.
1024 Point sampling: no smoothing between texels. A sampler set with SetTextureSampler can do this (nearest filters) and overrides the flag.
65536 Use the second set of texture coordinates of the mesh, see TextureCoords.

The texture is created at the size you ask for, so TextureWidth and TextureHeight return exactly what you passed. Power-of-two sizes are the safest choice for other Blitz3D implementations.

Differences

  • Only flags 2, 4, 8, 16, 32 and 65536 change how the texture looks. Video memory (256) and high color (512) are always in effect, so the flags change nothing. Point sampling (1024) is accepted and stored, but a texture is drawn with linear filtering unless it is given a sampler with SetTextureSampler. A sphere map (64) takes its coordinates from the normal of the surface in the view, and ScaleTexture, PositionTexture and RotateTexture do not change them. A cube map (128) has six faces of the size you give, chosen with SetCubeFace and shown as SetCubeMode says; it does not have mip maps. A texture with both flags is drawn as a plain one. Without flag 8 it has no mip maps.
  • The alpha (2) flag is only applied to pictures that LoadTexture or LoadAnimTexture read from a file. A texture made with CreateTexture and drawn on stays opaque everywhere, also where you drew black, unless it is masked (4): the masked flag does cut out black there.

Examples

Graphics3D 320, 240, 0, 2
SetBuffer BackBuffer()
camera = CreateCamera()
CameraClsColor camera, 70, 100, 160
light = CreateLight()
RotateEntity light, 40, 30, 0
cube = CreateCube()
PositionEntity cube, 0, 0, 4.2
TurnEntity cube, 25, 35, 0

tex = CreateTexture(128, 128)
SetBuffer TextureBuffer(tex)
ClsColor 240, 240, 240
Cls
Color 30, 90, 200
For y = 0 To 7
	For x = 0 To 7
		If (x + y) Mod 2 = 0 Then Rect x * 16, y * 16, 16, 16, 1
	Next
Next
Color 220, 40, 40
Oval 32, 32, 64, 64, 1

SetBuffer BackBuffer()
EntityTexture cube, tex
RenderWorld
Flip
WaitKey

Media

CreateTexture

Related Commands

ClearTextureFilters, CreateSampler 〔BlitzLLVM〕, FreeTexture, LoadAnimTexture, LoadTexture, PositionTexture, RotateTexture, ScaleTexture

Home · Command Index



Differences
Language Features
BlitzBasic
Blitz3D
BlitzPlus

Clone this wiki locally