简体   繁体   English

OpenGL Shader编译代码在哪里?

[英]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. 我怀疑我的opengl头文件中可能缺少代码,或者我的编译无法查询和加载与着色器编译有关的代码。 I am using Simple DirectMedia Layer and I can write and run all shorts of OpenGL code - until I get to shaders. 我正在使用简单DirectMedia层,并且可以编写和运行所有OpenGL代码的简短内容-直到接触着色器为止。 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. 我有OpenGL 4.2版。 The files I include in proceduralTexture.c are: 我包含在proceduralTexture.c中的文件是:

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

And my makefile looks like this: 我的makefile看起来像这样:

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. 在大多数操作系统中,适用于OpenGL的应用程序二进制接口(ABI)仅适用于1.1或1.2版,晚于该版本的版本附带的所有内容都必须在运行时加载。 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. MacOS X是一个例外,其中可用的OpenGL版本直接由OS版本确定,并且OpenGL框架将已经满足该特定版本的所有需求。

The easiest way to get modern OpenGL features is to use an extension loader-wrapper. 获得现代OpenGL功能的最简单方法是使用扩展程序loader-wrapper。 Unfortunately the most popular one (GLEW) still doesn't cover perfectly the core profiles (you have to enable experimental features). 不幸的是,最受欢迎的(GLEW)仍然不能完全涵盖核心配置文件(您必须启用实验功能)。 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. 因此,我建议转到GLEW主页, 首先阅读所有文档,然后下载GLEW 源代码 (不要担心预构建的二进制库版本),将源代码添加到项目中并以静态版本使用它。 Call glewInit() after you created an OpenGL context, and should cover it. 创建OpenGL上下文后,请调用glewInit() ,并将其覆盖。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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