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.
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.