TA的每日心情 | 开心 2019-11-11 10:36 |
---|
签到天数: 2 天 [LV.1]初来乍到
|
GLSL教程
译:FreeSouth
创建一个Shader
下图显示了创建一个shader的步骤:
第一步是创建一个对象,可以看成是shader的容器,返回该容器的指针(句柄)。
OpenGL2.0下使用如下函数:
________________________________________
GLuint glCreateShader(GLenum shaderType);
参数:
shaderType - GL_VERTEX_SHADER or GL_FRAGMENT_SHADER.
________________________________________
ARB扩展使用如下函数:
________________________________________
GLhandleARB glCreateShaderObjectARB(GLenum shaderType);
参数:
shaderType - GL_VERTEX_SHADER_ARB or GL_FRAGMENT_SHADER_ARB.
________________________________________
你可以创建很多的shader添加到程序里面,但是顶点着色器与片元着色器都只可以拥有一个main函数。
The following step is to add some source code. The source code for a shader is a string array, although you can use a pointer to a single string.
下面的步骤开始添加一个shader,参数一个字符串数组。
OpenGL2.0的句式为:
________________________________________
void glShaderSource(GLuint shader, int numOfStrings, const char **strings, int *lenOfStrings);
参数:
shader - the handler to the shader.
numOfStrings - the number of strings in the array.
strings - the array of strings.
lenOfStrings - an array with the length of each string, or NULL, meaning that the strings are NULL terminated.
________________________________________
使用ARB扩展为:
________________________________________
void glShaderSourceARB(GLhandleARB shader, int numOfStrings, const char **strings, int *lenOfStrings);
参数:
shader - the handler to the shader.
numOfStrings - the number of strings in the array.
strings - the array of strings.
lenOfStrings - an array with the length of each string, or NULL, meaning that the strings are NULL terminated.
________________________________________
最终shader需要被编译,OpenGL2.0完成此功能的函数为:
________________________________________
void glCompileShader(GLuint shader);
参数:
shader - the handler to the shader.
________________________________________
使用ARB扩展:
________________________________________
void glCompileShaderARB(GLhandleARB shader);
参数:
shader - the handler to the shader.
原文链接:http://www.lighthouse3d.com/opengl/glsl/index.php?oglshader
OpenGL-创建一个Shader.pdf
(104.38 KB, 下载次数: 650)
|
|