The Texture Generator

The following example shows texture generator code; the example is broken up into functional sections of code (in bold text).

Variables:large_scale_flagdw0;0= small scale mode, 1=large scale mode (bglseed.asm)
scale_factordd0;the universal 3-D scale factor set by the SCALE command
;Units * 65536 / M

Edge Block Structures

edge_recordstruc
top_ydw0;top scan line Y (smaller)
bot_ydw0;bot scan line Y (bigger)
xposdw0,0;32-bit fixed point X position
dxposdw0,0;32-bit fixed point delta X
edge_recordends
edge_record_lnthequ12

gshade_recordstruc
top_ydw0;top scan line Y (smaller)
bot_ydw0;bot scan line Y (bigger)
xposdw0,0;32-bit fixed point X position
dxposdw0,0;32-bit fixed point delta X
cposdw0,0;32-bit color value
dcposdw0,0;32-bit delta color
gshade_recordends
gshade_record_lnthequ20

texture_recordstruc
top_ydw0;top scan line Y (smaller)
bot_ydw0;bot scan line Y (bigger)
xposdw0,0;32-bit fixed point X position
dxposdw0,0;32-bit fixed point delta X
irdw0,0;inverse rotation vector
jrdw0,0
krdw0,0
dir1dw0,0;delta inverse rotation vector
djr1dw0,0
dkr1dw0,0
texture_recordends
texture_record_lnthequ36

sprite_recordstruc
top_xdw0;top scan line Y (smaller)
bot_xdw0;bot scan line Y (bigger)
yposdw0,0;32-bit fixed point X position
dyposdw0,0;32-bit fixed point delta X
spritexdw0,0
spriteydw0,0
dspritexdw0,0
dspriteydw0,0

sprite_recordends
sprite_record_lnthequ28

gtshade_recordstruc
top_xdw0;top scan line Y (smaller)
bot_xdw0;bot scan line Y (bigger)
yposdw0,0;32-bit fixed point X position
dyposdw0,0;32-bit fixed point delta X
spritexdw0,0
spriteydw0,0
dspritexdw0,0
dspriteydw0,0
iposdw0,0
diposdw0,0

gtshade_recordends
gtshade_record_lnthequsprite_record_lnth+8

The TEXTURE Command

INSTRUCTION
%ibp=opcode
%ibp+2=internal ID number
%ibp+4=X instance value
%ibp+6=Y instance value
%ibp+8=Z instance value
%ibp+10=14 character ASCIIZ file name for texture
TEXTURE VARIABLES & BUFFERS in BGLTEX.ASM
texture_cntequ64;binary mult of 2, please
time_stampdwtexture_cnt dup (0);when have we used this
texture_distdwtexture_cnt dup (0);distance away (256m units)
texture_handledwtexture_cnt dup (0);segment/handle of image
texture_lastdwtexture_cnt dup (0);pointer of user to follow
texture_fastdwtexture_cnt dup (0);fast access flag
texture_namedbtexture_cnt * file_lnthdup (0);filename
texture_useddwtexture_cnt dup (0)
in GLOBAL.ASM
txtr_segdw0;texture source address
texture_flagdw0;0==no texture, nonzero==texture
imvaliddw0;is inverse matrix valid?
texture_qualitydw0;image quality of texture map (can be overridden by BGL)
;0=low quality=always 160 quality (on 320 driver)
;1=med quality=do 320 unless haze_factor not zero, then do 160
;2=high quality=always do 320 quality
texture_ixdd0;instanced position of the texture (high 16-bits loaded from TEXTURE cmd.
texture_iydd0;relative to (0,0,0) in ii.ff
texture_izdd0
haze_factordw0;haze/transparency color 0=off 2-255 = color number if less than don't copy
;1=use special haze texture drawer (using palette run from green to gray)
texture_adw0;equation of texture mapped polygon
texture_bdw0;Ax+By+Cz+D=0
texture_cdw0;where A,B,C is normalized surface
texture_ddd0;normal, and D is DWORD point value
texture_lxdd0;bounds of the texture map being
texture_lzdd0;drawn to eliminate the edge
texture_uxdd0;problem
texture_uzdd0
in ROOTVAR.ASM
water_texturedw0;0=off  .nz.=on
TEXTURE COMMAND
BGL_TEXTURE (bgltex.asm)
if (shadow_flag=1);don't texture shadows
goto BGL_TEXTURE_NO_EMS
if (water_texture turned off);if water_texture off, switch water & lakes to non-textured polygons
if 14-char ASCIIZ filename = water_texture_name or lake_texture_name
goto BGL_TEXTURE_NO_EMS
haze_factor=0;hazing off
if (instruction's internal ID number bit 15=0= "internal");NEED TO GET TEXTURE
goto BGL_LOAD_TEXTURE
if texture_handle=0
goto BGL_LOAD_TEXTURE
if instruction's filename doesn't match texture_name[slot pointer]
goto BGL_LOAD_TEXTURE
goto BGL_TEXTURE_HAVE_HANDLE;we have texture and it's a good one
bgl_texture_no_ems:;don't do texture
texture_flag=0
texture_avail=0
goto BGL_TEXTURE_DONE
bgl_load_texture:;try to load texture and use it
BGL_TEXTURE_LOAD
if not loaded, goto BGL_TEXTURE_NO_EMS
bgl_texture_have_handle:;texture available in slot pointer bx and handle ax. use it.
internal ID number=slot pointer/2 + 8000h;top bit set to flag as "external"
time_stamp[slot pointer]=tick18;time stamp our usage
texture_used[slot pointer]=0;we used this texture
if (rbias<texture_dist[slot pointer])
texture_dist[slot pointer]=rbias;update dist to indicate closest use
BGL_TEXTURE_MAP_SEG (ax=handle, bx=slot pointer)
txtr_seg=segment of the texture map (may come from ems,xms,conv)
texture_quality=image_quality
if imvalid=0
INV_MATRIX_FAR_ID;create inverse matrix for this texture
imvalid++
texture_ix+2/_iy+2/_iz+2=X/Y/Z instance from instruction
texture_ix/_iy/_iz=0;texture_ix/iy/iz are 32-bit values
texture_lx=8000 0000h;set lower and upper texture scan x & z bounds
texture_lz=8000 0000h
texture_ux=7fff ffffh
texture_uz=7fff ffffh
texture_flag=1
texture_avail=1
bgl_texture_done:
ibp+22;advance past 22-bytes of 24-byte opcode. (bgl_surface gets the other 2-bytes)
goto BGL_SURFACE
bgl_surface:;bgl surface command handler
surflg++
convex_surface=concave_flag+1
concave_flag=0
SURFACE
elptr=elist_loc;reset edge list pointer & vertex counter
vcount=-1
ibp=ibp+2
EXIT