Search code examples
copengllinkerundeclared-identifier

OpenGl error linking


hi guys recently 'm learning the basics of opengl.. so understanded them i tried to write my first program. At the beginning i tried with the functions that allow you to create buffers for the drawing call. but the linker tell to me that these function are undeclared. so i tried with the old one ( i think maybe i'm wrong) and it works. so my code is the following

    #include <GL/glut.h>
    #include <GL/glext.h>

    #include <GL/gl.h>
    #include <stdlib.h>
    #include <stdio.h>


    void reshape(int, int);
    void display(void);
    void keyboard(unsigned char, int, int);


    int main(int argc, char** argv)
    {
        glutInit(&argc, argv);
        glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
        glutInitWindowSize(500,500);
        glutInitWindowPosition (100, 100);
        glutCreateWindow(argv[0]);
        glClearColor(0.0,0.0,0.0,0.0);
        glShadeModel(GL_FLAT);
        glutDisplayFunc(display);
        glutReshapeFunc(reshape);
        glutKeyboardFunc(keyboard);
        glutMainLoop();
        return 0;
    }

    void reshape(int w, int h)
    {
    glViewport(0,0,(GLsizei) w, (GLsizei) h);

    }

    void display(void)
    {
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        GLuint* i;
        glGenBuffers(1,i);

        glClear(GL_COLOR_BUFFER_BIT);

         glBegin(GL_TRIANGLES);
                glColor3f(1.0f,1.00f,1.0f);         
                glVertex3f(0.5f, 0.0f, 0.0f);       
                glVertex3f(-0.5f,0.5f, 0.0f);       
                glVertex3f( 0.0f,-0.5f, 0.0f);      
            glEnd();
        glBegin(GL_TRIANGLES);
                glColor3f(1.0f,1.00f,1.0f);         
                glVertex3f(-0.5f, 0.0f, 0.0f);      
                glVertex3f(0.5f,0.5f, 0.0f);        
                glVertex3f(0.0f,-0.5f, 0.0f);       
            glEnd();
            //glutWireCube(10);
            glFlush();

    }

    void keyboard(unsigned char key, int x, int y)
    {
    switch(key) {
    case 'l':

    break;
    }
    } 

the problem born with the glGenBuffers and all the gl* functions. here there is the gcc's commande used

gcc -o cube main.c -lGL -lGLU -lglut 

and this is the error

main.c: In function ‘display’:
main.c:40:3: warning: implicit declaration of function ‘glGenBuffers’ [-Wimplicit-function-declaration]
   glGenBuffers(1,i);

sorry for my English and thank to all.


Solution

  • You are missing the following line at the beginning of your code

    #define GL_GLEXT_PROTOTYPES
    
    #include <GL/glut.h>
    #include <GL/glext.h>
    
    #include <GL/gl.h>
    #include <stdlib.h>
    #include <stdio.h>
    

    It compiles without any warnings like this on my Ubuntu computer, see glGenBuffers not defined?