Question

I'm trying to run a GLSL example, but I can't.

The error is in the line glGetShaderiv(vShader, GL_COMPILE_STATUS, &status); where the program exits. vShader is the file vPhong.glsl.

The error returned is:

0(18) : error C0000: syntax error, unexpected $undefined at token "<undefined>"
0(18) : error C0501: type name expected at token "<undefined>"

I have 'installed' and referenced GLEW and Glut and their lib-files. I have glewInit'ed my program.

The program is able to find the .glsl-files.

The weird thing is that I am able to run a precompiled GLSL-demo, and also compile and run the project on my pc. The "initializations" in the non-working program and this are the same.

I have tried copying the defective source into the successful project, to see if there was something in the project settings causing the error, but unfortunately, that wasn't the case. So the error seems to be in the C++ code, not the project.


PROGRESS:

On my Windows 7-machine i got "Access violation" when running through Visual Studio. The program just stopped working if I ran it "alone". On a Windows XP-machine I got an uncaught exception.

I received no errors or warnings (apart from a warning that fopen is unsafe) when I compiled the program.

Visual Studio highlighted the line vShader = glCreateShader(GL_VERTEX_SHADER); as the source of the error.

Adding glewInit(); fixed the above errors.

Was it helpful?

Solution

There were two errors in the program:

First:

glLinkProgram(program);
glGetShaderiv(program, GL_LINK_STATUS, &status);

The last line should have been glGetProgramiv(program, GL_LINK_STATUS, &status);.

Also, the fopen that read in the shader files should have been used with rb as an argument instead of just r.

Substituting glGetShaderiv with glGetProgramiv and adding glewInit() fixed one of my initial errors.

Changing the argument to fopen fixed the shader error.

OTHER TIPS

Those errors are coming from the GLSL compiler, not the C++ compiler. At line 18 in some shader, you have something that is confusing the GLSL compiler; probably random garbage or an unprintable character. One easy way to do this is to specify too long a length (or no length at all) for your shader source, and not have a NUL-terminator at the end of the string

I'm not sure how you compiled that code. It's using GL API that is not directly available in the windows SDK. All the shader APIs are in that category.

To access them on windows, you generally need to use the extension mechanism provide by wgl, or use an extension wrapper.

[edit to add]

So... with glew init out of the way! Shader compilation provides a build log when failing to build (taken from this tutorial):

GLint blen = 0; 
GLsizei slen = 0;

glGetShaderiv(ShaderObject, GL_INFO_LOG_LENGTH , &blen);       

if (blen > 1)
{
 GLchar* compiler_log = (GLchar*)malloc(blen);

 glGetInfoLogARB(ShaderObject, blen, &slen, compiler_log);
 cout << "compiler_log:\n", compiler_log);
 free (compiler_log);
}

That error message usually means there is some kind of error in your shader program file itself. In my experience, it's been something like an unexpected character at the beginning or end of the file. Try copying and pasting the text from that URL into notepad or gedit and then saving the file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top