i've been just messing about putting together some basic framework for a shader tutorial ... don't worry anyone who wants the tutorial, i've tried to use as little as the DBpro functions with this as possible and can remake the shader tutorial in a matter of a few lines with the builtin function.
unfortunately i don't have the resources to test if this actually works
(hopefully this post won't cut off)
Tut1VS.dpw.dba ->>
remstart
/*
Developer: FMTau Labs LLC
Title: Shader Tutorial
Version: 0.00.1 alpha (Build 0000)
Date: 23/04/2003 12:51:07
Additional Notes:
You will need a graphics card capable of using
vertex shaders 1.1 or above with atleast 32 registers
nVidia GeForce4 4x00 or GeForceFX 5x00's are recommended
*/ ** Tut1VS.dpw.dba ****
remend
`#include
`#include
disable escapekey
backdrop on
`// i'm declaring this here becuase i've not done any of the math.inc.dba yet
#constant PI 3.1415926535897932384626433832795
`------------------------------
`// Custom Vertex
`------------------------------
`// for now the custom vertex is just used for reference
type CustomVertex_t
x, y, z as float
colour as dword
endtype
#constant CustomVertex = ( FVF_XYZ+FVF_DIFFUSE )
MyApplication() :`// run the main program
`// cleanup and end the program
CleanUp()
end
`/* -------------------------------------
` Name: OneTimeInit( )
` Desc: Application PreLoop Setup
` ------------------------------------- */
function OneTimeInit( )
`{
`// setup text options
set text font "Ariel"
set text size 12
set text to bold
ink rgb(255,255,0),rgb(0,0,255) :`// set font to yellow and the background to blue
set window title "Direct3D Demonstration of FVF Objects"
`// replace 16 with FVF_SizeOf( CustomVertex ) once i finish the library
global g_pVertexBuffer as dword = D3DpVERTEXBUFFER( CustomVertex, 16, NUM_VERTEX )
global g_pObject as dword = (inc g_Object)
`// populate vertex data (create a Quad)
local g_pVertex as dword = g_pVertexBuffer
g_pVertex=CustomVertex( g_pVertex,-1.0f,-1.0f, 0.0f, 0xff00ff00 )
g_pVertex=CustomVertex( g_pVertex, 1.0f,-1.0f, 0.0f, 0xff00ff00 )
g_pVertex=CustomVertex( g_pVertex, 1.0f, 1.0f, 0.0f, 0xffff0000 )
CustomVertex( g_pVertex, 1.0f, 1.0f, 0.0f, 0xff0000ff )
make_mesh_from_memory( g_pVertexBuffer ) :`// create a mesh from the VB data
make object g_pObject,g_Mesh,0 :`// create an object from the mesh
`// setup world matrix pointer
global D3DWORLDMATRIX as dword = make matrix4( inc g_Matrix4 )
world matrix4 D3DWORLDMATRIX
`// projection matrix
global D3DPROJMATRIX as dword = make matrix4( inc g_Matrix4 )
projection matrix4 D3DPROJMATRIX
`// world matrix
global D3DVIEWMATRIX as dword = make matrix4( inc g_Matrix4 )
view matrix4 D3DVIEWMATRIX
endfunction
`}
`/* -------------------------------------
` Name: MyApplication( )
` Desc: Main Application Routines
` ------------------------------------- */
function MyApplication( )
`{
OneTimeInit( )
RestoreDeviceObjects( )
do
if escapekey()=TRUE then exitfunction
FrameMove( )
DisplayDebug( 0,0 )
sync
loop
endfunction
`}
`/* -----------------------------------------
` Name: RestoreDeviceObjects( )
` Desc: Restore device-memory objects
` and state after a device is created
` or resized.
` ----------------------------------------- */
function RestoreDeviceObjects( )
`{
`// Set the projection matrix
global matProj as dword = make matrix4( inc g_Matrix4 )
global fAspect as dword = BackBuffer.Width / BackBuffer.Height
build perspective lhmatrix4 matProj, D3D_PI/4, fAspect, 1.0, 100.0
transpose matrix4 D3DPROJMATRIX, matProj
`// setup matrix
global matView as dword = make matrix4( inc g_Matrix4 )
local vecEye as dword = make vector3( inc g_Vec3 ) : set vector3 vecEye, 0.0, 1.0, -4.0
local vecAt as dword = make vector3( inc g_Vec3 ) : set vector3 vecAt, 0.0, 0.0, 0.0
local vecUp as dword = make vector3( inc g_Vec3 ) : set vector3 vecUp, 0.0, -1.0, 0.0
build lookat lhmatrix4 matVeiw, vecEye, vecAt, vecUp
transpose matrix4 D3DVEIWMATRIX, matView
`// Turn off Lighting and Backface Culling
set object g_pObject,1,1,0,1,0,1,1,0
endfunction
`}
`/* --------------------------------------------------
` Name: FrameMove( )
` Desc: Called once per frame, the call is the entry
` point for animating the scene.
` -------------------------------------------------- */
function FrameMove( )
`{
`// For our world matrix, just rotate the object about the y-axis.
if matWorld0 then global matWorld as dword = make matrix4(inc g_Matrix)
rotate y matrix4 matWorld, m_fTime * 4.0
transpose matrix4 D3DWOLRDMATRIX, matWorld
endfunction
`}
`/* -------------------------------------
` Name: CustomVertex( )
` Desc: CustomVertex Populator
` ------------------------------------- */
function CustomVertex( pMemory as dword, x as float, y as float, z as float, colour as dword )
`{
local addr as dword = pMemory
*addr=x : inc addr,4
*addr=y : inc addr,4
*addr=z : inc addr,4
*addr=colour : inc addr,4
endfunction addr
`}
`/* ------------------------------------------
` Name: DisplayDebug( )
` Desc: displays debugging information
` ------------------------------------------ */
function DisplayDebug( x as integer, y as integer )
`{
local width as integer = screen width()
local height as integer = screen height()
local depth as integer = screen depth()
local fps as float = screen fps()
local gtype as string
if screen type()=TRUE
gtype = "HAL"
else
gtype = "REF"
endif
local strDisplay1 as string
local strDisplay2 as string
local strCard as string = current graphics card$()
set cursor x,y
strDisplay1 = str$(fps)+" fps ("+str$(width)+"x"+str$(height)+"x"+str$(depth)
strDisplay2 = gtype+": "+strCard
print strDisplay1
print strDisplay2
endfunction
`}
`/* ------------------------------------------
` Name: ConfirmDevice( )
` Desc: Put in here what the Hardware needs
` to be able to run your program
` ------------------------------------------ */
function ConfirmDevice( )
`{
local result as boolean = TRUE
local f as byte = (inc g_File)
if get maximum vertex shader version() NULL then Release(g_pVB)// Example
if g_pVertexBufferNULL then Release( g_pVertexBuffer )
`// delete matrix from memory
for i=g_Matrix to 1 step -1
delete matrix4(i)
next i
`// delete vectors from memory
for i=g_Vec3 to 1 step -1
delete vector3(i)
next i
endfunction
`}
remstart
/*
Credits:
-- Programming ----
Robert 'Raven' Lettan
-- Beta Testers ----
Copyright© 2003 FMTau Labs, LLC. All Rights Reserved.
Version 0.00.r1.alpha.0000
*/
remend
std.inc.dba ->>
remstart
/*
Name: std.inc.dba
Desc: Standard DarkBasic Include Header
*/ 0.01.r0.alpha
remend
`------------------------------
`// Standard Constants
`------------------------------
#constant TRUE (1=1)
#constant FALSE (1=0)
#constant void (0=0)
#constant NULL 0
#constant DEFUALT 1
#constant m_fTime timer()
`------------------------------
`// Global Variables
`------------------------------
global g_File as byte = NULL
global g_Memblock as byte = NULL
global g_Bitmap as byte = NULL
global g_Object as word = NULL
global g_Image as word = NULL
global g_Sprite as word = NULL
global g_Midi as word = NULL
global g_Sound as word = NULL
`--------------------------------------
`// Setup Global BackBuffer Information
`--------------------------------------
type BackBuffer_t
Width as integer
Height as integer
Depth as integer
Pitch as integer
endtype
global BackBuffer as BackBuffer_t
lock backbuffer
BackBuffer.Width = get backbuffer width( )
BackBuffer.Height = get backbuffer height( )
BackBuffer.Depth = get backbuffer depth( )
BackBuffer.Pitch = get backbuffer pitch( )
unlock backbuffer
`/* ------------------------------------
` Name: HRESULT( )
` Desc: Causes a popup box from Errors
` ------------------------------------ */
function HRESULT( error as boolean )
`{
local f as byte = inc g_File
local size as integer
local i as integer
local j as integer
local l as integer
local buffer as byte
local strError as string
local dim buffer(256,256) as byte
if error=TRUE
size=file size("Error.log")
open to read f,"Error.log"
for i=0 to size-1
if l>255 then l=0
read byte 1,buffer
if chr$(buffer)="-" then inc j
buffer(j,l)=buffer
inc l
next i
close file f
endif
i=j
l as boolean=FALSE
for j=0 to 255
if l=FALSE
if chr$(buffer(i,j))=chr$(32) and chr$(buffer(i,j+1))=chr$(32)
l=TRUE
else
strError=strError+chr$(buffer(i,j))
endif
endif
next j
strError=right$(strError,len(strError)-1)
dec g_File
exit prompt "Error",strError
endfunction
`}
`/* -------------------------------------
` Name: Release( )
` Desc: Releases all memory attached to
` a pointer
` ------------------------------------- */
function Release( pMemory as dword )
`{
delete memory *pMemory
endfunction
`}
remstart
/*
Copyright© 2003 FMTau Labs, LLC. All Rights Reserved.
*/ 0.01.r0.alpha
remend
fvf.inc.dba ->>
remstart
/*
Name: fvf.inc.dba
Desc: Flexible Vertex Format header
Constants, Types & Functions
*/ 0.01.r0.alpha
remend
`------------------------------
`// FVF UINT Constants
`------------------------------
`// you can't declare XYZ & XYZRWH or XYZBn together
#constant FVF_XYZ 2
#constant FVF_XYZRHW 4
#constant FVF_XYZB1 6
#constant FVF_XYZB2 8
#constant FVF_XYZB3 10
#constant FVF_XYZB4 12
#constant FVF_XYZB5 14
`// if you declare XYZRWH you can't use NORMAL
#constant FVF_NORMAL 16
#constant FVF_PSIZE 32
#constant FVF_DIFFUSE 64
#constant FVF_SPECULAR 128
`/* you only declare on of these each one is
` the number of UV points you have, ie TEX1 is 1set of u,v float
` TEX2 is 2sets of u,v float etc... */
#constant FVF_TEX0 0
#constant FVF_TEX1 256
#constant FVF_TEX2 512
#constant FVF_TEX3 768
#constant FVF_TEX4 1024
#constant FVF_TEX5 1280
#constant FVF_TEX6 1536
#constant FVF_TEX7 1792
#constant FVF_TEX8 2048
`// fvf constant header setup
type D3DFVF_HEADER_t
Version as DWORD
SizeOf as DWORD
NumVert as DWORD
endtype
`// darkbasic data layout
type D3DFVF_VERTEX_t
p as fVec3_t
n as fVec3_t
d as DWORD
tu as float
tv as float
endtype
#constant D3DFVF_VERTEX ( FVF_XYZ+FVF_NORMAL+FVF_DIFFUSE+FVF_TEX1 )
`/* ------------------------------------
` Name: D3DpVertexBuffer()
` Desc: Creates a Vertex Buffer
` ------------------------------------ */
function D3DpVertexBuffer( Code as dword, SizeOf as dword, NumVert as dword )
`{
local result as dword = NULL
result=make memory( 12+(SizeOf*NumVert) )
fill memory *result, Code, 4
fill memory *result, SizeOf, 4
fill memory *result, NumVert, 4
return result
`}
`/* ------------------------------------
` Name: FVF_SizeOf()
` Desc: Gets the Vertex Data Size of
` the FVF Format you've declared
` ------------------------------------ */
function FVF_SizeOf( version as dword )
`{ Not Working Yet
local result as integer = NULL
endfunction result
`}
`/* --------------------------------------
` Name: make_fvf_from_memory()
` Desc: creates a DarkBasic useable mesh
` from Vertex Buffer
` -------------------------------------- */
function make_fvf_from_memory( pMemory as dword )
`{
local addr as dword = pMemory
local header as D3DFVF_HEADER_t
local pos as integer = NULL
local i as integer = NULL
local mb as byte = inc g_Memblock
header.Version = *addr : addr=addr+4
header.SizeOf = *addr : addr=addr+4
header.NumVert = *addr : addr=addr+4
make memblock mb,12+(size*vert)
write memblock dword mb,pos,header.Version : pos=pos+4
write memblock dword mb,pos,header.SizeOf : pos=pos+4
write memblock dword mb,pos,header.NumVert : pos=pos+4
local pMemblock as dword = get memblock ptr(mb)
pMemblock=pMemblock+pos
copy memory *pMemblock,*pVertexBuffer,(header.SizeOf*header.NumVer)
make mesh from memblock (inc g_Mesh),mb
delete memblock mb
dec g_Memblock
endfunction
`}
remstart
/*
Copyright© 2003 FMTau Labs, LLC. All Rights Reserved.
*/ 0.01.r0.alpha
remend
well have fun trying to figure out what it actually does

Tsu'va Oni Ni Jyuuko Fiori Sei Tau!
One block follows the suit ... the whole suit of blocks is the path ... what have you found?