Implicit declaration glCreateShader()?

243 Views Asked by At

I am getting warning from gcc. Warning is:

warning: implicit declaration of function ‘glCreateShader’ [-Wimplicit-function-declaration]
  137 |  unsigned int vertex_shader = glCreateShader(GL_VERTEX_SHADER);

I included the headers as follows:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>

#include <GL/freeglut.h>
#include <GL/gl.h>

And I compile the program as follows:

gcc main.c -lglut -lGL -lGLEW -lGLU -lm -o snakeGame

And My main function code is here:

int main(int argc, char **argv){
    srand(time(NULL));

    for (int i=0; i<snake_size; ++i){
        snake[i] = 0;
    }

//glut set
    glutInit(&argc, argv);

    glutInitWindowSize(window_x, window_y);
    glutInitWindowPosition(window_position_x, window_position_y);
    glutInitDisplayMode(display_mode);

    int window = glutCreateWindow("snake game");

    glutDisplayFunc(display_function);
    glutKeyboardFunc(keyboard_function);
    glutIdleFunc(idle_function);

//opengl set

    unsigned int vertex_shader = glCreateShader(GL_VERTEX_SHADER);

    glutMainLoop();

    glutDestroyWindow(window);
    printf("game over\n");

    return 0;
}

Most likely there is a problem with the headers.

BTW I am using linux.

2

There are 2 best solutions below

0
genpfault On BEST ANSWER

Per Khronos only GL 1.1 functions are declared in gl.h. GL 1.2 and above live in glext.h and need to be acquired at run-time.

Though since you're using GLEW you should #include <GL/glew.h> instead, since that will have declarations for all GL functions. Don't forget to initialize GLEW.

0
Erdal Küçük On

Load OpenGL Functions

Loading OpenGL Functions is an important task for initializing OpenGL after creating an OpenGL context. You are strongly advised to use an OpenGL Loading Library instead of a manual process.

OpenGL Loading Library

An OpenGL Loading Library is a library that loads pointers to OpenGL functions at runtime, core as well as extensions. This is required to access functions from OpenGL versions above 1.1 on most platforms.

GLEW

GLenum err = glewInit(); //loads all procs

More on how to use GLEW: https://glew.sourceforge.net/basic.html