- // Definitions Datei
- //function ist ein Tag für eine funktion, die eine funktion im externen code aufruft und beim init des Script gesetzt wurde oder leitet eine Scriptinterne funktion ein.
- //Script internal ID
- typedef unsigned int TLocation;//0 = error
- struct TClass
- {
- TString ClassName;
- };
- struct TMaterial
- {
- TLocation Draw;
- TLocation EndDraw;
- TLocation BeginDraw;
- function LoadTexture;
- };
- struct TShader
- {
- function Load;
- function Bind;
- function SetVariable;
- function EnableAttribute;
- function DisableAttribute;
- function SetAttribute;
- };
- struct TTexture
- {
- function Load;
- function Bind;
- };
- struct TMesh
- {
- function Draw
- };
- struct TMesh
- {
- function GetFaceCount;
- function Draw;
- };
- struct TRenderer
- {
- function GetPass;
- };
- #define ZPASS 1
- #define RENDERPASS 2
- #define MESHVERTEX 1
- #define MESHCOLOR 2
- TClass Owner;
- // Definitions Datei Ende
- //Beispiel Datei: Material
- TMaterial Material;
- TTexture SkyTex;
- TShader SkyShader;
- TMesh Mesh;
- TRenderer Renderer;
- TMesh Mesh;
- function EndDraw()
- {
- switch(Renderer.GetPass())
- {
- case RENDERPASS:
- SkyShader.DisableAttribute(MESHVERTEX);
- SkyShader.DisableAttribute(MESHCOLOR);
- SkyShader.Unbind();
- SkyTex.Unbind();
- Mesh.Unbind();
- break;
- }
- }
- function Draw()
- {
- switch(Renderer.GetPass())
- {
- case ZPASS:
- case RENDERPASS:
- for (int f=0;f<Mesh.GetFaceCount();f++)
- Mesh.Draw(f);
- break;
- }
- }
- function BeginDraw()
- {
- switch(Renderer.GetPass())
- {
- case ZPASS:
- Mesh.Bind();
- break;
- case RENDERPASS:
- SkyShader.Bind();
- SkyShader.SetVariable("ProjectionviewMatrix",Renderer.GetProjectionviewMatrix());
- SkyShader.SetVariable("ModelviewMatrix",Renderer.GetModelviewMatrix());
- Mesh.BindBuffer(MESHVERTEX);
- SkyShader.EnableAttribute("Vertex");
- SkyShader.SetAttribute("Vertex",3,float,false,0,0);
- Mesh.BindBuffer(MESHCOLOR);
- SkyShader.EnableAttribute("Color");
- SkyShader.SetAttribute("Color",3,float,false,0,0);
- SkyTex.Bind(0);
- break;
- }
- }
- function main()
- {
- if (Owner.ClassName!="TMaterial")
- {
- Error("Wrong Classtype");
- Exit();
- }
- Material.Draw=Draw();
- Material.BeginDraw=BeginDraw();
- Material.EndDraw=EndDraw();
- SkyTex.Load("file://media/textures/clearSky.dds");
- SkyShader.Load("file://media/shader/sky.frag","file://media/shader/sky.vert");
- }