GLSL 的创建

    GLuint brickVS, brickFS, brickProg;   // handles to objects
    GLint  vertCompiled, fragCompiled;    // status values
    GLint  linked;

    // Create a vertex shader object and a fragment shader object

    brickVS = glCreateShader(GL_VERTEX_SHADER);
    brickFS = glCreateShader(GL_FRAGMENT_SHADER);

    // Load source code strings into shaders

    glShaderSource(brickVS, 1, &brickVertex, NULL);
    glShaderSource(brickFS, 1, &brickFragment, NULL);

    // Compile the brick vertex shader, and print out
    // the compiler log file.

    glCompileShader(brickVS);
    printOpenGLError();  // Check for OpenGL errors
    glGetShaderiv(brickVS, GL_COMPILE_STATUS, &vertCompiled);
    printShaderInfoLog(brickVS);

    // Compile the brick vertex shader, and print out
    // the compiler log file.

    glCompileShader(brickFS);
    printOpenGLError();  // Check for OpenGL errors
    glGetShaderiv(brickFS, GL_COMPILE_STATUS, &fragCompiled);
    printShaderInfoLog(brickFS);

    if (!vertCompiled || !fragCompiled)
        return 0;

    // Create a program object and attach the two compiled shaders

    brickProg = glCreateProgram();
    glAttachShader(brickProg, brickVS);
    glAttachShader(brickProg, brickFS);

    // Link the program object and print out the info log

    glLinkProgram(brickProg);
    printOpenGLError();  // Check for OpenGL errors
    glGetProgramiv(brickProg, GL_LINK_STATUS, &linked);
    printProgramInfoLog(brickProg);

    if (!linked)
        return 0;

    // Install program object as part of current state

    glUseProgram(brickProg);

    // Set up initial uniform values

    glUniform3f(getUniLoc(brickProg, "BrickColor"), 1.0, 0.3, 0.2);
    glUniform3f(getUniLoc(brickProg, "MortarColor"), 0.85, 0.86, 0.84);
    glUniform2f(getUniLoc(brickProg, "BrickSize"), 0.30, 0.15);
    glUniform2f(getUniLoc(brickProg, "BrickPct"), 0.90, 0.85);
    glUniform3f(getUniLoc(brickProg, "LightPosition"), 0.0, 0.0, 4.0);

    return 1;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值