-1

Hello i just followed the youtube tutorial example but it didnt work. I think i cannot use another way becuse then the other videos of the tutorial would be different for me. I just paste the shader code here and not the window creation etc. I also removed the lines that would warn me if something went from (there did not come any errors)


const char* vertexSource = "#version 330 core\n"
                           "layout (location = 0) in vec3 position;\n"
                           "out vec3 currentPos;\n"
                           "void main() {\n"
                           "gl_Position = vec4(position.x, position.y, position.z, 1.0f);\n"
                           "currentPos = position;\n"
                           "}\0";

const char* fragmentSource = "#version 330 core\n"
                              "in vec3 currentPos;\n"
                              "out vec4 colour;\n"
                              "void main() {\n"
                              "colour = vec4(currentPos.x + 0.5, currentPos.y + 0.5, currentPos.z + 1.0, 1.0);\n"
                              "}\0";

this are the stings for the shader Here comes the stuff before the while loop


    float vertices[] = {
            -0.5f, -0.5f, 0.0f,
            0.5f, 0.5f, 0.5f,
            0.0f, 0.5f, 0.0f
    };

    unsigned int vaoID;
    glGenVertexArrays(1, &vaoID);
    glBindVertexArray(vaoID);

    unsigned int vboID;
    glGenBuffers(1, &vboID);
    glBindBuffer(GL_ARRAY_BUFFER, vboID);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

    unsigned int vertexshaderID;
    vertexshaderID = glCreateShader(GL_VERTEX_SHADER);
    glShaderSource(vertexshaderID, 1, &vertexSource, null);
    glCompileShader(vertexshaderID);
    int success;

    glGetShaderiv(vertexshaderID, GL_COMPILE_STATUS, &success);

    unsigned int fboID;
    glGenBuffers(1, &fboID);
    glBindBuffer(GL_ARRAY_BUFFER, fboID);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

    unsigned int fragmentshaderID;
    fragmentshaderID = glCreateShader(GL_FRAGMENT_SHADER);
    glShaderSource(fragmentshaderID, 1, &fragmentSource, null);
    glCompileShader(fragmentshaderID);
    glGetShaderiv(vertexshaderID, GL_COMPILE_STATUS, &success);

    unsigned int shaderProg;
    shaderProg = glCreateProgram();

    glAttachShader(shaderProg, vertexshaderID);
    glAttachShader(shaderProg, fragmentshaderID);
    glLinkProgram(shaderProg);

    glGetProgramiv(shaderProg, GL_LINK_STATUS, &success);

    glUseProgram(shaderProg);
    glDeleteShader(vertexshaderID);
    glDeleteShader(fragmentshaderID);

    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*) 0);
    glEnableVertexAttribArray(0);

And in the while loop i call


        glUseProgram(shaderProg);

        glBindVertexArray(vaoID);
        glDrawArrays(GL_TRIANGLES, 0, 3);

I watched the video 2 more times but could not find what is wrong! Here is also die YT vid if you need it for some reason: https://www.youtube.com/watch?v=YMIKl2xvh2E&t=916s

CloudBeta
  • 1
  • 2
  • Can you share a complete code we can compile? See [mcve]. – HolyBlackCat Nov 13 '22 at 11:08
  • 1
    I didn't spot the error, but `vboID` and `fvboID` look like two copies of the same thing. – HolyBlackCat Nov 13 '22 at 11:08
  • You get the shader compilation/link status in `success` but never check it. You might also want to consider a better tutorial site such as [learnopengl.com](https://learnopengl.com/). – G.M. Nov 13 '22 at 11:48

1 Answers1

0

I can recommend this PlayList with lessons on OpenGL, I watched it myself and everything worked out for me. If it still doesn't work out, then write to me and I will try to write code for you and throw off the VisualStudio project.

OpenGl Tutorials here

  • Okay thak you i had trouble with finding a tutorial and thought that would look good. I will watch that tutorial list you linked now – CloudBeta Nov 13 '22 at 13:14