zoukankan      html  css  js  c++  java
  • Shaders_练习二

    使用uniform定义一个水平偏移量,在顶点着色器中使用这个偏移量把三角形移动到屏幕右侧

     1 // In your CPP file:
     2 // ======================
     3 float offset = 0.5f;
     4 ourShader.setFloat("xOffset", offset);
     5 
     6 // In your vertex shader:
     7 // ======================
     8 #version 330 core
     9 layout (location = 0) in vec3 aPos;
    10 layout (location = 1) in vec3 aColor;
    11 
    12 out vec3 ourColor;
    13 
    14 uniform float xOffset;
    15 
    16 void main()
    17 {
    18     gl_Position = vec4(aPos.x + xOffset, aPos.y, aPos.z, 1.0); // add the xOffset to the x position of the vertex position
    19     ourColor = aColor;
    20 }
    View Code

    注意:查询uniform地址不要求你之前使用过着色器程序,但是更新一个uniform之前你必须先使用程序(调用glUseProgram),因为它是在当前激活的着色器程序中设置uniform的。

    2019/11/27

  • 相关阅读:
    C# Dev PropertyGrid
    C# PropertyGrid控件应用心得
    FileWriter不覆盖
    FileWriter
    java试题
    Java线程池
    java自带线程池和队列详细讲解
    HashMap练习题
    Map集合
    java指定
  • 原文地址:https://www.cnblogs.com/ljy08163268/p/11943491.html
Copyright © 2011-2022 走看看