HomeAbout inludoServicesGamesClientsDevelopmentsForumContact usHomeMail inludo


Creating Shaders and Textures:


Download the source here.


Intro:
It is often beneficial to create your own shaders and textures. However, there are a lot of options which can be set, and a lot of error checking that is necessary.
To get around this I created some useful routines to enable you to initialise shaders and textures in a single line.
A texture is a single graphic that can be applied to shaders. Generally shaders contain the actual data used to describe the texture (apart from it's actual bitmap make-up). Lighting, texture transform manipulations etc are all taken care of by the shader. This allows a texture to be re-used many times with a different result each time. One useful analogy is that of members to sprites. A single member can be used in many sprites at once, and each sprite can be a different size, have different inks etc. set.

Creating textures:
The routine for creating a texture is called BS_CreateTexture(). The BS are my initials. Gosh, it's almost like I'm famous. The routine can be called with the following options:

BS_CreateTexture(tmWorld, tmBitmap)
BS_CreateTexture(tmWorld, tmBitmap, tQuality)
BS_CreateTexture(tmWorld, tmBitmap, tQuality, tlExtras)
tNewTexturePointer = BS_CreateTexture(tmWorld, tmBitmap)
tNewTexturePointer = BS_CreateTexture(tmWorld, tmBitmap, tQuality)
tNewTexturePointer = BS_CreateTexture(tmWorld, tmBitmap, tQuality, tlExtras)

where:

tmWorld is the name of the 3D member you wish to create the texture in.
tmBitmap is the name of the bitmap member you wish to create the texture from.
tQuality is either #low, #medium or #high. #low sets the texture to not use mipmapping. #medium sets the texture to use bi-linear mipmapping and #high uses tri-linear mipmapping. Mipmapping uses more VRAM on the graphics card. If this parameter is omitted it defaults to #high.
tlExtras is a property list. This uses the undocumented property list feature when creating textures. For a detailed explanation of what this can contain, visit www.shockwavemovies.com and peruse the 'undoc'd' section (specifically the 'Inks/masks with newTexture' section).

If the routine runs succesfully then tNewTexturePointer contains the reference to the newly created texture. Note that if a texture with this name already exists, a pointer to that texture is returned; no error message is generated.
If the routine fails, then tNewTexturePointer contains a symbol detailing the error that occured. A simple way to check if the routine worked is to do:

if
symbolP(tNewTexturePointer) then -- An error has occured

The possible error messages are as follows:

  • #invalid_world_name - tmWorld does not match any member names.
  • #invalid_world_member_type - Member tmWorld is not a 3D member.
  • #invalid_bitmap_name - tmBitmap does not match any member names.
  • #invalid_bitmap_member_type - Member tmBitmap is not a bitmap member.
Creating shaders:
The routine for creating a shader from a bitmap member is called BS_CreateShader(). The routine can be called with the following options:

BS_CreateShader(tmWorld, tmBitmap)
tNewShaderPointer = BS_CreateShader(tmWorld, tmBitmap)

where:

tmWorld is the name of the 3D member you wish to create the texture in.
tmBitmap is the name of the bitmap member you wish to create the texture used in this shader from.

If the routine runs succesfully then tNewShaderPointer contains the reference to the newly created shader.
This routine looks for a texture with the name tmBitmap. If found, it uses this. If not found, it triggers a call to BS_CreateTexture(). Therefore to run properly either a texture should already exist called tmBitmap or there should be a bitmap member with the name tmBitmap.
Note that if a shader with the chosen name already exists, an error message is returned (see below).
If the routine fails, then tNewShaderPointer contains a symbol detailing the error that occured. A simple way to check if the routine worked is to do:

if
symbolP(tNewShaderPointer) then -- An error has occured

The possible error messages are as follows:
  • #invalid_world_name - tmWorld does not match any member names.
  • #invalid_world_member_type - Member tmWorld is not a 3D member.
  • #shader_already_exists - A shader with this name already exists.
  • #invalid_bitmap_name - tmBitmap does not match any member names.
  • #invalid_bitmap_member_type - Member tmBitmap is not a bitmap member.

 

Development
Screenshots
Demos
Tutorials