switch the example to ES2/GL3, the shaders need to be re-written
That is exactly what I did
I added text to your example to see what's going on, and another shader that isn't using values x and y.
On PC, the glGetUniformLocation values are 1 and 2.

- Screenshot 2025-07-11 172308.png (1.83 KiB) Viewed 74 times
On Android, it's 0 and 0... And the square isn't showing up. I believe it's because 0 corresponds to modelViewProjectionMatrix ?

- Screenshot 2025-07-11 172257.png (1.87 KiB) Viewed 74 times
Code: Select all
<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="Debug Personality" GLBase="1" FileVersion="2" AndroidPackageName="com.txori.debug_personality">
<OnLoaded>
<ZExternalLibrary ModuleName="opengl32">
<BeforeInitExp>
<![CDATA[//
if (ANDROID)
{
ModuleName="libGLESv2.so";
}]]>
</BeforeInitExp>
<Source>
<![CDATA[//
int glGetUniformLocation(int program, string name){}
void glUniform1f(int location, float v0){}]]>
</Source>
</ZExternalLibrary>
<ZExpression>
<Expression>
<![CDATA[//
@UseMaterial(Material: DemoMaterial);
DemoLocations[0] = glGetUniformLocation(DemoShader.Handle, "x");
DemoLocations[1] = glGetUniformLocation(DemoShader.Handle, "y");]]>
</Expression>
</ZExpression>
</OnLoaded>
<OnRender>
<UseMaterial Material="BasicMaterial"/>
<RenderMesh Mesh="DemoMesh"/>
<UseMaterial Material="DemoMaterial"/>
<ZExpression>
<Expression>
<![CDATA[//
glUniform1f(DemoLocations[0], sin(App.Time));
glUniform1f(DemoLocations[1], cos(App.Time));]]>
</Expression>
</ZExpression>
<RenderMesh Mesh="DemoMesh"/>
<UseMaterial Material="FontArcadeMaterial"/>
<RenderText Scale="0.3" TextExpression="intToStr(DemoLocations[0])+" "+intToStr(sin(App.Time)*100.0)+" - "+intToStr(DemoLocations[1])+" "+intToStr(cos(App.Time)*100.0);"/>
</OnRender>
<Content>
<Array Name="DemoLocations" Type="1" SizeDim1="2"/>
<Material Name="DemoMaterial" Shader="DemoShader"/>
<Mesh Name="DemoMesh">
<Producers>
<MeshBox Scale="0.5 0.5 1" Grid2DOnly="255"/>
<MeshExpression VertexColors="255">
<Expression>
<![CDATA[C.R = V.X;
C.G = V.Y;
C.B = V.Z;]]>
</Expression>
</MeshExpression>
</Producers>
</Mesh>
<Shader Name="DemoShader">
<VertexShaderSource>
<![CDATA[#ifdef GL_ES
precision mediump float;
#endif
uniform mat4 modelViewProjectionMatrix;
uniform float x;
uniform float y;
attribute vec4 position;
void main()
{
// gl_Position = modelViewProjectionMatrix * position;
gl_Position = modelViewProjectionMatrix * (position + vec4(x, y, 0.0f, 0.0f));
}]]>
</VertexShaderSource>
<FragmentShaderSource>
<![CDATA[#ifdef GL_ES
precision mediump float;
#endif
void main()
{
gl_FragColor = vec4(1.0f, 0.0f, 0.0f, 1.0f);
}]]>
</FragmentShaderSource>
</Shader>
<Group Comment="Arcade">
<Children>
<Bitmap Name="FontArcadeBitmap" Width="144" Height="44" Filter="1">
<Producers>
<BitmapFromFile Comment="Imported from Arcade.png" Transparency="2" HasAlphaLayer="1" DataWidth="144" DataHeight="44">
<BitmapFile>
<![CDATA[789CED58419283300CEBFF3F9D1E3A7442B065390152527946871261CB8E08CB96525E451004411004E1BFB005CBABF9C558B7F8280FAA8DD6B379D8FC5E1F595D8CDE48F713C0F4D072AC7BEA6BDE6CD86BEC5E64F72D5AB3B80C6754C793E105E38D6270B273425C6F2DD2C86A4291C993ED07DDFF34A0798D70BC595991DD8B8C9EE2FCCEF887DDFB28C78A1EB27A69AF5DC9C96ABB4A4F7138ACE799FA2B7A08CDEB6A8E75CF2CFF449CE2FC1EED0D719E002F18DE19797A34A1FA33389967C58AD91E10849FC3167772106F869E3B34AF8A3B7BFFD719AF8C3BF754FE590FD59E6E51AFB7D7BCB0CE319303F258FADC7A40B3876C1E740D6967D72DFE68EF3D9CCC7E9CE51F56CFEE37A8E5698E7A617B8DEAB17DF5E845B58AB13ED23BDB27E264E61A9D093DB5CCDACDF9C46A8EFA60FAECD58C723375993D1CA951AF17E79E9663D5B4EAD0FD9DF5FE626A0FF827AA95D163F1505CED9FDE6783D19CE1A4FB6BBE4D993CBD1C66363D7DF4D6EAD573A67F466BA0405E457A7AFA3B9C0BAD9F188F05EFA796E3F640789A5E0FCEBB545FCEB7419BC7DDE70B7BDF38874406E712FF38F75AF77B61CDEFC009F2649EB1CC33C8D4441A337A500FBDB5D8BC67D4627B120441F8498077793ACF59B90441783CEAF85E37BE53DA88D677F988754F17D23BC24135466ACDDECF19DEA97F7FFD637D9F82EFD6DDEC886FE568DEEC3D560F6C2DA421CB67D657029C73F2FF1B6DEC38CEDF3BBB42468EA3985C1E97D372DBEBD59AD91FABC7585B09E19C09BEB58E78070ED8F7A89EC7F3223387919EBE8D11DA9F8CBA55F83CD67CF0DC59F30CF7CB39C7A0BF8DC8F89CF590959FA9F5B9B0BE7F5E5B9FEDF3EF9DF3ED223343E7ACB7EEF13C82CEA88C1F58BF441CF9C7DFAF57B1FD1379C20ACF33071ED2E4F93893C3E0A06073647A5F16D6FB089C1B708DC93DA3B7191A56F78FD75FE48FCC7ECCDCBFD958BD67E66C893867CC6FC539FFC333C37845103CC83F42F9C46C0D82200882200882200802C01B50635CC2]]>
</BitmapFile>
</BitmapFromFile>
</Producers>
</Bitmap>
<Font Name="FontArcade" Bitmap="FontArcadeBitmap" FirstChar="32" CharPixelWidth="8" CharPixelHeight="10" BorderPixels="1"/>
<Material Name="FontArcadeMaterial" Light="0" Blend="1" ZBuffer="0" Font="FontArcade" Shader="FontShader"/>
<Shader Name="FontShader">
<VertexShaderSource>
<![CDATA[//
#ifdef GL_ES
precision mediump float;
#endif
varying vec2 tc;
uniform mat4 modelViewProjectionMatrix;
uniform mat4 textureMatrix;
attribute vec4 position; //vertex position
attribute vec2 texCoord; //vertex texture coordinate
void main()
{
tc = (textureMatrix * vec4(texCoord,0,1)).xy;
gl_Position = modelViewProjectionMatrix * position;
}
//]]>
</VertexShaderSource>
<FragmentShaderSource>
<![CDATA[//
#ifdef GL_ES
precision mediump float;
#endif
varying vec2 tc; // texCoordVarying
uniform sampler2D tex1;
void main()
{
gl_FragColor = texture2D(tex1, tc);
}
//]]>
</FragmentShaderSource>
</Shader>
</Children>
</Group>
<Shader Name="BasicShader">
<VertexShaderSource>
<![CDATA[//
#ifdef GL_ES
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif
#endif
varying vec4 v_color;
//The variables below are predefined in ZGE
uniform mat4 modelViewProjectionMatrix;
attribute vec4 position; //vertex position
attribute vec4 color; //vertex color
void main()
{
v_color = color;
gl_Position = modelViewProjectionMatrix * position;
}
//]]>
</VertexShaderSource>
<FragmentShaderSource>
<![CDATA[//
#ifdef GL_ES
precision mediump float;
#endif
varying vec4 v_color;
void main() {
gl_FragColor = v_color;
}
//]]>
</FragmentShaderSource>
</Shader>
<Material Name="BasicMaterial" Shader="BasicShader"/>
</Content>
</ZApplication>
Edit:
Setting this manually doesn't make the rotating cube appear on Android either.
Code: Select all
DemoLocations[0] = 1;
DemoLocations[1] = 2;
But the main problem is glGetUniformLocation that returns 0
I moved that to OnBeginRenderPass:
Code: Select all
@UseMaterial(Material: DemoMaterial);
DemoLocations[0] = glGetUniformLocation(DemoShader.Handle, "x");
DemoLocations[1] = glGetUniformLocation(DemoShader.Handle, "y");
Now the numbers are 1 and 1 on Android. Still no rotating square.
Edit 2:
All right, the square isn't showing up on Android because of the "f" in "0.0f". It works fine without them. I used text-compare to spot the difference

Here's the last test with a visible cube on Android, but glGetUniformLocation isn't working.
Code: Select all
<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="Debug Personality" GLBase="1" FileVersion="2" AndroidPackageName="com.txori.debug_personality">
<OnLoaded>
<ZExternalLibrary ModuleName="opengl32">
<BeforeInitExp>
<![CDATA[//
if (ANDROID)
{
ModuleName="libGLESv2.so";
}]]>
</BeforeInitExp>
<Source>
<![CDATA[//
int glGetUniformLocation(int program, string name){}
void glUniform1f(int location, float v0){}]]>
</Source>
</ZExternalLibrary>
<ZExpression>
<Expression>
<![CDATA[//
@UseMaterial(Material: DemoMaterial);
// Returns 0 and 0 on Android
DemoLocations[0] = glGetUniformLocation(DemoShader.Handle, "x");
DemoLocations[1] = glGetUniformLocation(DemoShader.Handle, "y");
//DemoLocations[0] = 1;
//DemoLocations[1] = 2;]]>
</Expression>
</ZExpression>
</OnLoaded>
<OnRender>
<UseMaterial Material="DemoMaterial"/>
<ZExpression>
<Expression>
<![CDATA[//
glUniform1f(DemoLocations[0], sin(App.Time));
glUniform1f(DemoLocations[1], cos(App.Time));]]>
</Expression>
</ZExpression>
<RenderMesh Mesh="DemoMesh"/>
<UseMaterial Material="FontArcadeMaterial"/>
<RenderText Scale="0.3" TextExpression="intToStr(DemoLocations[0])+" "+intToStr(sin(App.Time)*100.0)+" - "+intToStr(DemoLocations[1])+" "+intToStr(cos(App.Time)*100.0);"/>
</OnRender>
<Content>
<Array Name="DemoLocations" Type="1" SizeDim1="2"/>
<Material Name="DemoMaterial" Shader="DemoShader"/>
<Mesh Name="DemoMesh">
<Producers>
<MeshBox Scale="0.5 0.5 1" Grid2DOnly="255"/>
<MeshExpression VertexColors="255">
<Expression>
<![CDATA[C.R = V.X;
C.G = V.Y;
C.B = V.Z;]]>
</Expression>
</MeshExpression>
</Producers>
</Mesh>
<Shader Name="DemoShader">
<VertexShaderSource>
<![CDATA[//
#ifdef GL_ES
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif
#endif
uniform mat4 modelViewProjectionMatrix;
uniform float x;
uniform float y;
attribute vec4 position; //vertex position
void main()
{
gl_Position = modelViewProjectionMatrix * (position + vec4(x, y, 0.0, 0.0));
}
//]]>
</VertexShaderSource>
<FragmentShaderSource>
<![CDATA[//
#ifdef GL_ES
precision mediump float;
#endif
void main() {
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
//]]>
</FragmentShaderSource>
</Shader>
<Group Comment="Arcade">
<Children>
<Bitmap Name="FontArcadeBitmap" Width="144" Height="44" Filter="1">
<Producers>
<BitmapFromFile Comment="Imported from Arcade.png" Transparency="2" HasAlphaLayer="1" DataWidth="144" DataHeight="44">
<BitmapFile>
<![CDATA[789CED58419283300CEBFF3F9D1E3A7442B065390152527946871261CB8E08CB96525E451004411004E1BFB005CBABF9C558B7F8280FAA8DD6B379D8FC5E1F595D8CDE48F713C0F4D072AC7BEA6BDE6CD86BEC5E64F72D5AB3B80C6754C793E105E38D6270B273425C6F2DD2C86A4291C993ED07DDFF34A0798D70BC595991DD8B8C9EE2FCCEF887DDFB28C78A1EB27A69AF5DC9C96ABB4A4F7138ACE799FA2B7A08CDEB6A8E75CF2CFF449CE2FC1EED0D719E002F18DE19797A34A1FA33389967C58AD91E10849FC3167772106F869E3B34AF8A3B7BFFD719AF8C3BF754FE590FD59E6E51AFB7D7BCB0CE319303F258FADC7A40B3876C1E740D6967D72DFE68EF3D9CCC7E9CE51F56CFEE37A8E5698E7A617B8DEAB17DF5E845B58AB13ED23BDB27E264E61A9D093DB5CCDACDF9C46A8EFA60FAECD58C723375993D1CA951AF17E79E9663D5B4EAD0FD9DF5FE626A0FF827AA95D163F1505CED9FDE6783D19CE1A4FB6BBE4D993CBD1C66363D7DF4D6EAD573A67F466BA0405E457A7AFA3B9C0BAD9F188F05EFA796E3F640789A5E0FCEBB545FCEB7419BC7DDE70B7BDF38874406E712FF38F75AF77B61CDEFC009F2649EB1CC33C8D4441A337A500FBDB5D8BC67D4627B120441F8498077793ACF59B90441783CEAF85E37BE53DA88D677F988754F17D23BC24135466ACDDECF19DEA97F7FFD637D9F82EFD6DDEC886FE568DEEC3D560F6C2DA421CB67D657029C73F2FF1B6DEC38CEDF3BBB42468EA3985C1E97D372DBEBD59AD91FABC7585B09E19C09BEB58E78070ED8F7A89EC7F3223387919EBE8D11DA9F8CBA55F83CD67CF0DC59F30CF7CB39C7A0BF8DC8F89CF590959FA9F5B9B0BE7F5E5B9FEDF3EF9DF3ED223343E7ACB7EEF13C82CEA88C1F58BF441CF9C7DFAF57B1FD1379C20ACF33071ED2E4F93893C3E0A06073647A5F16D6FB089C1B708DC93DA3B7191A56F78FD75FE48FCC7ECCDCBFD958BD67E66C893867CC6FC539FFC333C37845103CC83F42F9C46C0D82200882200882200802C01B50635CC2]]>
</BitmapFile>
</BitmapFromFile>
</Producers>
</Bitmap>
<Font Name="FontArcade" Bitmap="FontArcadeBitmap" FirstChar="32" CharPixelWidth="8" CharPixelHeight="10" BorderPixels="1"/>
<Material Name="FontArcadeMaterial" Light="0" Blend="1" ZBuffer="0" Font="FontArcade" Shader="FontShader"/>
<Shader Name="FontShader">
<VertexShaderSource>
<![CDATA[//
#ifdef GL_ES
precision mediump float;
#endif
varying vec2 tc;
uniform mat4 modelViewProjectionMatrix;
uniform mat4 textureMatrix;
attribute vec4 position; //vertex position
attribute vec2 texCoord; //vertex texture coordinate
void main()
{
tc = (textureMatrix * vec4(texCoord,0,1)).xy;
gl_Position = modelViewProjectionMatrix * position;
}
//]]>
</VertexShaderSource>
<FragmentShaderSource>
<![CDATA[//
#ifdef GL_ES
precision mediump float;
#endif
varying vec2 tc; // texCoordVarying
uniform sampler2D tex1;
void main()
{
gl_FragColor = texture2D(tex1, tc);
}
//]]>
</FragmentShaderSource>
</Shader>
</Children>
</Group>
</Content>
</ZApplication>
Edit 3:
I made glGetUniformLocation work by moving everything in OnRender:
Code: Select all
<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="Debug Personality" GLBase="1" FileVersion="2" AndroidPackageName="com.txori.debug_personality">
<OnLoaded>
<ZExternalLibrary ModuleName="opengl32">
<BeforeInitExp>
<![CDATA[//
if (ANDROID)
{
ModuleName="libGLESv2.so";
}]]>
</BeforeInitExp>
<Source>
<![CDATA[//
int glGetUniformLocation(int program, string name){}
void glUniform1f(int location, float v0){}]]>
</Source>
</ZExternalLibrary>
</OnLoaded>
<OnRender>
<UseMaterial Material="DemoMaterial"/>
<ZExpression>
<Expression>
<![CDATA[//
DemoLocations[0] = glGetUniformLocation(DemoShader.Handle, "x");
DemoLocations[1] = glGetUniformLocation(DemoShader.Handle, "y");
glUniform1f(DemoLocations[0], sin(App.Time));
glUniform1f(DemoLocations[1], cos(App.Time));]]>
</Expression>
</ZExpression>
<RenderMesh Mesh="DemoMesh"/>
<UseMaterial Material="FontArcadeMaterial"/>
<RenderText Scale="0.3" TextExpression="intToStr(DemoLocations[0])+" "+intToStr(sin(App.Time)*100.0)+" - "+intToStr(DemoLocations[1])+" "+intToStr(cos(App.Time)*100.0);"/>
</OnRender>
<Content>
<Array Name="DemoLocations" Type="1" SizeDim1="2"/>
<Material Name="DemoMaterial" Shader="DemoShader"/>
<Mesh Name="DemoMesh">
<Producers>
<MeshBox Scale="0.5 0.5 1" Grid2DOnly="255"/>
<MeshExpression VertexColors="255">
<Expression>
<![CDATA[C.R = V.X;
C.G = V.Y;
C.B = V.Z;]]>
</Expression>
</MeshExpression>
</Producers>
</Mesh>
<Shader Name="DemoShader">
<VertexShaderSource>
<![CDATA[//
#ifdef GL_ES
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif
#endif
uniform mat4 modelViewProjectionMatrix;
uniform float x;
uniform float y;
attribute vec4 position; //vertex position
void main()
{
gl_Position = modelViewProjectionMatrix * (position + vec4(x, y, 0.0, 0.0));
}
//]]>
</VertexShaderSource>
<FragmentShaderSource>
<![CDATA[//
#ifdef GL_ES
precision mediump float;
#endif
void main() {
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
//]]>
</FragmentShaderSource>
</Shader>
<Group Comment="Arcade">
<Children>
<Bitmap Name="FontArcadeBitmap" Width="144" Height="44" Filter="1">
<Producers>
<BitmapFromFile Comment="Imported from Arcade.png" Transparency="2" HasAlphaLayer="1" DataWidth="144" DataHeight="44">
<BitmapFile>
<![CDATA[789CED58419283300CEBFF3F9D1E3A7442B065390152527946871261CB8E08CB96525E451004411004E1BFB005CBABF9C558B7F8280FAA8DD6B379D8FC5E1F595D8CDE48F713C0F4D072AC7BEA6BDE6CD86BEC5E64F72D5AB3B80C6754C793E105E38D6270B273425C6F2DD2C86A4291C993ED07DDFF34A0798D70BC595991DD8B8C9EE2FCCEF887DDFB28C78A1EB27A69AF5DC9C96ABB4A4F7138ACE799FA2B7A08CDEB6A8E75CF2CFF449CE2FC1EED0D719E002F18DE19797A34A1FA33389967C58AD91E10849FC3167772106F869E3B34AF8A3B7BFFD719AF8C3BF754FE590FD59E6E51AFB7D7BCB0CE319303F258FADC7A40B3876C1E740D6967D72DFE68EF3D9CCC7E9CE51F56CFEE37A8E5698E7A617B8DEAB17DF5E845B58AB13ED23BDB27E264E61A9D093DB5CCDACDF9C46A8EFA60FAECD58C723375993D1CA951AF17E79E9663D5B4EAD0FD9DF5FE626A0FF827AA95D163F1505CED9FDE6783D19CE1A4FB6BBE4D993CBD1C66363D7DF4D6EAD573A67F466BA0405E457A7AFA3B9C0BAD9F188F05EFA796E3F640789A5E0FCEBB545FCEB7419BC7DDE70B7BDF38874406E712FF38F75AF77B61CDEFC009F2649EB1CC33C8D4441A337A500FBDB5D8BC67D4627B120441F8498077793ACF59B90441783CEAF85E37BE53DA88D677F988754F17D23BC24135466ACDDECF19DEA97F7FFD637D9F82EFD6DDEC886FE568DEEC3D560F6C2DA421CB67D657029C73F2FF1B6DEC38CEDF3BBB42468EA3985C1E97D372DBEBD59AD91FABC7585B09E19C09BEB58E78070ED8F7A89EC7F3223387919EBE8D11DA9F8CBA55F83CD67CF0DC59F30CF7CB39C7A0BF8DC8F89CF590959FA9F5B9B0BE7F5E5B9FEDF3EF9DF3ED223343E7ACB7EEF13C82CEA88C1F58BF441CF9C7DFAF57B1FD1379C20ACF33071ED2E4F93893C3E0A06073647A5F16D6FB089C1B708DC93DA3B7191A56F78FD75FE48FCC7ECCDCBFD958BD67E66C893867CC6FC539FFC333C37845103CC83F42F9C46C0D82200882200882200802C01B50635CC2]]>
</BitmapFile>
</BitmapFromFile>
</Producers>
</Bitmap>
<Font Name="FontArcade" Bitmap="FontArcadeBitmap" FirstChar="32" CharPixelWidth="8" CharPixelHeight="10" BorderPixels="1"/>
<Material Name="FontArcadeMaterial" Light="0" Blend="1" ZBuffer="0" Font="FontArcade" Shader="FontShader"/>
<Shader Name="FontShader">
<VertexShaderSource>
<![CDATA[//
#ifdef GL_ES
precision mediump float;
#endif
varying vec2 tc;
uniform mat4 modelViewProjectionMatrix;
uniform mat4 textureMatrix;
attribute vec4 position; //vertex position
attribute vec2 texCoord; //vertex texture coordinate
void main()
{
tc = (textureMatrix * vec4(texCoord,0,1)).xy;
gl_Position = modelViewProjectionMatrix * position;
}
//]]>
</VertexShaderSource>
<FragmentShaderSource>
<![CDATA[//
#ifdef GL_ES
precision mediump float;
#endif
varying vec2 tc; // texCoordVarying
uniform sampler2D tex1;
void main()
{
gl_FragColor = texture2D(tex1, tc);
}
//]]>
</FragmentShaderSource>
</Shader>
</Children>
</Group>
</Content>
</ZApplication>
Maybe it's another case of openGL not initialized before a first forced render or something?