简体   繁体   中英

Where is OpenGL Shader Compilation code located?

I suspect I may be missing code in my opengl header files or my compilation is failing to query and load the code related to shader compilation. I am using Simple DirectMedia Layer and I can write and run all shorts of OpenGL code - until I get to shaders. I have a friend who is having the same issue. When I get to shaders I am getting a lot of undeclared statements:

$ make
cc    -c -o proceduralTexture.o proceduralTexture.c
proceduralTexture.c: In function 'PrintShaderLog':
proceduralTexture.c:60:22: error: 'GL_INFO_LOG_LENGTH' undeclared (first use in
this function)
    glGetShaderiv(obj,GL_INFO_LOG_LENGTH,&len);
                      ^
proceduralTexture.c:60:22: note: each undeclared identifier is reported only onc
e for each function it appears in
proceduralTexture.c:70:22: error: 'GL_COMPILE_STATUS' undeclared (first use in t
his function)
    glGetShaderiv(obj,GL_COMPILE_STATUS,&len);
                      ^
proceduralTexture.c: In function 'PrintProgramLog':
proceduralTexture.c:76:23: error: 'GL_INFO_LOG_LENGTH' undeclared (first use in
this function)
    glGetProgramiv(obj,GL_INFO_LOG_LENGTH,&len);
                       ^
proceduralTexture.c:85:23: error: 'GL_LINK_STATUS' undeclared (first use in this
 function)
    glGetProgramiv(obj,GL_LINK_STATUS,&len);
                       ^
proceduralTexture.c: In function 'SDL_main':
proceduralTexture.c:430:34: error: 'GL_FRAGMENT_SHADER' undeclared (first use in
 this function)
     _procShader = glCreateShader(GL_FRAGMENT_SHADER);
                                  ^
proceduralTexture.c:438:34: error: 'GL_VERTEX_SHADER' undeclared (first use in t
his function)
     _vertShader = glCreateShader(GL_VERTEX_SHADER);
                                  ^
make: *** [proceduralTexture.o] Error 1

I have OpenGL version 4.2. The files I include in proceduralTexture.c are:

#include <stdio.h>
#include <math.h>
#include "SDL/SDL.h"
#include <GL/gl.h>
#include <GL/glu.h>

And my makefile looks like this:

proceduralTexture: proceduralTexture.o
#   Windows
    gcc -Wall -O3 -o $@ $^ -lopengl32 -lmingw32 -lSDLmain -lSDL -lSDL_mixer -lz

What am I missing?

What am I missing?

That in most Operating Systems the Application Binary Interface (ABI) for OpenGL goes only to version 1.1 or 1.2 and that everything that comes with versions later than that must be loaded at runtime. This is called the extension mechanism .

The exception is MacOS X where the available OpenGL version is directly determined by the OS version and the OpenGL framework will already cover every needs for that particular version.

The easiest way to get modern OpenGL features is to use an extension loader-wrapper. Unfortunately the most popular one (GLEW) still doesn't cover perfectly the core profiles (you have to enable experimental features). For getting shaders to work it's good enough, though.

So I suggest over to The GLEW homepage first read all the documentation then download the GLEW sources (don't bother with a pre-built binary library version) add the sources to your project and use it a static build. Call glewInit() after you created an OpenGL context, and should cover it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM