lundi 27 avril 2020

Fragment shader cannot be compiled[GLEW]

I am trying to to build a simple application that will display a triangle to the screen but the fragment shader cannot be compiled. I believe this is due to the fact that the fragment shader gets an error reading the string of characters while the vertex shader works alright. I might be wrong, any help will be appreciated.

const GLchar *vertexShaderSrc =
      "attribute vec3 in_Position;          "\
      "void main()                          "\
      "{                                    "\
      "gl_position = vec4(in_Position, 1.0);"\
      "}                                    ";

      //create a new vertex shader, attach source code, compile it and check for errors.

  GLuint vertexShaderId = glCreateShader(GL_VERTEX_SHADER);
  glShaderSource(vertexShaderId, 1, &vertexShaderSrc, NULL);
  glCompileShader(vertexShaderId);
  GLint success = 0;
  glGetShaderiv(vertexShaderId, GL_COMPILE_STATUS, &success); // will return true if compiled, making success 1 instead of 0.

  if (!success)
  {
      throw std::exception();
  }

  ///Fragment Shader ///
  const GLchar *fragmentShaderSrc =
      "void main()                          "\
      "{                                    "\
      " gl_FragColor = vec4(0,0,1,1)        "\
      "}                                    ";


  //create a new fragment shader, attach source code, compile and check for errors.

  GLuint fragmentShaderId = glCreateShader(GL_FRAGMENT_SHADER);
  glShaderSource(fragmentShaderId, 1, &fragmentShaderSrc, NULL);
  glCompileShader(fragmentShaderId);
  glGetShaderiv(fragmentShaderId, GL_COMPILE_STATUS, &success);
  if (!success)
  {
      throw std::exception();
  }

Aucun commentaire:

Enregistrer un commentaire