"shader compilation" An empty window appears, and an error in the console!

  • IlyaDudar
    Likes 0

    Problem Description

    ERROR::SHADER::COMPILATION_FAILEDERROR: 0:5: Use of undeclared identifier 'pozition'

    ERROR::PROGRAM::LINKING_FAILEDERROR: One or more attached shaders not successfully compiled

    did everything exactly like a video tutorial

    my code:

    #include <iostream>

    #define GLEW_STATIC

    #include <GL/glew.h>

    #include <GLFW/glfw3.h>

     

    using namespace std;

     

    const GLint WIDTH = 800, HEIGTH = 600;

     

    const GLchar *vertexShaderSource = "#version 330 core\n"

    "layout (location = 0) in vec3 position;\n"

    "void main()\n"

    "{\n"

    "gl_Position = vec4(position.x, position.y, pozition.z, 1.0);\n"

    "}";

     

    const GLchar *fragmentShaderSource = "#version 330 core\n"

    "out vec4 color;\n"

    "void main () \n"

    "{\n"

    "color = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n"

    "}";

     

    int main () {

        glfwInit();

        

        glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);

        glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);

        glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

        glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);

        glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);

        

        GLFWwindow *window = glfwCreateWindow (WIDTH, HEIGTH, "Learn OpenGL", nullptr, nullptr);

        

        int screenWidth, screenHeight;

        glfwGetFramebufferSize (window, &screenWidth, &screenHeight);

        

        if (nullptr == window) {

            cout<<"Failed to create GLFW window"<<endl;

            glfwTerminate ();

            

            return EXIT_FAILURE;

        }

        

        glfwMakeContextCurrent(window);

        glewExperimental = GL_TRUE;

        

        if (GLEW_OK != glewInit()) {

            cout<<"Failed to initialize GLEW"<<endl;

            return EXIT_FAILURE;

        }

        

        glViewport (0, 0, screenWidth, screenHeight);

        

        GLuint vertexShader = glCreateShader (GL_VERTEX_SHADER);

        glShaderSource (vertexShader, 1, &vertexShaderSource, NULL );

        glCompileShader (vertexShader);

        

        GLint success;

        GLchar infoLog[512];

        

        glGetShaderiv (vertexShader, GL_COMPILE_STATUS, &success);

        if (!success) {

            glGetShaderInfoLog (vertexShader, 512, NULL, infoLog);

            cout<<"ERROR::SHADER::COMPILATION_FAILED"<<infoLog<<endl;

        }

        

        GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);

        glShaderSource (fragmentShader, 1, &fragmentShaderSource, NULL);

        glCompileShader (fragmentShader);

        

        glGetShaderiv (fragmentShader, GL_COMPILE_STATUS, &success);

        

        if (!success) {

            glGetShaderInfoLog (fragmentShader, 512, NULL, infoLog);

            cout<<"ERROR::FRAGMENT::COMPILATION_FAILED"<<infoLog<<endl;

        }

        

        GLuint shaderProgram = glCreateProgram ();

        glAttachShader (shaderProgram, vertexShader);

        glAttachShader (shaderProgram, fragmentShader);

        glLinkProgram (shaderProgram);

        

        glGetProgramiv (shaderProgram, GL_LINK_STATUS, &success);

        

        if (!success) {

            glGetProgramInfoLog (shaderProgram, 512, NULL, infoLog);

            cout<<"ERROR::PROGRAM::LINKING_FAILED"<<infoLog<<endl;

        }

        

        glDeleteShader (vertexShader);

        glDeleteShader (fragmentShader);

        

        GLfloat vertices [] {

            -0.5f, -0.5f, 0.0f,

            0.5f, -0.5f, 0.0f,

            0.0f, 0.5f, 0.0f

        };

        

        GLuint VBO, VAO;

        glGenVertexArrays (1, &VAO);

        glGenBuffers (1, &VBO);

        

        glBindVertexArray (VAO);

        glBindBuffer(GL_ARRAY_BUFFER, VBO);

        glBufferData (GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

        

        glVertexAttribPointer (0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof (GLfloat), (GLvoid *) 0);

        glEnableVertexAttribArray (0);

        

        glBindBuffer (GL_ARRAY_BUFFER, 0);

        

        glBindVertexArray (0);

        

        while (!glfwWindowShouldClose(window)) {

            glfwPollEvents();

            

            

            glClear (GL_COLOR_BUFFER_BIT);

            

            glUseProgram ( shaderProgram );

            glBindVertexArray ( VAO );

            glDrawArrays(GL_TRIANGLES, 0, 3);

            glBindVertexArray (0);

            

            glfwSwapBuffers (window);

        }

        

        glDeleteVertexArrays (1, &VAO);

        glDeleteBuffers (1, &VBO);

        

        glfwTerminate ();

        

        return EXIT_SUCCESS;

    }

  • Sonar Systems admin
    Likes 0

    What OS are you using?

  • IlyaDudar
    Likes 0

    MacOS Mojave

  • IlyaDudar
    Likes 0


  • Sonar Systems admin
    Likes 0

    Did you link the resources folder to copy?

  • IlyaDudar
    Likes 0

    You mean this?

  • IlyaDudar
    Likes 0

  • IlyaDudar
    Likes 0

    If that's not what you mean, then I don't know... I did everything exactly as in the video

  • Sonar Systems admin
    Likes 0

    I cant see anything?

  • IlyaDudar
    Likes 0

     well I cut out a piece of screen, and then pasted in chat ctrl + v. After refreshing the page, there really is no image.…

    on the screenshot I wanted to show that to the header search paths I specified /usr/local/include. and connected all the required libraries

    all as you explained in the video tutorial


  • Sonar Systems admin
    Likes 0

    Try uploading the image to another website

  • IlyaDudar
    Likes 0

    did I do everything right? or missed something? as I understand it that would be enough to compile the shaders

  • Sonar Systems admin
    Likes 0

    Did you copy the shader files over to the executable directory?

  • IlyaDudar
    Likes 0

    where are the Shader files?
    do I understand correctly that after writing this code, a shader file should appear?
     


    /Users/ilya/Library/Developer/Xcode/DerivedData/collectAndKill-codlznmoddbxvffzuaytdcewzesb/Build/Products/Debug/collectAndKill
    there is no Shader file!
    screenshot:
    https://wampi.ru/image/6QJW9MP

  • IlyaDudar
    Likes 0

    https://wampi.ru/image/6QJW9MP

  • Sonar Systems admin
    Likes 0

    Which tutorials are you creating?

  • IlyaDudar
    Likes 0

    https://www.youtube.com/watch?v=EIpxcNl2WJU&t=515s
    OpenGL 3.0+ [GETTING STARTED] Tutorial 1
    The triangle is not displayed! only a blank window
    "I don't know English well, I apologize in advance!"

  • Sonar Systems admin
    Likes 0

    Which setup video did you use?

  • IlyaDudar
    Likes 0

    https://www.youtube.com/watch?v=Tz0dq2krCW8&t=158s

  • IlyaDudar
    Likes 0

    established I as in this video

  • IlyaDudar
    Likes 0

    the following video shows how to draw a triangle

  • IlyaDudar
    Likes 0

    I would like to offer to send the project by emal

  • IlyaDudar
    Likes 0

    In this case you can test it yourself and check if I need to fix something.

  • IlyaDudar
    Likes 0

    If everything works on your machine, this means that the problem is somewhere else.

  • Sonar Systems admin
    Likes 0

    Have you tried the code from the GitHub page?

  • IlyaDudar
    Likes 0

    the problem is solved! the error was in the code, I fixed it!

  • Sonar Systems admin
    Likes 0

    :D         

Login to reply