Bug in SDK v3.0 R2? Incorrect Shader Result for Simple ES 2.0 Application

I have a simple ES 2.0 application that draws a cylinder and calculates Blinn Phong lighting on it.

No textures used, no extensions used.

But I got different results when running it on 2 machines, one desktop, one laptop.

The result from the laptop result in cylinder only displaying the ambient color, which is incorrect.

The result from desktop is what I expected, with the part closer to light source being brighter:

Below are the settings for the 2 machines:

desktop: Windows 7, SDK v3.0, Nvidia Quadro 400 , Visual Studio C++ 2008 Express , linked against libGLESv2.dll, libEGL.dll

laptop : Windows 8, SDK v3.0 R2, Nvidia Geforce 635M, Visual Studio C++ 2008 Express , linked against libGLESv2.dll, libEGL.dll

I’m not sure if this is a problem of the operating system (win7 vs win8) or the SDK (v3,0 vs v3,0 R2), since my code is the same.

I tried to display intermediate results directly, and found that the cosAngIncidence (output of dot(surfaceNormal, lightDir)) is different for the 2 platforms.

I displayed the values using the following code:

gl_FragColor = vec4(cosAngIncidence , 0.0, 0.0, 1.0);

On desktop, there’s a spot being red where the light is brightest. Whereas on laptop, the cylinder is entirely black.

And I checked the input to the dot function (namely, surfaceNormal and lightDir), and both output similar colors on screen.

gl_FragColor = vec4(surfaceNormal, 1.0);

I’ve no idea what to look for now, can anyone help me?

(Another thing is, I cannot install SDK v3.0 on my laptop, it’ll say error, version incorrect or something like that during downloaing of installation.

And I’m afraid to uninstall the SDK v3.0 on the desktop and try out the v3.0 R2, since I might not be able to reinstall the old version afterwards.)

Fragment shader code:

precision mediump float;

uniform vec4 lightIntensity;

uniform vec4 ambientIntensity;

uniform float lightAttenuation;

uniform float shininessFactor;

varying vec4 diffuseColor;

varying vec3 normal;

varying vec3 cameraSpacePosition;

varying vec3 cameraSpaceLightPos;

const vec4 specularColor = vec4(0.25, 0.25, 0.25, 1.0);

float CalcAttenuation(in vec3 cameraSpacePosition, out vec3 lightDirection)


vec3 lightDifference = cameraSpaceLightPos - cameraSpacePosition;

float lightDistanceSqr = dot(lightDifference, lightDifference);

lightDirection = lightDifference * inversesqrt(lightDistanceSqr);

return (1.0 / ( 1.0 + lightAttenuation * sqrt(lightDistanceSqr)));


void main()


vec3 lightDir = vec3(0.0);

float atten = CalcAttenuation(cameraSpacePosition, lightDir);

vec4 attenIntensity = atten * lightIntensity;

vec3 surfaceNormal = normalize(normal);

float cosAngIncidence = dot(surfaceNormal, lightDir);

//clamp to [0, 1]

cosAngIncidence = clamp(cosAngIncidence, 0.0, 1.0);

vec3 viewDirection = normalize(-cameraSpacePosition);

vec3 halfAngle = normalize(lightDir+viewDirection);

float blinnTerm = dot(surfaceNormal, halfAngle);

//blinnTerm clamp to [0, 1]

blinnTerm = clamp(blinnTerm, 0.0, 1.0);

blinnTerm = cosAngIncidence != 0.0 ? blinnTerm : 0.0;

blinnTerm = pow(blinnTerm, shininessFactor);

gl_FragColor = (diffuseColor * attenIntensity * cosAngIncidence) +

(specularColor * attenIntensity * blinnTerm) +

(diffuseColor * ambientIntensity);


Hi Ellina

Is the shader compiling successfully, and are any GL errors being reported?

The emulator should automatically print details of any GL errors which occur while the app is running to stderr. If you open up the PVRVFrameGUI tool before running your app they should show up in the console there too.

Hi Chris,

Thanks for your quick response.

I forgot to mention that the shaders compiled successfully without any errors.

The PVRFrameGUI displayed the following, but I don’t think they are errors (both warnings and information are checked).

PVRVFrame version 9.4

Hardware profile: Host (OpenGL)

I also called glGetError after initialization, and before eglSwapBuffers, and no errors were reported.

One thing you could do just to check if it’s an environmental issue is to take the 3.0 libraries (libEGL and libGLESv2) from your desktop and manually copy them over to the laptop (make a backup of the R2 libraries first). Or vice versa.

Hi Chris,

Sorry for the late reply, I was away for the Chinese New Year Holiday.

I replaced the libEGL.dll, libEGL.lib, libGLESv2.dll, libGLESv2.lib with old ones (3.0) on the laptop and the result is the same (incorrect).

Also replaced the libEGL.dll, libEGL.lib, libGLESv2.dll, libGLESv2.lib with new ones (3.0 R2) on the desktop and the result is the same (correct).

So I guess it’s not the problem of the library, but in the environment.

But now I’m at a loss of how to keep tracking this issue…>_<

Could it be because of the Win8 operating system?

I found the problem!

It seems that my laptop has 2 GPUS: Intel HD Graphics 4000 and Nvidia Geforce GT 635M.

And the system automatically switches between the two.

So apparently it was using Intel HD Graphics 4000 when I run the OpenGL ES application through Visual Studio 2008 Express.

I manually switched over to Nvidia Geforce GPU, and then the application ran perfectly fine!

Many thanks to Chris for pointing out a direction.

Seems I can’t answer my own question, so I’ll mark Chris’s comment as answer.

Hi Ellina, I hope you had a fun new year.

I think it’s more likely the issue is with the laptop hardware itself. The OpenGL requirements of the emulator are quite high and many laptop graphics cards are not quite up to scratch. This should improve somewhat in future versions of the SDK as we work to reduce the hardware requirements of the emulator and get it running better on lower-end systems.

Is there any chance you could give me some more information regarding the GL capabilities of your laptop’s graphics card? There is a nice utility named Extensions Viewer which you can use to generate a detailed report. It would be greatly appreciated :slight_smile:


Hi Chris,

How should I give the XML file to you?

Hi Ellina

You could send it as an e-mail attachment to devtech@imgtec.com or use something like http://pastebin.com to share it with me. Whichever you find easiest!

Thanks for your help