You can get a version from the OpenGL and GL Shading program by:
1 | glGetString(GL_SHADING_LANGUAGE_VERSION) |
If don’t initialize the OpenGL you can get it:
1 | OpenGL (null), GLSL (null) |
Let’s try one simple example.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #include <GL/glut.h> #include // define the size of the window #define window_width 640 #define window_height 480 // Main loop function void main_loop_function() { // Clear color screen // And depth , is used internally to block obstructed objects glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // If don't use the next source code OpenGL will show dizzy content of windows glutSwapBuffers(); } // Initialze OpenGL perspective matrix void GL_Setup(int width, int height) { glViewport( 0, 0, width, height ); glMatrixMode( GL_PROJECTION ); glEnable( GL_DEPTH_TEST ); gluPerspective( 45, (float)width/height, .1, 100 ); glMatrixMode( GL_MODELVIEW ); } // Initialize GLUT and start main loop function int main(int argc, char** argv) { glutInit(&argc, argv); glutInitWindowSize(window_width, window_height); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); glutCreateWindow("www.free-tutorials.org - get? the GLSL version example."); glutIdleFunc(main_loop_function); GL_Setup(window_width, window_height); //next source code will show on shell the OpenGL and GLSL version printf("OpenGL %s, GLSL %s\n", glGetString(GL_VERSION),glGetString(GL_SHADING_LANGUAGE_VERSION)); glutMainLoop(); } |
The output will be print on the shell.
1 | OpenGL 2.1 Mesa 7.3-devel, GLSL 1.10 |