I would accept it for a typeless const but in this case it's 4 byte ulong.
Joshy
Code: Select all
type TGEO_HEADERID as ulong
const as TGEO_HEADERID GEO_ID = &H47443348 ' "H3DG"
chdir exepath()
var hFile = FreeFile()
if open("test.geo",for binary,access write,as #hFile) then
print "error: can't create file 'test.geo' !"
beep: sleep: end 1
end if
put #hFile,,GEO_ID
' ...
close #hFile
here are the real example with many const's
Code: Select all
type TGEO_HEADERID as ulong
type TGEO_VERSION as ulong
type TGEO_STREAM_COUNT as ulong
type TGEO_STREAM_ID as ulong
type TGEO_ELEMENT_SIZE as ulong
type TGEO_ELEMENT_COUNT as ulong
type TGEO_TRIANGLE_INDEX as ulong
type TGEO_CHUNKID as ulong
const as TGEO_HEADERID GEO_ID = &H47443348 ' "H3DG"
const as TGEO_VERSION GEO_VERSION = 5
const as TGEO_STREAM_ID GEO_POSITON = 0
const as TGEO_STREAM_ID GEO_NORMAL = 1
const as TGEO_STREAM_ID GEO_TANGENT = 2
const as TGEO_STREAM_ID GEO_BITANGENTS = 3
const as TGEO_STREAM_ID GEO_JOINT_INDEX = 4
const as TGEO_STREAM_ID GEO_WHEIGHTS = 5
const as TGEO_STREAM_ID GEO_TEXTURE_COORDS0 = 6
const as TGEO_STREAM_ID GEO_TEXTURE_COORDS1 = 7
const as TGEO_ELEMENT_SIZE GEO_POSITON_SIZE = 12 ' 3 * sizeof(single) (x,y,z)
const as TGEO_ELEMENT_SIZE GEO_NORMAL_SIZE = 6 ' 3 * sizeof(short) (x,y,z)
const as TGEO_ELEMENT_SIZE GEO_TANGENT_SIZE = 6 ' 3 * sizeof(short) (x,y,z)
const as TGEO_ELEMENT_SIZE GEO_BITANGENTS_SIZE = 6 ' 3 * sizeof(short) (x,y,z)
const as TGEO_ELEMENT_SIZE GEO_JOINT_INDEX_SIZE = 4 ' 4 * sizeof(ubyte) or 0 if not used
const as TGEO_ELEMENT_SIZE GEO_WHEIGHTS_SIZE = 4 ' 4 * sizeof(ubyte)
const as TGEO_ELEMENT_SIZE GEO_TEXTURE_COORDS0_SIZE = 8 ' 2 * sizeof(single) (u,v)
const as TGEO_ELEMENT_SIZE GEO_TEXTURE_COORDS1_SIZE = 8 ' 2 * sizeof(single) (u,v)
' a simple textured cube
const as TGEO_ELEMENT_COUNT nStreams = 3 ' ( in this case 3 vertex streams: position, normal and texture coords set0)
const as TGEO_ELEMENT_COUNT nVertices = 24 ' 6 quads * 4 vertices
const as TGEO_ELEMENT_COUNT nTriangles = 12 ' 6 quads * 2 triangles
const as TGEO_ELEMENT_COUNT nTriangleIndices = 36 ' 12 triangles * 3 indicies
type TGEO_JOINT_INVERSE_BIND_MATRICE
as single m4x4(15)
end type
type TGEO_POSITION
as single x,y,z
end type
type TGEO_NORMAL
as short x,y,z ' single stored as short / 32767.0
end type
type TGEO_TANGENT
as short x,y,z ' single stored as short/ 32767.0
end type
type TGEO_BITANGENTS
as short x,y,z ' single stored as short/ 32767.0
end type
type TGEO_JOINT_INDEX
as ubyte a,b,c,d ' can be 0=unused
end type
type TGEO_JOINT_WIGHTS
as ubyte a,b,c,d ' single stored as byte / 255
end type
type TGEO_TEXTURE_COORDS
as single u,v
end type
dim as TGEO_POSITION Positions(nVertices-1) => { _
(-0.5, 0.5, 0.5), (-0.5,-0.5, 0.5), ( 0.5,-0.5, 0.5), ( 0.5, 0.5, 0.5), _ ' 4 vertices build the front face of the cube
( 0.5, 0.5, 0.5), ( 0.5,-0.5, 0.5), ( 0.5,-0.5,-0.5), ( 0.5, 0.5,-0.5), _ ' 4 vertices build the right face of the cube
( 0.5, 0.5,-0.5), ( 0.5,-0.5,-0.5), (-0.5,-0.5,-0.5), (-0.5, 0.5,-0.5), _ ' 4 vertices build the back face of the cube
(-0.5, 0.5,-0.5), (-0.5,-0.5,-0.5), (-0.5,-0.5, 0.5), (-0.5, 0.5, 0.5), _ ' 4 vertices build the left face of the cube
(-0.5, 0.5,-0.5), (-0.5, 0.5, 0.5), ( 0.5, 0.5, 0.5), ( 0.5, 0.5,-0.5), _ ' 4 vertices build the top face of the cube
(-0.5,-0.5, 0.5), (-0.5,-0.5,-0.5), ( 0.5,-0.5,-0.5), ( 0.5,-0.5, 0.5)} ' 4 vertices build the bottom face of the cube
#define one 32767
dim as TGEO_NORMAL Normals(nVertices-1) => { _
(0,0, one), (0,0, one), (0,0, one), (0,0, one), _ ' 4 normals of the front face
( one,0,0), ( one,0,0), ( one,0,0), ( one,0,0), _ ' 4 normals of the right face
(0,0,-one), (0,0,-one), (0,0,-one), (0,0,-one), _ ' 4 normals of the back face
(-one,0,0), (-one,0,0), (-one,0,0), (-one,0,0), _ ' 4 normals of the left face
(0, one,0), (0, one,0), (0, one,0), (0, one,0), _ ' 4 normals of the top face
(0,-one,0), (0,-one,0), (0,-one,0), (0,-one,0)} ' 4 normals of the bottom face
#undef one
dim as TGEO_TEXTURE_COORDS TextureCoords0(nVertices-1) => { _
(0,1),(0,0),(1,0),(1,1), _ ' texture coords from front face
(0,1),(0,0),(1,0),(1,1), _ ' texture coords from right face
(0,1),(0,0),(1,0),(1,1), _ ' texture coords from back face
(0,1),(0,0),(1,0),(1,1), _ ' texture coords from left face
(0,1),(0,0),(1,0),(1,1), _ ' texture coords from top face
(0,1),(0,0),(1,0),(1,1) } ' texture coords from bottom face
dim as TGEO_TRIANGLE_INDEX Indices(nTriangleIndices-1) => { _
0, 1, 2, 2, 3, 0, _ ' 2 triangles build the front face
4, 5, 6, 6, 7, 4, _ ' 2 triangles build the right face
8, 9,10, 10,11, 8, _ ' 2 triangles build the back face
12,13,14, 14,15,12, _ ' 2 triangles build the left face
16,17,18, 18,19,16, _ ' 2 triangles build the top face
20,21,22, 22,23,20} ' 2 triangles build the bottom face
ChDir ExePath()
' write file: cube.geo in Horde3D/Content/models/cube/
var hFile = FreeFile()
if open("cube.geo",for binary,access write,as #hFile) then
print "error: can't create 'cube.geo' !"
beep : sleep: end 1
end if
dim as ulong u32 ' a helper FreeBASIC can#t write typed const#s in binary file !
#define WRITE_U32(value) u32=value : put #hFile,,u32
WRITE_U32(GEO_ID) ' write geo file id
WRITE_U32(GEO_VERSION) ' write geo file version
WRITE_U32(0) ' write number of joints in this file
' write nJoints * 16 single inverse matrices if any
'for i as integer=0 to nJoints-1
' put #hFile,,Matrices(i)
' next
WRITE_U32(nStreams) ' write number of vertex strams in this file 3 in this case
WRITE_U32(nVertices) ' write number of vertices in this file
' write position chunk 1
WRITE_U32(GEO_POSITON)
WRITE_U32(GEO_POSITON_SIZE)
put #hFile,,Positions()
' write normal chunk 2
WRITE_U32(GEO_NORMAL)
WRITE_U32(GEO_NORMAL_SIZE)
put #hFile,,Normals()
' write tangent chunk if any
'WRITE_U32(GEO_TANGENT)
'WRITE_U32(GEO_TANGENT_SIZE)
'put #hFile,,Tangents()
' write bitangents chunk if any
'WRITE_U32(GEO_BITANGENTS)
'WRITE_U32(GEO_BITANGENTS_SIZE)
'put #hFile,,Bitangents()
' write joint indicies if an y
'WRITE_U32(GEO_JOINT_INDEX)
'WRITE_U32(GEO_JOINT_INDEX_SIZE)
'put #hFile,,Jointindicies()
' write joint wheights if any
'WRITE_U32(GEO_WHEIGHTS)
'WRITE_U32(GEO_WHEIGHTS_SIZE)
'put #hFile,,Wheights()
' write texturecoord set0 chunk 3
WRITE_U32(GEO_TEXTURE_COORDS0)
WRITE_U32(GEO_TEXTURE_COORDS0_SIZE)
put #hFile,,TextureCoords0()
' write texturecoord set1 if any
'WRITE_U32(GEO_TEXTURE_COORDS1)
'WRITE_U32(GEO_TEXTURE_COORDS1_SIZE)
'put #hFile,,TextureCoords1()
' write triangle indicies
WRITE_U32(nTriangleIndices)
put #hFile,,Indices()
WRITE_U32(0) ' write number of morph targets
' close the file
close #hFile