0

I've been not into OpenGL for a long time, and never used OpenGLES at all. For my project I must use OpenGLES, the version printed by glGetString(GL_VERSION) is 3.0, but since I'm doing a collage of tutorials is perfectly possible that I'm mixing code which can't work on this version (that is why the #version tag is commented on the shaders code, but it did not fix the problem anyway).

This is the code of the vertex shader:

        const GLchar * vertex_shader_source =
//                "#version 100\n                                                             "
//                "                                                                           "
                " attribute vec2 a_TexCoordinate; /* Per-vertex texture coordinate */       "
                "                                 /* information we will pass in.  */       "
                " attribute vec2 coord2d;                                                   "
                "                                                                           "
                "                                                                           "
                " varying vec2 v_TexCoordinate;   // This will be passed into the fragment  "
                "                                                                           "
                " void main(){                                                              "
                "                                                                           "
                "       gl_Position = vec4(coord2d, 0.0, 1.0);                              "
                "                                                                           "
                "     // Pass through the texture coordinate.                               "
                "        v_TexCoordinate = a_TexCoordinate;                                 "
                " }                                                                         ";

        glShaderSource(vertex_shader_index, 1, &vertex_shader_source, nullptr);
        glCompileShader(vertex_shader_index);
        glGetShaderiv(vertex_shader_index, GL_COMPILE_STATUS, &compile_ok);

And this is the code of the fragment shader:

        const GLchar * fragment_shader_source =
//                "#version 100\n                                                     "
//                "                                                                   "
                "uniform sampler2D u_Texture;    // The input texture.              "
                "                                                                   "
                "varying vec2 v_TexCoordinate; /* Interpolated texture    */        "
                "                              /* coordinate per fragment */        "
                "                                                                   "
                " void main(){                                                      "
                "                                                                   "
                "     // Output color = color of the texture at the specified UV    "
                "     gl_FragColor = texture2D(u_Texture, v_TexCoordinate);         "
                " }                                                                 ";

        glShaderSource(fragment_shader_index, 1, &fragment_shader_source, nullptr);
        glCompileShader(fragment_shader_index);
        glGetShaderiv(fragment_shader_index, GL_COMPILE_STATUS, &compile_ok);

This is the code of the program:

m_program = glCreateProgram( );
        glAttachShader(m_program, vertex_shader_index);
        glAttachShader(m_program, fragment_shader_index);
        glLinkProgram(m_program);
        glGetProgramiv(m_program, GL_LINK_STATUS, &link_ok);

The variable link_ok is false, while the variables compile_ok are both true. The extended error from the linking of the program says:

(0) Vertex info: C3001 no program defined (0) Fragment info: C3001 no program defined

genpfault
  • 47,669
  • 9
  • 68
  • 119
nyarlathotep108
  • 4,663
  • 1
  • 16
  • 46

1 Answers1

4

Your individual shaders compile just fine. The specific error code you are getting means that no main functions could be found in the complete program. And for good reason - you commented them. Your shader strings do not contain any new lines, so the entire shader is on one line.

For example:

const GLchar * var = "uniform value; // a value"
                     "main () {}               ";

Is actually

const GLchar * var = "uniform value; // a valuemain() {}";

Any commenting done with // comments out the rest of the line - hence the rest of your shader. Removing the // comments, replacing them with /**/ or adding \n at the end of each line and it worked fine for me.

Also, it might be safe to null-terminate your strings with \0.

Reigertje
  • 705
  • 4
  • 15
  • Ok, maybe this could solve! Now the fragment is not compiling due to "unspecified precision on a float variable" line 125, but the shader is shorter than 125 line... can you explain which float is the error referring to? – nyarlathotep108 Dec 15 '15 at 14:29
  • 2
    @nyarlathotep108 If you are using OpenGL ES you have to specify a float precision. Add something like this `precision mediump float;` at the top of your fragment shader. Check this out: http://stackoverflow.com/questions/13780609/what-does-precision-mediump-float-mean – Reigertje Dec 15 '15 at 14:33