-2

Error:

ERROR: 0:1: 'basicVertex120' : syntax error parse error

Code:

#version 120

attribute vec3 position;
attribute vec2 texCoord;

varying vec2 texCoord0;

uniform mat4 transform;

void main()
{
    gl_Position = transform * vec4(position, 1.0);
    texCoord0 = texCoord;
}

I have been following the tutorial from here: http://www.youtube.com/watch?v=8n1GV99FJ2Y&list=PLEETnX-uPtBXP_B2yupUKlflXBznWIlL5&index=11

All code from his tutorial are here: https://github.com/BennyQBD/3DGameEngine

I am not following it exactly, but as far as shader class and all go it is exactly the same. If you need any other code posted... let me know.

I am still very new to OpenGL 2.0+ and GLSL and trying to figure out how to know which line has the error. Is there something for vertex shaders like GL11.glGetError();?

Are there any tools I can use or documetation I can browse over to try and solve the issue?

I would really like to learn to solve these issues myself. How can I do that?

Zeveso
  • 1,274
  • 3
  • 21
  • 41
  • 2
    Yes, use glGetShaderInfoLog (I see it did do this though in the source you linked). More importantly is that I don't see anywhere you request a OpenGL version. I don't think a 2.0 context which gives glsl 1.1 will have the #version directive, but this is just a guess as I only work OpenGL 3.1+. – Xonar Nov 21 '13 at 15:09
  • I have used glGetShaderInfoLog in the code, as it gave no real information... I figured that it was useless. - The OpenGL Version I am running is 3.0, it does print it how... however I did not include it. #Version 120 equates to OpenGL 2.1, although I am not quite sure what your third sentence means. – Zeveso Nov 21 '13 at 21:07
  • @Xonar: This is actually a bit of a grey area. Early versions of the GLSL 1.1 spec. did not define the `#version` or `#extension` pre-processor directives, so some early implementations may not support it. I have never encountered this problem though. – Andon M. Coleman Nov 21 '13 at 21:33

1 Answers1

2

This happens quite frequently when people try to read shader files line-by-line instead of reading the entire file all at once. They often forget that when reading a line-buffered file, the line ending is removed from each line. Thus, everything winds up on line 1 and the pre-processor thinks that the entire shader is one ridiculously long #version directive.

If you followed that code verbatim this should not be an issue, but you never know.

I would consider querying the shader string back from GL and seeing what it is actually parsing, as well as the compiler log:

GLsizei src_len,
        log_len;

glGetShaderiv (shader, GL_INFO_LOG_LENGTH,      &log_len);
glGetShaderiv (shader, GL_SHADER_SOURCE_LENGTH, &src_len);

GLchar* src_str = calloc (src_len + 1, sizeof (GLchar));
GLchar* log_str = calloc (log_len + 1, sizeof (GLchar));

glGetShaderInfoLog (shader, log_len, NULL, log_str);
glGetShaderSource  (shader, src_len, NULL, src_str);

printf ("Shader %d\n",      shader);
printf (" >> Info:   %s\n", log_str);
printf (" >> Source: %s\n", src_str);

free (log_str);
free (src_str);

I realize this is written in C; I am not familiar with the Java bindings but the general process is the same.

Andon M. Coleman
  • 42,359
  • 2
  • 81
  • 106
  • I can't take a good look at it now like I want, so I will be doing that tomorrow. However, i will say this. When I request the shader source, using 'glGetShaderSource' I get a length of 18 and the source looks as follows: "basicVertex120.vs" which makes me think something is coded enormously wrong since that is the name, not the source. Like I said, ill have to get back to you. - As I have yet to try to solve the issue after your post. – Zeveso Nov 21 '13 at 21:30