RenderMonkey opengles example compile failed with error C0118: macros prefixed with 'GL_' are reserved

204 views Asked by At

I trying to use RenderMonkey 1.82 on Win10 PC, and graphics card is NVIDIA Geforce 405 v342.01. I cannot use the OpenGL ES examples that comes with it. I remember once I could do this on another machine. Is this an compatibility problem?

Vertex shader:

uniform mat4 view_proj_matrix;
uniform vec4 view_position;

attribute vec4 rm_Vertex;
attribute vec3 rm_Normal;

varying vec3 vNormal;
varying vec3 vViewVec;

void main(void)
{
   gl_Position = view_proj_matrix * rm_Vertex;

   // World-space lighting
   vNormal = rm_Normal;
   vViewVec = view_position.xyz - rm_Vertex.xyz;


}

Fragment shader:

precision mediump float;
uniform vec4 color;

varying vec3 vNormal;
varying vec3 vViewVec;

void main(void)
{
   float v = 0.5 * (1.0 + dot(normalize(vViewVec), vNormal));
   gl_FragColor = v * color;

}

The error message is:

OpenGL ES Preview Window: Compiling vertex shader API(OpenGL ES)
/../Plastic_OpenGL_ES/Single Pass/Vertex Program/ ... failure 

0(8) :
error C0118: macros prefixed with 'GL_' are reserved 

OpenGL ES Preview
Window: Compiling fragment shader API(OpenGL ES)
/../Plastic_OpenGL_ES/Single Pass/Fragment Program/ ... failure 

0(3) :
error C0118: macros prefixed with 'GL_' are reserved 

RENDERING
ERROR(s):  Vertex program 'Vertex Program' failed to compile in pass
'Single Pass'.  See Output window for details Fragment program

'Fragment Program' failed to compile in pass 'Single Pass'.  See
Output window for details
1

There are 1 answers

0
MuertoExcobito On

RenderMonkey adds a bunch of definitions onto the shaders before sending them to the GLSL compiler. You can verify this by running it through CodeXL, and then inspecting the text of the shaders. For my machine, this seems to be the standard (for vertex shaders, fragment shaders are similar):

#version 120
attribute float _J_K_;
void _VSh();void main()
{
   _VSh();   gl_Position += (vec4(_J_K_) - vec4(_J_K_));
}
#define main _VSh
#define GL_ES
#define highp
#define mediump
#define lowp
#define invariant
#define gl_MaxVertexAttribs 15
#define gl_MaxVertexUniformVectors 224
#define gl_MaxVaryingVectors 8
#define gl_MaxVertexTextureImageUnits 0
#define gl_MaxCombinedTextureImageUnits 8
#define gl_MaxTextureImageUnits 8
#define gl_MaxFragmentUniformVectors 256
#define gl_MaxDrawBuffers 1

As you can see, on line 8, #define GL_ES is the error you are hitting (and this occurs on line 3 for fragment shaders).

In the GLSL ES spec, it states:

All macro names prefixed with “GL_” (“GL” followed by a single underscore) are also reserved, and defining such a name results in a compile-time error.

Thus, your driver is doing the correct thing, and rejecting this shader because it in fact violates the spec. Likely in very old Nvidia drivers, this error was not reported. You would need to recompile RenderMonkey to property resolve this issue, and the sources are not public.

However, you can hack RenderMonkey to get this to compile these shaders. These extra strings that are prepended are contained in the libGLESv2.dll in plain text, and you can use a hex editor to change them to something that doesn't start with GL_. They occur at offsets 0x16052E and 0x1606A0.

Or, instead just use the GL2 workspaces for developing your shaders, since GLSL and GLSL ES are very similar.