Here's a little example:
Code: Select all
<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" GLBase="1" FileVersion="2">
<OnLoaded>
<ZExternalLibrary ModuleName="opengl32">
<BeforeInitExp>
<![CDATA[//
if(ANDROID)
{
this.ModuleName = "libGLESv1_CM.so";
}
else if(LINUX)
{
this.ModuleName = "libGL.so";
}
else
{
this.ModuleName = "opengl32";
}]]>
</BeforeInitExp>
<Source>
<![CDATA[//
const int GL_BLEND = 0x0BE2;
const int GL_SRC_ALPHA = 0x0302;
const int GL_ONE_MINUS_SRC_ALPHA = 0x0303;
void glEnable(int cap){}
void glBlendFunc(int sfactor, int dfactor){}]]>
</Source>
</ZExternalLibrary>
<ZExpression>
<Expression>
<![CDATA[//
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);]]>
</Expression>
</ZExpression>
</OnLoaded>
<OnRender>
<RenderTransformGroup Comment="ground" Translate="0 -1 0" Rotate="-0.2 0 0">
<Children>
<UseMaterial Material="GroundMaterial"/>
<RenderMesh Mesh="GoundMesh"/>
</Children>
</RenderTransformGroup>
<RenderTransformGroup Comment="sphere basic" Translate="-4 0 0">
<Children>
<UseMaterial Material="BasicMaterial"/>
<RenderMesh Mesh="SphereMesh"/>
</Children>
</RenderTransformGroup>
<RenderTransformGroup Comment="sphere flat shadow">
<Children>
<UseMaterial Material="FlatShadowMaterial"/>
<RenderMesh Mesh="SphereMesh"/>
</Children>
</RenderTransformGroup>
<RenderTransformGroup Comment="sphere alpha" Translate="4 0 0">
<Children>
<UseMaterial Material="AlphaMaterial"/>
<RenderMesh Mesh="SphereMesh"/>
</Children>
</RenderTransformGroup>
</OnRender>
<Content>
<Mesh Name="SphereMesh">
<Producers>
<MeshSphere ZSamples="32" RadialSamples="32"/>
</Producers>
</Mesh>
<Mesh Name="GoundMesh">
<Producers>
<MeshBox Scale="10 10 1" Grid2DOnly="255"/>
</Producers>
</Mesh>
<Bitmap Name="GroundBitmap">
<Producers>
<BitmapCells/>
</Producers>
</Bitmap>
<Material Name="GroundMaterial" Shader="TextureShader">
<Textures>
<MaterialTexture Texture="GroundBitmap" TextureScale="10 10 1" TextureWrapMode="1"/>
</Textures>
</Material>
<Material Name="AlphaMaterial" Shader="AlphaShader"/>
<Material Name="BasicMaterial" Shader="TextureShader">
<Textures>
<MaterialTexture Texture="GroundBitmap"/>
</Textures>
</Material>
<Material Name="FlatShadowMaterial" Shading="1" EmissionColor="1 1 1 1" Shader="FlatShadowShader"/>
<Shader Name="BasicShader">
<VertexShaderSource>
<![CDATA[//
precision mediump float;
varying vec4 colorVar;
//The variables below are predefined in ZGE
uniform mat4 modelViewProjectionMatrix;
attribute vec3 position; //vertex position
attribute vec4 color; //vertex color
void main()
{
colorVar = color;
// project the transformed position
vec4 p = modelViewProjectionMatrix * vec4(position, 1.0);
gl_Position = p;
}]]>
</VertexShaderSource>
<FragmentShaderSource>
<![CDATA[//
precision mediump float;
varying vec4 colorVar;
void main() {
gl_FragColor = colorVar;
}]]>
</FragmentShaderSource>
</Shader>
<Shader Name="FlatShadowShader">
<VertexShaderSource>
<![CDATA[//
precision mediump float;
varying vec4 colorVar;
//The variables below are predefined in ZGE
uniform mat4 modelViewProjectionMatrix;
attribute vec3 position; //vertex position
attribute vec4 color; //vertex color
void main()
{
colorVar = color;
// project the transformed position
vec4 p = modelViewProjectionMatrix * vec4(position, 1.0);
gl_Position = p;
}]]>
</VertexShaderSource>
<FragmentShaderSource>
<![CDATA[//
precision mediump float;
varying vec4 colorVar;
void main() {
gl_FragColor = colorVar;
}]]>
</FragmentShaderSource>
</Shader>
<Shader Name="AlphaShader">
<VertexShaderSource>
<![CDATA[//
precision mediump float;
//The variables below are predefined in ZGE
uniform mat4 modelViewProjectionMatrix;
attribute vec3 position; //vertex position
void main()
{
// project the transformed position
vec4 p = modelViewProjectionMatrix * vec4(position, 1.0);
gl_Position = p;
}]]>
</VertexShaderSource>
<FragmentShaderSource>
<![CDATA[//
void main() {
gl_FragColor = vec4(0.0, 0.0, 0.0, 0.6);
}]]>
</FragmentShaderSource>
</Shader>
<Shader Name="TextureShader">
<VertexShaderSource>
<![CDATA[//
precision mediump float;
varying vec2 tc;
//The variables below are predefined in ZGE
uniform mat4 modelViewProjectionMatrix;
uniform mat4 textureMatrix;
attribute vec3 position; //vertex position
attribute vec2 texCoord; //vertex texture coordinate
//attribute vec3 normal; //vertex normal
void main() {
tc=(textureMatrix * vec4(texCoord,0,1)).xy;
// project the transformed position
vec4 p = modelViewProjectionMatrix * vec4(position, 1.0);
gl_Position = p;
}]]>
</VertexShaderSource>
<FragmentShaderSource>
<![CDATA[//
precision mediump float;
varying vec2 tc;
uniform sampler2D tex1;
void main() {
gl_FragColor = texture2D(tex1, tc);
}]]>
</FragmentShaderSource>
</Shader>
</Content>
</ZApplication>
1- The first should display the same texture as the ground, but it is black instead.
2- I don't get how to display flat shadow on the sphere as it is rendered in normal ZGE.
3- I managed to make the third sphere semi transparent, so I'm quite happy with that
I have a few other questions, but let's do that one per one
Thanks