0

I'm trying to make a opengl program to display a point on the screen but i'm getting this error while compiling.

cannot convert ‘GLuint {aka unsigned int}’ to ‘GLuint() {aka unsigned int()}’ in assignment
GLuint renderingProgram(); //global variable *Edit, this variable doesn't have any "="

void init(GLFWwindow* window)
{
    renderingProgram = createShaderProgram();
    glGenVertexArrays(numVAOs, vao);
    glBindVertexArray(vao[0]); 
}

This is the only error I'm getting and I don't really know how I could fix this as I'm new to OpenGL :)

Edit

GLuint createShaderProgram()
{
    const char *vshaderSource =
        "#version 330    \n"
        "void main(void) \n"
        "{ gl_Position = vec4(0.0,0.0,0.0,1.0); }";
    const char *fshaderSource =
        "#version 330    \n"
        "out vec4 color; \n"
        "void main(void) \n"
        "{ color = vec4(0.0,0.0,1.0,1.0); }";
    
    GLuint vShader = glCreateShader(GL_VERTEX_SHADER);
    GLuint fShader = glCreateShader(GL_FRAGMENT_SHADER);
    
    glShaderSource(vShader, 1, &vshaderSource, NULL);
    glShaderSource(fShader, 1, &fshaderSource, NULL);
    glCompileShader(vShader);
    glCompileShader(fShader);
    
    GLuint vfProgram = glCreateProgram();
    glAttachShader(vfProgram, vShader);
    glAttachShader(vfProgram, fShader);
    glLinkProgram(vfProgram);
    
    return vfProgram;
}

  • It appears you aren't _naming_ your variable. Perhaps you mean `GLuit myglobal = renderingProgram();` – Tas Jun 29 '20 at 03:50
  • I suspect that you're also new to C++, and that [a good book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) would be very helpful to you. – molbdnilo Jun 29 '20 at 03:51
  • Tried doing it but doesn't seem to be the case as after giving it a name it will just say that renderingProgram (in the same line) is not declared in the scope, for the record, I'm taking this from a book and it appears in the same way – Staling Marin Jun 29 '20 at 03:53
  • Thank you for the book, actually you're right, i'm new to C++ too so the book recommendation comes great. – Staling Marin Jun 29 '20 at 03:54
  • Edited the question and now the variable declaration is the same as I have it, sorry for the confusion... – Staling Marin Jun 29 '20 at 03:58
  • @"*this variable doesn't have any "="*" No, that is not a *variable* at all. `renderingProgram` is a function that returns `GLuint` and takes no parameters. – Nicol Bolas Jun 29 '20 at 04:09
  • `GLuint renderingProgram();` is a function declaration. It tells the compiler there is a symbol called `renderingProgram` that can be used as a function with no arguments, and that function returns the type `GLuint`. If it's a global variable, define it as `GLuint renderingProgram;` Even better, assign it an initial value (_e.g._ zero). If it's defined in a different source file, declare it as `extern` so the linker knows how to find it. – paddy Jun 29 '20 at 04:09
  • Thank you for clarifying Nicol, now moving forward to paddy's comment as nicol said, it's a function, not a variable, my bad, and it is being defined in the same file below the headers, I added some more code for more context to see if there's anything wrong with it or something! as I stated, this is being taken from a book which makes me feel kind of disappointed when transcribing doesn't really work at all – Staling Marin Jun 29 '20 at 04:17

0 Answers0