main(){

    1. // build and compile our shader program
    2. // ------------------------------------
    3. // vertex shader
    4. unsigned int vertexShader = glCreateShader(GL_VERTEX_SHADER);
    5. glShaderSource(vertexShader, 1, &vertexShaderSource, NULL);
    6. glCompileShader(vertexShader);
    7. // check for shader compile errors
    8. int success;
    9. char infoLog[512];
    10. glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &success);
    11. if (!success)
    12. {
    13. glGetShaderInfoLog(vertexShader, 512, NULL, infoLog);
    14. std::cout << "ERROR::SHADER::VERTEX::COMPILATION_FAILED\n" << infoLog << std::endl;
    15. }
    16. // fragment shader
    17. unsigned int fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
    18. glShaderSource(fragmentShader, 1, &fragmentShaderSource, NULL);
    19. glCompileShader(fragmentShader);
    20. // check for shader compile errors
    21. glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &success);
    22. if (!success)
    23. {
    24. glGetShaderInfoLog(fragmentShader, 512, NULL, infoLog);
    25. std::cout << "ERROR::SHADER::FRAGMENT::COMPILATION_FAILED\n" << infoLog << std::endl;
    26. }
    27. // link shaders
    28. unsigned int shaderProgram = glCreateProgram();
    29. glAttachShader(shaderProgram, vertexShader);
    30. glAttachShader(shaderProgram, fragmentShader);
    31. glLinkProgram(shaderProgram);
    32. // check for linking errors
    33. glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success);
    34. if (!success) {
    35. glGetProgramInfoLog(shaderProgram, 512, NULL, infoLog);
    36. std::cout << "ERROR::SHADER::PROGRAM::LINKING_FAILED\n" << infoLog << std::endl;
    37. }
    38. glDeleteShader(vertexShader);
    39. glDeleteShader(fragmentShader);

    while (!glfwWindowShouldClose(window)){

    1. glUseProgram(shaderProgram);