查看: 4927|回复: 0

GLSL教程(5) OpenGL GLSL程序-创建shader

[复制链接]
  • TA的每日心情
    开心
    2019-11-11 10:36
  • 签到天数: 2 天

    [LV.1]初来乍到

    发表于 2009-6-2 22:30:38 | 显示全部楼层 |阅读模式
    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)
    您需要登录后才可以回帖 登录 | 注册

    本版积分规则

    OSG中国官方论坛-有您OSG在中国才更好

    网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

    联系我们

    • 工作时间:09:00--18:00
    • 反馈邮箱:1315785073@qq.com
    快速回复 返回顶部 返回列表