【OpenGL】实例渲染示例——草地渲染
Git過大無法發正確幀數的原圖
原理:使用glDrawArraysInstancedARB函數進行渲染1024*1024個6個頂點的三角形帶,即glDrawArraysInstancedARB(GL_TRIANGLE_STRIP, 0, 6, 1024 * 1024); ,在進行這一步之前要準備好所有所需的數據,它們都被捆綁到了VAO中,有如下幾個數據:
1、grass_blade 草的頂點數組 總共6個組成一個由4個三角形構成的三角形帶,將其存儲在一個GL_ARRAY_BUFFER綁定點的緩沖區vertexBuffer中。
2、length.tga 長度紋理存儲在?length_texture紋理對象中。 【紋理目標1】
3、orientation.tga 旋轉(方向)紋理 存儲在orientation_texture紋理對象中。?【紋理目標2】
4、grasspalette_data1D漸變紋理數據 存儲在?grasspalette_texture 1D紋理對象中?【紋理目標3】
5、color.tga 顏色紋理 存儲在grasscolor_texture紋理對象中?【紋理目標4】
6、bend.tga 混合值紋理 存儲在bend_texture紋理對象中??【紋理目標5】
上述數據對應到頂點著色器的vVertex、length_texture、orientation_texture、grasspalette_texture、grasscolor_texture、bend_texture。全部都捆綁到了VAO,到時候調用glDrawArraysInstancedARB之前只需指定這個VAO即可,即glBindVertexArray(vao);
Grass.vs
// Perspective correction demonstration // Vertex Shader // Graham Sellers // OpenGL SuperBible #version 150precision highp float;// Incoming per vertex position and texture coordinate in vec4 vVertex;// Output varyings out vec4 color;uniform mat4 mvpMatrix;uniform sampler2D length_texture; uniform sampler2D orientation_texture; uniform sampler1D grasspalette_texture; uniform sampler2D grasscolor_texture; uniform sampler2D bend_texture;int random(int seed, int iterations) {int value = seed;int n;for (n = 0; n < iterations; n++) {value = ((value >> 7) ^ (value << 9)) * 15485863;}return value; }vec4 random_vector(int seed) {int r = random(gl_InstanceID, 4);int g = random(r, 2);int b = random(g, 2);int a = random(b, 2);return vec4(float(r & 0x3FF) / 1024.0,float(g & 0x3FF) / 1024.0,float(b & 0x3FF) / 1024.0,float(a & 0x3FF) / 1024.0); }mat4 construct_rotation_matrix(float angle) {float st = sin(angle);float ct = cos(angle);return mat4(vec4(ct, 0.0, st, 0.0),vec4(0.0, 1.0, 0.0, 0.0),vec4(-st, 0.0, ct, 0.0),vec4(0.0, 0.0, 0.0, 1.0)); }void main(void) {//可能這里看不懂在干嘛,這是用gl_InstanceID實例ID(每個草的ID都不一樣從0開始自增到最大數量-1) 我們用的是2的20次方個數,即有20位,用它的前面10位作為X,后10位作為Y 生成offset。//其中,減去-512.0是將其坐標映射到一個[-512,512]的2D范圍(XY都是這個范圍)vec4 offset = vec4(float(gl_InstanceID >> 10) - 512.0,0.0f,float(gl_InstanceID & 0x3FF) - 512.0,0.0f);//3次迭代根據實例ID求隨機數1int number1 = random(gl_InstanceID, 3);//2次迭代根據實例ID求隨機數2int number2 = random(number1, 2);//隨機數1和隨機數2均取它的后八位并除以1024作為一個擾動值,讓草的位置不那么規整。offset += vec4(float(number1 & 0xFF) / 1024.0,0.0f,float(number2 & 0xFF) / 1024.0,0.0f);// float angle = float(random(number2, 2) & 0x3FF) / 1024.0;//根據擾動后的草位置求出它的紋理坐標,即先將xz映射回[-0.5,0.5]再+0.5映射回[0,1](本例紋理坐標必須是[0,1]才正常)vec2 texcoord = offset.xz / 1024.0 + vec2(0.5);// float bend_factor = float(random(number2, 7) & 0x3FF) / 1024.0;//從混合值貼圖采樣得到R通道即混合值float bend_factor = texture(bend_texture, texcoord).r * 2.0;//求出一個被混合數值,它是頂點坐標Y值的余弦值(這里我也很迷)float bend_amount = cos(vVertex.y);//從旋轉貼圖獲取旋轉角度 并轉成弧度值float angle = texture(orientation_texture, texcoord).r * 2.0 * 3.141592;//根據弧度值生成相應的圍繞Y軸旋轉矩陣rotmat4 rot = construct_rotation_matrix(angle);//對頂點坐標先進行局部位置的Y值偏移,然后進行旋轉變換,最后再加上位置偏移量offsetvec4 position = (rot * (vVertex + vec4(0.0, 0.0, bend_amount * bend_factor, 0.0))) + offset;//對位置Y值進行根據長度貼圖采樣的系數進行縮放(即草的高度縮放)position *= vec4(1.0, texture(length_texture, texcoord).r * 0.9 + 0.3, 1.0, 1.0);//局部轉投影空間gl_Position = mvpMatrix * position; // (rot * position);// color = vec4(random_vector(gl_InstanceID).xyz * vec3(0.1, 0.5, 0.1) + vec3(0.1, 0.4, 0.1), 1.0);// color = texture(orientation_texture, texcoord);//從首先從草地顏色貼圖采樣出R通道,它是作為1D漸變貼圖的采樣紋理坐標數值去采樣1D紋理貼圖獲取到草的顏色,再疊加一個根據實例ID隨機出的隨機向量 + 偏綠顏色值 得到最終顏色輸出給片段著色器進行輸出color = texture(grasspalette_texture, texture(grasscolor_texture, texcoord).r) +vec4(random_vector(gl_InstanceID).xyz * vec3(0.1, 0.5, 0.1), 1.0); }Grass.fs
// Perspective correction demonstration // Fragment Shader // Graham Sellers // OpenGL SuperBible #version 150precision highp float;in vec4 color;out vec4 output_color;void main(void) {vec2 coord;output_color = color; } // grassShader.cpp // OpenGL SuperBible // Demonstrates the effect of the 'noperspective' interpolation qualifier // Program by Graham Sellers #pragma comment(lib, "gltools.lib") #include <GLTools.h> // OpenGL toolkit #include <GLMatrixStack.h> #include <GLFrame.h> #include <GLFrustum.h> #include <GLGeometryTransform.h> #include "StopWatch.h"#include <math.h> #ifdef __APPLE__ #include <glut/glut.h> #else #define FREEGLUT_STATIC #include <GL/glut.h> //#include <GL/freeglut_ext.h> #endif//#include <GL/freeglut_ext.h> #ifdef linux #include <cstdlib> #endifGLFrame viewFrame; GLFrustum viewFrustum; GLMatrixStack modelViewMatrix; GLMatrixStack projectionMatrix; GLGeometryTransform transformPipeline;GLuint grassShader; // The perspective demonstration shader GLint locMVP; // The location of the ModelViewProjection matrix uniformGLuint length_texture; // GLuint orientation_texture; GLuint grasspalette_texture; GLuint grasscolor_texture; GLuint bend_texture;GLuint vao; // The VAO GLuint vertexBuffer; // Geometry VBOconst unsigned char grasspalette_data[] = {0x5E, 0x5F, 0x15, 0x5E, 0x5F, 0x14, 0x5E, 0x5F,0x14, 0x5E, 0x5F, 0x14, 0x5E, 0x5F, 0x14, 0x5E,0x5F, 0x14, 0x5E, 0x5F, 0x14, 0x5E, 0x5F, 0x14,0x5F, 0x5F, 0x14, 0x5F, 0x60, 0x14, 0x5F, 0x60,0x14, 0x5F, 0x60, 0x14, 0x5F, 0x60, 0x14, 0x5F,0x60, 0x13, 0x5F, 0x60, 0x13, 0x5F, 0x60, 0x13,0x60, 0x60, 0x13, 0x60, 0x61, 0x13, 0x60, 0x61,0x13, 0x60, 0x61, 0x13, 0x60, 0x61, 0x13, 0x60,0x61, 0x13, 0x60, 0x61, 0x13, 0x60, 0x61, 0x13,0x61, 0x61, 0x13, 0x61, 0x62, 0x12, 0x61, 0x62,0x12, 0x61, 0x62, 0x12, 0x61, 0x62, 0x12, 0x61,0x62, 0x12, 0x61, 0x62, 0x12, 0x62, 0x62, 0x12,0x62, 0x62, 0x12, 0x62, 0x63, 0x12, 0x62, 0x63,0x12, 0x62, 0x63, 0x12, 0x62, 0x63, 0x12, 0x62,0x63, 0x11, 0x62, 0x63, 0x11, 0x63, 0x63, 0x11,0x63, 0x63, 0x11, 0x63, 0x64, 0x11, 0x63, 0x64,0x11, 0x63, 0x64, 0x11, 0x63, 0x64, 0x11, 0x63,0x64, 0x11, 0x63, 0x64, 0x11, 0x64, 0x64, 0x11,0x64, 0x64, 0x11, 0x64, 0x64, 0x10, 0x64, 0x65,0x10, 0x64, 0x65, 0x10, 0x64, 0x65, 0x10, 0x64,0x65, 0x10, 0x65, 0x65, 0x10, 0x65, 0x65, 0x10,0x65, 0x65, 0x10, 0x65, 0x65, 0x10, 0x65, 0x66,0x10, 0x65, 0x66, 0x10, 0x65, 0x66, 0x10, 0x65,0x66, 0x0F, 0x66, 0x66, 0x0F, 0x66, 0x66, 0x0F,0x66, 0x66, 0x0F, 0x66, 0x66, 0x0F, 0x66, 0x67,0x0F, 0x66, 0x67, 0x0F, 0x66, 0x67, 0x0F, 0x66,0x67, 0x0F, 0x67, 0x67, 0x0F, 0x67, 0x67, 0x0F,0x67, 0x67, 0x0F, 0x67, 0x67, 0x0E, 0x67, 0x68,0x0E, 0x67, 0x68, 0x0E, 0x67, 0x68, 0x0E, 0x67,0x68, 0x0E, 0x68, 0x68, 0x0E, 0x68, 0x68, 0x0E,0x68, 0x68, 0x0E, 0x68, 0x68, 0x0E, 0x68, 0x69,0x0E, 0x68, 0x69, 0x0E, 0x68, 0x69, 0x0E, 0x69,0x69, 0x0D, 0x69, 0x69, 0x0D, 0x69, 0x69, 0x0D,0x69, 0x69, 0x0D, 0x69, 0x69, 0x0D, 0x69, 0x69,0x0D, 0x69, 0x6A, 0x0D, 0x69, 0x6A, 0x0D, 0x6A,0x6A, 0x0D, 0x6A, 0x6A, 0x0D, 0x6A, 0x6A, 0x0D,0x6A, 0x6A, 0x0D, 0x6A, 0x6A, 0x0C, 0x6A, 0x6A,0x0C, 0x6A, 0x6B, 0x0C, 0x6A, 0x6B, 0x0C, 0x6B,0x6B, 0x0C, 0x6B, 0x6B, 0x0C, 0x6B, 0x6B, 0x0C,0x6B, 0x6B, 0x0C, 0x6B, 0x6B, 0x0C, 0x6B, 0x6B,0x0C, 0x6B, 0x6C, 0x0C, 0x6C, 0x6C, 0x0C, 0x6C,0x6C, 0x0B, 0x6C, 0x6C, 0x0B, 0x6C, 0x6C, 0x0B,0x6C, 0x6C, 0x0B, 0x6C, 0x6C, 0x0B, 0x6C, 0x6C,0x0B, 0x6C, 0x6D, 0x0B, 0x6D, 0x6D, 0x0B, 0x6D,0x6D, 0x0B, 0x6D, 0x6D, 0x0B, 0x6D, 0x6D, 0x0B,0x6D, 0x6D, 0x0B, 0x6D, 0x6D, 0x0A, 0x6D, 0x6D,0x0A, 0x6D, 0x6E, 0x0A, 0x6E, 0x6E, 0x0A, 0x6E,0x6E, 0x0A, 0x6E, 0x6E, 0x0A, 0x6E, 0x6E, 0x0A,0x6E, 0x6E, 0x0A, 0x6E, 0x6E, 0x0A, 0x6E, 0x6E,0x0A, 0x6F, 0x6F, 0x0A, 0x6F, 0x6F, 0x0A, 0x6F,0x6F, 0x0A, 0x6F, 0x6F, 0x09, 0x6F, 0x6F, 0x09,0x6F, 0x6F, 0x09, 0x6F, 0x6F, 0x09, 0x6F, 0x6F,0x09, 0x6F, 0x6F, 0x09, 0x6F, 0x6F, 0x09, 0x70,0x70, 0x09, 0x70, 0x70, 0x09, 0x70, 0x70, 0x09,0x70, 0x70, 0x09, 0x70, 0x70, 0x09, 0x70, 0x70,0x09, 0x70, 0x70, 0x09, 0x70, 0x70, 0x08, 0x71,0x71, 0x08, 0x71, 0x71, 0x08, 0x71, 0x71, 0x08,0x71, 0x71, 0x08, 0x71, 0x71, 0x08, 0x71, 0x71,0x08, 0x71, 0x71, 0x08, 0x71, 0x71, 0x08, 0x71,0x71, 0x08, 0x72, 0x72, 0x08, 0x72, 0x72, 0x08,0x72, 0x72, 0x08, 0x72, 0x72, 0x08, 0x72, 0x72,0x07, 0x72, 0x72, 0x07, 0x72, 0x72, 0x07, 0x72,0x72, 0x07, 0x73, 0x73, 0x07, 0x73, 0x73, 0x07,0x73, 0x73, 0x07, 0x73, 0x73, 0x07, 0x73, 0x73,0x07, 0x73, 0x73, 0x07, 0x73, 0x73, 0x07, 0x73,0x73, 0x07, 0x74, 0x74, 0x07, 0x74, 0x74, 0x07,0x74, 0x74, 0x07, 0x74, 0x74, 0x06, 0x74, 0x74,0x06, 0x74, 0x74, 0x06, 0x74, 0x74, 0x06, 0x74,0x74, 0x06, 0x74, 0x74, 0x06, 0x75, 0x75, 0x06,0x75, 0x75, 0x06, 0x75, 0x75, 0x06, 0x75, 0x75,0x06, 0x75, 0x75, 0x06, 0x75, 0x75, 0x06, 0x75,0x75, 0x06, 0x75, 0x75, 0x06, 0x76, 0x76, 0x05,0x76, 0x76, 0x05, 0x76, 0x76, 0x05, 0x76, 0x76,0x05, 0x76, 0x76, 0x05, 0x76, 0x76, 0x05, 0x76,0x76, 0x05, 0x76, 0x76, 0x05, 0x77, 0x77, 0x05,0x77, 0x77, 0x05, 0x77, 0x77, 0x05, 0x77, 0x77,0x05, 0x77, 0x77, 0x05, 0x77, 0x77, 0x05, 0x77,0x77, 0x04, 0x77, 0x77, 0x04, 0x77, 0x77, 0x04,0x78, 0x78, 0x04, 0x78, 0x78, 0x04, 0x78, 0x78,0x04, 0x78, 0x78, 0x04, 0x78, 0x78, 0x04, 0x78,0x78, 0x04, 0x78, 0x78, 0x04, 0x78, 0x78, 0x04,0x79, 0x79, 0x04, 0x79, 0x79, 0x04, 0x79, 0x79,0x04, 0x79, 0x79, 0x04, 0x79, 0x79, 0x03, 0x79,0x79, 0x03, 0x79, 0x79, 0x03, 0x79, 0x79, 0x03,0x79, 0x79, 0x03, 0x7A, 0x7A, 0x03, 0x7A, 0x7A,0x03, 0x7A, 0x7A, 0x03, 0x7A, 0x7A, 0x03, 0x7A,0x7A, 0x03, 0x7A, 0x7A, 0x03, 0x7A, 0x7A, 0x03,0x7A, 0x7A, 0x03, 0x7B, 0x7B, 0x03, 0x7B, 0x7B,0x02, 0x7B, 0x7B, 0x02, 0x7B, 0x7B, 0x02, 0x7B,0x7B, 0x02, 0x7B, 0x7B, 0x02, 0x7B, 0x7B, 0x02,0x7B, 0x7B, 0x02, 0x7C, 0x7C, 0x02, 0x7C, 0x7C,0x02, 0x7C, 0x7C, 0x02, 0x7C, 0x7C, 0x02, 0x7C,0x7C, 0x02, 0x7C, 0x7C, 0x02, 0x7C, 0x7C, 0x02,0x7C, 0x7C, 0x01, 0x7C, 0x7C, 0x01, 0x7D, 0x7D,0x01, 0x7D, 0x7D, 0x01, 0x7D, 0x7D, 0x01, 0x7D,0x7D, 0x01, 0x7D, 0x7D, 0x01, 0x7D, 0x7D, 0x01,0x7D, 0x7D, 0x01, 0x7D, 0x7D, 0x01, 0x7E, 0x7E,0x01, 0x7E, 0x7E, 0x01, 0x7E, 0x7E, 0x01, 0x7E,0x7E, 0x01, 0x7E, 0x7E, 0x01, 0x7E, 0x7E, 0x00,0x7E, 0x7E, 0x00, 0x7E, 0x7E, 0x00, 0x7F, 0x7F,0x00, 0x7F, 0x7F, 0x00, 0x7F, 0x7F, 0x00, 0x7F,0x7F, 0x00, 0x7F, 0x7F, 0x00, 0x7F, 0x7F, 0x00,0x7F, 0x7F, 0x00, 0x7F, 0x7F, 0x00, 0x7F, 0x7F,0x00, 0x80, 0x80, 0x00, 0x7F, 0x80, 0x00, 0x7F,0x80, 0x00, 0x7F, 0x80, 0x00, 0x7E, 0x80, 0x00,0x7E, 0x80, 0x00, 0x7E, 0x80, 0x00, 0x7D, 0x80,0x00, 0x7D, 0x80, 0x00, 0x7D, 0x80, 0x00, 0x7C,0x80, 0x00, 0x7C, 0x80, 0x00, 0x7C, 0x80, 0x00,0x7B, 0x80, 0x00, 0x7B, 0x80, 0x00, 0x7B, 0x80,0x00, 0x7A, 0x80, 0x00, 0x7A, 0x80, 0x00, 0x7A,0x80, 0x00, 0x79, 0x80, 0x00, 0x79, 0x80, 0x00,0x79, 0x80, 0x00, 0x78, 0x80, 0x00, 0x78, 0x80,0x00, 0x78, 0x80, 0x00, 0x77, 0x80, 0x00, 0x77,0x80, 0x00, 0x77, 0x80, 0x00, 0x76, 0x80, 0x00,0x76, 0x80, 0x00, 0x76, 0x80, 0x00, 0x75, 0x80,0x00, 0x75, 0x80, 0x00, 0x75, 0x80, 0x00, 0x74,0x80, 0x00, 0x74, 0x80, 0x00, 0x74, 0x80, 0x00,0x74, 0x80, 0x00, 0x73, 0x80, 0x00, 0x73, 0x80,0x00, 0x73, 0x80, 0x00, 0x72, 0x80, 0x00, 0x72,0x80, 0x00, 0x72, 0x80, 0x00, 0x71, 0x80, 0x00,0x71, 0x80, 0x00, 0x71, 0x80, 0x00, 0x70, 0x80,0x00, 0x70, 0x80, 0x00, 0x70, 0x80, 0x00, 0x6F,0x80, 0x00, 0x6F, 0x80, 0x00, 0x6F, 0x80, 0x00,0x6E, 0x80, 0x00, 0x6E, 0x80, 0x00, 0x6E, 0x80,0x00, 0x6D, 0x80, 0x00, 0x6D, 0x80, 0x00, 0x6D,0x80, 0x00, 0x6C, 0x80, 0x00, 0x6C, 0x80, 0x00,0x6C, 0x80, 0x00, 0x6B, 0x80, 0x00, 0x6B, 0x80,0x00, 0x6B, 0x80, 0x00, 0x6A, 0x80, 0x00, 0x6A,0x80, 0x00, 0x6A, 0x80, 0x00, 0x69, 0x80, 0x00,0x69, 0x80, 0x00, 0x69, 0x80, 0x00, 0x68, 0x80,0x00, 0x68, 0x80, 0x00, 0x68, 0x80, 0x00, 0x67,0x80, 0x00, 0x67, 0x80, 0x00, 0x67, 0x80, 0x00,0x66, 0x80, 0x00, 0x66, 0x80, 0x00, 0x66, 0x80,0x00, 0x65, 0x80, 0x00, 0x65, 0x80, 0x00, 0x65,0x80, 0x00, 0x64, 0x80, 0x00, 0x64, 0x80, 0x00,0x64, 0x80, 0x00, 0x63, 0x80, 0x00, 0x63, 0x80,0x00, 0x63, 0x80, 0x00, 0x62, 0x80, 0x00, 0x62,0x80, 0x00, 0x62, 0x80, 0x00, 0x62, 0x80, 0x00,0x61, 0x80, 0x00, 0x61, 0x80, 0x00, 0x61, 0x80,0x00, 0x60, 0x80, 0x00, 0x60, 0x80, 0x00, 0x60,0x80, 0x00, 0x5F, 0x80, 0x00, 0x5F, 0x80, 0x00,0x5F, 0x80, 0x00, 0x5E, 0x80, 0x00, 0x5E, 0x80,0x00, 0x5E, 0x80, 0x00, 0x5D, 0x80, 0x00, 0x5D,0x80, 0x00, 0x5D, 0x80, 0x00, 0x5C, 0x80, 0x00,0x5C, 0x80, 0x00, 0x5C, 0x80, 0x00, 0x5B, 0x80,0x00, 0x5B, 0x80, 0x00, 0x5B, 0x80, 0x00, 0x5A,0x80, 0x00, 0x5A, 0x80, 0x00, 0x5A, 0x80, 0x00,0x59, 0x80, 0x00, 0x59, 0x80, 0x00, 0x59, 0x80,0x00, 0x58, 0x80, 0x00, 0x58, 0x80, 0x00, 0x58,0x80, 0x00, 0x57, 0x80, 0x00, 0x57, 0x80, 0x00,0x57, 0x80, 0x00, 0x56, 0x80, 0x00, 0x56, 0x80,0x00, 0x56, 0x80, 0x00, 0x55, 0x80, 0x00, 0x55,0x80, 0x00, 0x55, 0x80, 0x00, 0x54, 0x80, 0x00,0x54, 0x80, 0x00, 0x54, 0x80, 0x00, 0x53, 0x80,0x00, 0x53, 0x80, 0x00, 0x53, 0x80, 0x00, 0x52,0x80, 0x00, 0x52, 0x80, 0x00, 0x52, 0x80, 0x00,0x51, 0x80, 0x00, 0x51, 0x80, 0x00, 0x51, 0x80,0x00, 0x51, 0x80, 0x00, 0x50, 0x80, 0x00, 0x50,0x80, 0x00, 0x50, 0x80, 0x00, 0x4F, 0x80, 0x00,0x4F, 0x80, 0x00, 0x4F, 0x80, 0x00, 0x4E, 0x80,0x00, 0x4E, 0x80, 0x00, 0x4E, 0x80, 0x00, 0x4D,0x80, 0x00, 0x4D, 0x80, 0x00, 0x4D, 0x80, 0x00,0x4C, 0x80, 0x00, 0x4C, 0x80, 0x00, 0x4C, 0x80,0x00, 0x4B, 0x80, 0x00, 0x4B, 0x80, 0x00, 0x4B,0x80, 0x00, 0x4A, 0x80, 0x00, 0x4A, 0x80, 0x00,0x4A, 0x80, 0x00, 0x49, 0x80, 0x00, 0x49, 0x80,0x00, 0x49, 0x80, 0x00, 0x48, 0x80, 0x00, 0x48,0x80, 0x00, 0x48, 0x80, 0x00, 0x47, 0x80, 0x00,0x47, 0x80, 0x00, 0x47, 0x80, 0x00, 0x46, 0x80,0x00, 0x46, 0x80, 0x00, 0x46, 0x80, 0x00, 0x45,0x80, 0x00, 0x45, 0x80, 0x00, 0x45, 0x80, 0x00,0x44, 0x80, 0x00, 0x44, 0x80, 0x00, 0x44, 0x80,0x00, 0x43, 0x80, 0x00, 0x43, 0x80, 0x00, 0x43,0x80, 0x00, 0x42, 0x80, 0x00, 0x42, 0x80, 0x00,0x42, 0x80, 0x00, 0x41, 0x80, 0x00, 0x41, 0x80,0x00, 0x41, 0x80, 0x00, 0x40, 0x80, 0x00, 0x40,0x80, 0x00, 0x40, 0x80, 0x00, 0x40, 0x80, 0x00,0x3F, 0x80, 0x00, 0x3F, 0x80, 0x00, 0x3F, 0x80,0x00, 0x3E, 0x80, 0x00, 0x3E, 0x80, 0x00, 0x3E,0x80, 0x00, 0x3D, 0x80, 0x00, 0x3D, 0x80, 0x00,0x3D, 0x80, 0x00, 0x3C, 0x80, 0x00, 0x3C, 0x80,0x00, 0x3C, 0x80, 0x00, 0x3B, 0x80, 0x00, 0x3B,0x80, 0x00, 0x3B, 0x80, 0x00, 0x3A, 0x80, 0x00,0x3A, 0x80, 0x00, 0x3A, 0x80, 0x00, 0x39, 0x80,0x00, 0x39, 0x80, 0x00, 0x39, 0x80, 0x00, 0x38,0x80, 0x00, 0x38, 0x80, 0x00, 0x38, 0x80, 0x00,0x37, 0x80, 0x00, 0x37, 0x80, 0x00, 0x37, 0x80,0x00, 0x36, 0x80, 0x00, 0x36, 0x80, 0x00, 0x36,0x80, 0x00, 0x35, 0x80, 0x00, 0x35, 0x80, 0x00,0x35, 0x80, 0x00, 0x34, 0x80, 0x00, 0x34, 0x80,0x00, 0x34, 0x80, 0x00, 0x33, 0x80, 0x00, 0x33,0x80, 0x00, 0x33, 0x80, 0x00, 0x32, 0x80, 0x00,0x32, 0x80, 0x00, 0x32, 0x80, 0x00, 0x31, 0x80,0x00, 0x31, 0x80, 0x00, 0x31, 0x80, 0x00, 0x30,0x80, 0x00, 0x30, 0x80, 0x00, 0x30, 0x80, 0x00,0x2F, 0x80, 0x00, 0x2F, 0x80, 0x00, 0x2F, 0x80,0x00, 0x2E, 0x80, 0x00, 0x2E, 0x80, 0x00, 0x2E,0x80, 0x00, 0x2D, 0x80, 0x00, 0x2D, 0x80, 0x00,0x2D, 0x80, 0x00, 0x2C, 0x80, 0x00, 0x2C, 0x80,0x00, 0x2C, 0x80, 0x00, 0x2B, 0x80, 0x00, 0x2B,0x80, 0x00, 0x2B, 0x80, 0x00, 0x2A, 0x80, 0x00,0x2A, 0x80, 0x00, 0x2A, 0x80, 0x00, 0x29, 0x80,0x00, 0x29, 0x80, 0x00, 0x29, 0x80, 0x00, 0x28,0x80, 0x00, 0x28, 0x80, 0x00, 0x28, 0x80, 0x00,0x27, 0x80, 0x00, 0x27, 0x80, 0x00, 0x27, 0x80,0x00, 0x26, 0x80, 0x00, 0x26, 0x80, 0x00, 0x26,0x80, 0x00, 0x25, 0x80, 0x00, 0x25, 0x80, 0x00,0x25, 0x80, 0x00, 0x24, 0x80, 0x00, 0x24, 0x80,0x00, 0x24, 0x80, 0x00, 0x24, 0x80, 0x00, 0x23,0x80, 0x00, 0x23, 0x80, 0x00, 0x23, 0x80, 0x00,0x22, 0x80, 0x00, 0x22, 0x80, 0x00, 0x22, 0x80,0x00, 0x21, 0x80, 0x00, 0x21, 0x80, 0x00, 0x21,0x80, 0x00, 0x20, 0x80, 0x00, 0x20, 0x80, 0x00,0x20, 0x80, 0x00, 0x1F, 0x80, 0x00, 0x1F, 0x80,0x00, 0x1F, 0x80, 0x00, 0x1E, 0x80, 0x00, 0x1E,0x80, 0x00, 0x1E, 0x80, 0x00, 0x1D, 0x80, 0x00,0x1D, 0x80, 0x00, 0x1D, 0x80, 0x00, 0x1C, 0x80,0x00, 0x1C, 0x80, 0x00, 0x1C, 0x80, 0x00, 0x1B,0x80, 0x00, 0x1B, 0x80, 0x00, 0x1B, 0x80, 0x00,0x1A, 0x80, 0x00, 0x1A, 0x80, 0x00, 0x1A, 0x80,0x00, 0x19, 0x80, 0x00, 0x19, 0x80, 0x00, 0x19,0x80, 0x00, 0x18, 0x80, 0x00, 0x18, 0x80, 0x00,0x18, 0x80, 0x00, 0x17, 0x80, 0x00, 0x17, 0x80,0x00, 0x17, 0x80, 0x00, 0x16, 0x80, 0x00, 0x16,0x80, 0x00, 0x16, 0x80, 0x00, 0x15, 0x80, 0x00,0x15, 0x80, 0x00, 0x15, 0x80, 0x00, 0x14, 0x80,0x00, 0x14, 0x80, 0x00, 0x14, 0x80, 0x00, 0x13,0x80, 0x00, 0x13, 0x80, 0x00, 0x13, 0x80, 0x00,0x12, 0x80, 0x00, 0x12, 0x80, 0x00, 0x12, 0x80,0x00, 0x11, 0x80, 0x00, 0x11, 0x80, 0x00, 0x11,0x80, 0x00, 0x10, 0x80, 0x00, 0x10, 0x80, 0x00,0x10, 0x80, 0x00, 0x0F, 0x80, 0x00, 0x0F, 0x80,0x00, 0x0F, 0x80, 0x00, 0x0E, 0x80, 0x00, 0x0E,0x80, 0x00, 0x0E, 0x80, 0x00, 0x0D, 0x80, 0x00,0x0D, 0x80, 0x00, 0x0D, 0x80, 0x00, 0x0C, 0x80,0x00, 0x0C, 0x80, 0x00, 0x0C, 0x80, 0x00, 0x0B,0x80, 0x00, 0x0B, 0x80, 0x00, 0x0B, 0x80, 0x00,0x0A, 0x80, 0x00, 0x0A, 0x80, 0x00, 0x0A, 0x80,0x00, 0x09, 0x80, 0x00, 0x09, 0x80, 0x00, 0x09,0x80, 0x00, 0x09, 0x80, 0x00, 0x08, 0x80, 0x00,0x08, 0x80, 0x00, 0x08, 0x80, 0x00, 0x07, 0x80,0x00, 0x07, 0x80, 0x00, 0x07, 0x80, 0x00, 0x06,0x80, 0x00, 0x06, 0x80, 0x00, 0x06, 0x80, 0x00,0x05, 0x80, 0x00, 0x05, 0x80, 0x00, 0x05, 0x80,0x00, 0x04, 0x80, 0x00, 0x04, 0x80, 0x00, 0x04,0x80, 0x00, 0x03, 0x80, 0x00, 0x03, 0x80, 0x00,0x03, 0x80, 0x00, 0x02, 0x80, 0x00, 0x02, 0x80,0x00, 0x02, 0x80, 0x00, 0x01, 0x80, 0x00, 0x01,0x80, 0x00, 0x01, 0x80, 0x00, 0x00, 0x80, 0x00,0x00, 0x80, 0x00, 0x00, 0x80, 0x00, 0x00, 0x80,0x00, 0x00, 0x80, 0x00, 0x00, 0x80, 0x00, 0x00,0x80, 0x00, 0x00, 0x81, 0x00, 0x00, 0x81, 0x00,0x00, 0x81, 0x00, 0x00, 0x81, 0x00, 0x00, 0x81,0x00, 0x00, 0x81, 0x00, 0x00, 0x82, 0x00, 0x00,0x82, 0x00, 0x00, 0x82, 0x00, 0x00, 0x82, 0x00,0x00, 0x82, 0x00, 0x00, 0x83, 0x00, 0x00, 0x83,0x00, 0x00, 0x83, 0x00, 0x00, 0x83, 0x00, 0x00,0x83, 0x00, 0x00, 0x84, 0x00, 0x00, 0x84, 0x00,0x00, 0x84, 0x00, 0x00, 0x84, 0x00, 0x00, 0x84,0x00, 0x00, 0x84, 0x00, 0x00, 0x85, 0x00, 0x00,0x85, 0x00, 0x00, 0x85, 0x00, 0x00, 0x85, 0x00,0x00, 0x85, 0x00, 0x00, 0x86, 0x00, 0x00, 0x86,0x00, 0x00, 0x86, 0x00, 0x00, 0x86, 0x00, 0x00,0x86, 0x00, 0x00, 0x86, 0x00, 0x00, 0x87, 0x00,0x00, 0x87, 0x00, 0x00, 0x87, 0x00, 0x00, 0x87,0x00, 0x00, 0x87, 0x00, 0x00, 0x88, 0x00, 0x00,0x88, 0x00, 0x00, 0x88, 0x00, 0x00, 0x88, 0x00,0x00, 0x88, 0x00, 0x00, 0x88, 0x00, 0x00, 0x89,0x00, 0x00, 0x89, 0x00, 0x00, 0x89, 0x00, 0x00,0x89, 0x00, 0x00, 0x89, 0x00, 0x00, 0x8A, 0x00,0x00, 0x8A, 0x00, 0x00, 0x8A, 0x00, 0x00, 0x8A,0x00, 0x00, 0x8A, 0x00, 0x00, 0x8B, 0x00, 0x00,0x8B, 0x00, 0x00, 0x8B, 0x00, 0x00, 0x8B, 0x00,0x00, 0x8B, 0x00, 0x00, 0x8B, 0x00, 0x00, 0x8C,0x00, 0x00, 0x8C, 0x00, 0x00, 0x8C, 0x00, 0x00,0x8C, 0x00, 0x00, 0x8C, 0x00, 0x00, 0x8D, 0x00,0x00, 0x8D, 0x00, 0x00, 0x8D, 0x00, 0x00, 0x8D,0x00, 0x00, 0x8D, 0x00, 0x00, 0x8D, 0x00, 0x00,0x8E, 0x00, 0x00, 0x8E, 0x00, 0x00, 0x8E, 0x00,0x00, 0x8E, 0x00, 0x00, 0x8E, 0x00, 0x00, 0x8F,0x00, 0x00, 0x8F, 0x00, 0x00, 0x8F, 0x00, 0x00,0x8F, 0x00, 0x00, 0x8F, 0x00, 0x00, 0x90, 0x00,0x00, 0x90, 0x00, 0x00, 0x90, 0x00, 0x00, 0x90,0x00, 0x00, 0x90, 0x00, 0x00, 0x90, 0x00, 0x00,0x91, 0x00, 0x00, 0x91, 0x00, 0x00, 0x91, 0x00,0x00, 0x91, 0x00, 0x00, 0x91, 0x00, 0x00, 0x92,0x00, 0x00, 0x92, 0x00, 0x00, 0x92, 0x00, 0x00,0x92, 0x00, 0x00, 0x92, 0x00, 0x00, 0x92, 0x00,0x00, 0x93, 0x00, 0x00, 0x93, 0x00, 0x00, 0x93,0x00, 0x00, 0x93, 0x00, 0x00, 0x93, 0x00, 0x00,0x94, 0x00, 0x00, 0x94, 0x00, 0x00, 0x94, 0x00,0x00, 0x94, 0x00, 0x00, 0x94, 0x00, 0x00, 0x94,0x00, 0x00, 0x95, 0x00, 0x00, 0x95, 0x00, 0x00,0x95, 0x00, 0x00, 0x95, 0x00, 0x00, 0x95, 0x00,0x00, 0x96, 0x00, 0x00, 0x96, 0x00, 0x00, 0x96,0x00, 0x00, 0x96, 0x00, 0x00, 0x96, 0x00, 0x00,0x97, 0x00, 0x00, 0x97, 0x00, 0x00, 0x97, 0x00,0x00, 0x97, 0x00, 0x00, 0x97, 0x00, 0x00, 0x97,0x00, 0x00, 0x98, 0x00, 0x00, 0x98, 0x00, 0x00,0x98, 0x00, 0x00, 0x98, 0x00, 0x00, 0x98, 0x00,0x00, 0x99, 0x00, 0x00, 0x99, 0x00, 0x00, 0x99,0x00, 0x00, 0x99, 0x00, 0x00, 0x99, 0x00, 0x00,0x99, 0x00, 0x00, 0x9A, 0x00, 0x00, 0x9A, 0x00,0x00, 0x9A, 0x00, 0x00, 0x9A, 0x00, 0x00, 0x9A,0x00, 0x00, 0x9B, 0x00, 0x00, 0x9B, 0x00, 0x00,0x9B, 0x00, 0x00, 0x9B, 0x00, 0x00, 0x9B, 0x00,0x00, 0x9C, 0x00, 0x00, 0x9C, 0x00, 0x00, 0x9C,0x00, 0x00, 0x9C, 0x00, 0x00, 0x9C, 0x00, 0x00,0x9C, 0x00, 0x00, 0x9D, 0x00, 0x00, 0x9D, 0x00,0x00, 0x9D, 0x00, 0x00, 0x9D, 0x00, 0x00, 0x9D,0x00, 0x00, 0x9E, 0x00, 0x00, 0x9E, 0x00, 0x00,0x9E, 0x00, 0x00, 0x9E, 0x00, 0x00, 0x9E, 0x00,0x00, 0x9E, 0x00, 0x00, 0x9F, 0x00, 0x00, 0x9F,0x00, 0x00, 0x9F, 0x00, 0x00, 0x9F, 0x00, 0x00,0x9F, 0x00, 0x00, 0xA0, 0x00, 0x00, 0xA0, 0x00,0x00, 0xA0, 0x00, 0x00, 0xA0, 0x00, 0x00, 0xA0,0x00, 0x00, 0xA0, 0x00, 0x00, 0xA0, 0x00, 0x00,0xA1, 0x00, 0x00, 0xA1, 0x00, 0x00, 0xA1, 0x00,0x00, 0xA1, 0x00, 0x00, 0xA1, 0x00, 0x00, 0xA1,0x00, 0x00, 0xA2, 0x00, 0x00, 0xA2, 0x00, 0x00,0xA2, 0x00, 0x00, 0xA2, 0x00, 0x00, 0xA2, 0x00,0x00, 0xA3, 0x00, 0x00, 0xA3, 0x00, 0x00, 0xA3,0x00, 0x00, 0xA3, 0x00, 0x00, 0xA3, 0x00, 0x00,0xA3, 0x00, 0x00, 0xA4, 0x00, 0x00, 0xA4, 0x00,0x00, 0xA4, 0x00, 0x00, 0xA4, 0x00, 0x00, 0xA4,0x00, 0x00, 0xA4, 0x00, 0x00, 0xA5, 0x00, 0x00,0xA5, 0x00, 0x00, 0xA5, 0x00, 0x00, 0xA5, 0x00,0x00, 0xA5, 0x00, 0x00, 0xA5, 0x00, 0x00, 0xA6,0x00, 0x00, 0xA6, 0x00, 0x00, 0xA6, 0x00, 0x00,0xA6, 0x00, 0x00, 0xA6, 0x00, 0x00, 0xA7, 0x00,0x00, 0xA7, 0x00, 0x00, 0xA7, 0x00, 0x00, 0xA7,0x00, 0x00, 0xA7, 0x00, 0x00, 0xA7, 0x00, 0x00,0xA8, 0x00, 0x00, 0xA8, 0x00, 0x00, 0xA8, 0x00,0x00, 0xA8, 0x00, 0x00, 0xA8, 0x00, 0x00, 0xA8,0x00, 0x00, 0xA9, 0x00, 0x00, 0xA9, 0x00, 0x00,0xA9, 0x00, 0x00, 0xA9, 0x00, 0x00, 0xA9, 0x00,0x00, 0xAA, 0x00, 0x00, 0xAA, 0x00, 0x00, 0xAA,0x00, 0x00, 0xAA, 0x00, 0x00, 0xAA, 0x00, 0x00,0xAA, 0x00, 0x00, 0xAB, 0x00, 0x00, 0xAB, 0x00,0x00, 0xAB, 0x00, 0x00, 0xAB, 0x00, 0x00, 0xAB,0x00, 0x00, 0xAB, 0x00, 0x00, 0xAC, 0x00, 0x00,0xAC, 0x00, 0x00, 0xAC, 0x00, 0x00, 0xAC, 0x00,0x00, 0xAC, 0x00, 0x00, 0xAC, 0x00, 0x00, 0xAD,0x00, 0x00, 0xAD, 0x00, 0x00, 0xAD, 0x00, 0x00,0xAD, 0x00, 0x00, 0xAD, 0x00, 0x00, 0xAE, 0x00,0x00, 0xAE, 0x00, 0x00, 0xAE, 0x00, 0x00, 0xAE,0x00, 0x00, 0xAE, 0x00, 0x00, 0xAE, 0x00, 0x00,0xAF, 0x00, 0x00, 0xAF, 0x00, 0x00, 0xAF, 0x00,0x00, 0xAF, 0x00, 0x00, 0xAF, 0x00, 0x00, 0xAF,0x00, 0x00, 0xB0, 0x00, 0x00, 0xB0, 0x00, 0x00,0xB0, 0x00, 0x00, 0xB0, 0x00, 0x00, 0xB0, 0x00,0x00, 0xB0, 0x00, 0x00, 0xB1, 0x00, 0x00, 0xB1,0x00, 0x00, 0xB1, 0x00, 0x00, 0xB1, 0x00, 0x00,0xB1, 0x00, 0x00, 0xB2, 0x00, 0x00, 0xB2, 0x00,0x00, 0xB2, 0x00, 0x00, 0xB2, 0x00, 0x00, 0xB2,0x00, 0x00, 0xB2, 0x00, 0x00, 0xB3, 0x00, 0x00,0xB3, 0x00, 0x00, 0xB3, 0x00, 0x00, 0xB3, 0x00,0x00, 0xB3, 0x00, 0x00, 0xB3, 0x00, 0x00, 0xB4,0x00, 0x00, 0xB4, 0x00, 0x00, 0xB4, 0x00, 0x00,0xB4, 0x00, 0x00, 0xB4, 0x00, 0x00, 0xB5, 0x00,0x00, 0xB5, 0x00, 0x00, 0xB5, 0x00, 0x00, 0xB5,0x00, 0x00, 0xB5, 0x00, 0x00, 0xB5, 0x00, 0x00,0xB6, 0x00, 0x00, 0xB6, 0x00, 0x00, 0xB6, 0x00,0x00, 0xB6, 0x00, 0x00, 0xB6, 0x00, 0x00, 0xB6,0x00, 0x00, 0xB7, 0x00, 0x00, 0xB7, 0x00, 0x00,0xB7, 0x00, 0x00, 0xB7, 0x00, 0x00, 0xB7, 0x00,0x00, 0xB7, 0x00, 0x00, 0xB8, 0x00, 0x00, 0xB8,0x00, 0x00, 0xB8, 0x00, 0x00, 0xB8, 0x00, 0x00,0xB8, 0x00, 0x00, 0xB9, 0x00, 0x00, 0xB9, 0x00,0x00, 0xB9, 0x00, 0x00, 0xB9, 0x00, 0x00, 0xB9,0x00, 0x00, 0xB9, 0x00, 0x00, 0xBA, 0x00, 0x00,0xBA, 0x00, 0x00, 0xBA, 0x00, 0x00, 0xBA, 0x00,0x00, 0xBA, 0x00, 0x00, 0xBA, 0x00, 0x00, 0xBB,0x00, 0x00, 0xBB, 0x00, 0x00, 0xBB, 0x00, 0x00,0xBB, 0x00, 0x00, 0xBB, 0x00, 0x00, 0xBB, 0x00,0x00, 0xBC, 0x00, 0x00, 0xBC, 0x00, 0x00, 0xBC,0x00, 0x00, 0xBC, 0x00, 0x00, 0xBC, 0x00, 0x00,0xBD, 0x00, 0x00, 0xBD, 0x00, 0x00, 0xBD, 0x00,0x00, 0xBD, 0x00, 0x00, 0xBD, 0x00, 0x00, 0xBD,0x00, 0x00, 0xBE, 0x00, 0x00, 0xBE, 0x00, 0x00,0xBE, 0x00, 0x00, 0xBE, 0x00, 0x00, 0xBE, 0x00,0x00, 0xBE, 0x00, 0x00, 0xBF, 0x00, 0x00, 0xBF,0x00, 0x00, 0xBF, 0x00, 0x00, 0xBF, 0x00, 0x00,0xBF, 0x00, 0x00, 0xC0, 0x00, 0x00, 0xC0, 0x00, };// This function does any needed initialization on the rendering // context. void SetupRC(void) {// BackgroundglClearColor(0.0f, 0.0f, 0.0f, 1.0f);glEnable(GL_DEPTH_TEST);viewFrame.MoveForward(-155.0f);viewFrame.MoveUp(20.0f);grassShader = gltLoadShaderPairWithAttributes("Grass.vs", "Grass.fs",1,GLT_ATTRIBUTE_VERTEX, "vVertex");locMVP = glGetUniformLocation(grassShader, "mvpMatrix");glUseProgram(grassShader);glUniform1i(glGetUniformLocation(grassShader, "length_texture"), 0);glUniform1i(glGetUniformLocation(grassShader, "orientation_texture"), 1);glUniform1i(glGetUniformLocation(grassShader, "grasspalette_texture"), 2);glUniform1i(glGetUniformLocation(grassShader, "grasscolor_texture"), 3);glUniform1i(glGetUniformLocation(grassShader, "bend_texture"), 4);static const GLfloat grass_blade[] ={-0.3f, 0.0f,0.3f, 0.0f,-0.20f, 1.0f,0.1f, 1.3f,-0.05f, 2.3f,0.0f, 3.3f};// Greate a vertex array object and a vertex buffer for the quad// including position and texture coordinatesglGenVertexArrays(1, &vao);glBindVertexArray(vao);glGenBuffers(1, &vertexBuffer);glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);glBufferData(GL_ARRAY_BUFFER, sizeof(grass_blade), grass_blade, GL_STATIC_DRAW);glVertexAttribPointer(GLT_ATTRIBUTE_VERTEX, 2, GL_FLOAT, GL_FALSE, 0, NULL);glEnableVertexAttribArray(GLT_ATTRIBUTE_VERTEX);// glGenTextures(1, &length_texture);glBindTexture(GL_TEXTURE_2D, length_texture);GLint w, h, c;GLenum f;void * bits = gltReadTGABits("length.tga", &w, &h, &c, &f);glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, w, h, 0, GL_BGR, GL_UNSIGNED_BYTE, bits);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);free(bits);glGenTextures(1, &orientation_texture);glActiveTexture(GL_TEXTURE1);glBindTexture(GL_TEXTURE_2D, orientation_texture);bits = gltReadTGABits("orientation.tga", &w, &h, &c, &f);glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, w, h, 0, GL_BGR, GL_UNSIGNED_BYTE, bits);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);free(bits);glGenTextures(1, &grasspalette_texture);glActiveTexture(GL_TEXTURE2);glBindTexture(GL_TEXTURE_1D, grasspalette_texture);glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB8, 1024, 0, GL_RGB, GL_UNSIGNED_BYTE, grasspalette_data);glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);glGenTextures(1, &grasscolor_texture);glActiveTexture(GL_TEXTURE3);glBindTexture(GL_TEXTURE_2D, grasscolor_texture);bits = gltReadTGABits("color.tga", &w, &h, &c, &f);glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, w, h, 0, GL_BGR, GL_UNSIGNED_BYTE, bits);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);free(bits);glGenTextures(1, &bend_texture);glActiveTexture(GL_TEXTURE4);glBindTexture(GL_TEXTURE_2D, bend_texture);bits = gltReadTGABits("bend.tga", &w, &h, &c, &f);glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, w, h, 0, GL_BGR, GL_UNSIGNED_BYTE, bits);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);free(bits); }// Cleanup void ShutdownRC(void) {glDeleteBuffers(1, &vertexBuffer);glDeleteVertexArrays(1, &vao); }// Called to draw scene void RenderScene(void) {static CStopWatch rotTimer;// Clear the window and the depth bufferglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);modelViewMatrix.PushMatrix(viewFrame);modelViewMatrix.Translate(0.0f, 0.0f, 800.0f);modelViewMatrix.Rotate(-12.0, 1.0f, 0.0f, 0.0f);modelViewMatrix.Rotate(rotTimer.GetElapsedSeconds() * 15.0f, 0.0f, 1.0f, 0.0f);glUseProgram(grassShader);glUniformMatrix4fv(locMVP, 1, GL_FALSE, transformPipeline.GetModelViewProjectionMatrix());glBindVertexArray(vao);glDrawArraysInstancedARB(GL_TRIANGLE_STRIP, 0, 6, 1024 * 1024);modelViewMatrix.PopMatrix();glutSwapBuffers();glutPostRedisplay(); }void ChangeSize(int w, int h) {// Prevent a divide by zeroif (h == 0)h = 1;// Set Viewport to window dimensionsglViewport(0, 0, w, h);viewFrustum.SetPerspective(35.0f, float(w) / float(h), 1.0f, 3000.0f);projectionMatrix.LoadMatrix(viewFrustum.GetProjectionMatrix());transformPipeline.SetMatrixStacks(modelViewMatrix, projectionMatrix); }void Keyboard(unsigned char key, int x, int y) {switch (key){// Space toggles perspective correctiondefault:break;}; }/// // Main entry point for GLUT based programs int main(int argc, char* argv[]) {gltSetWorkingDirectory(argv[0]);glutInit(&argc, argv);//glutInitContextVersion(3, 2);// glutInitContextProfile(GLUT_CORE_PROFILE);glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL);glutInitWindowSize(800, 600);glutCreateWindow("Grass");glutReshapeFunc(ChangeSize);glutKeyboardFunc(Keyboard);glutDisplayFunc(RenderScene);GLenum err = glewInit();if (GLEW_OK != err) {fprintf(stderr, "GLEW Error: %s\n", glewGetErrorString(err));return 1;}SetupRC();glutMainLoop();ShutdownRC();return 0; }?
總結
以上是生活随笔為你收集整理的【OpenGL】实例渲染示例——草地渲染的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SpringBoot+SQLSERVER
- 下一篇: M1 Pro MacBook Pro下载