TA的每日心情 | 开心 2019-11-11 10:36 |
---|
签到天数: 2 天 [LV.1]初来乍到
|
GLSL教程
译:FreeSouth
创建应用程序
下面的源码体现了上节所讲的创建shader的所有步骤。p,f,v是GLuint类型的全局变量(OpenGL2.0)或者GLhandleARB(ARB扩展)
OpenGL 2.0 :
________________________________________
void setShaders() {
char *vs,*fs;
v = glCreateShader(GL_VERTEX_SHADER);
f = glCreateShader(GL_FRAGMENT_SHADER);
vs = textFileRead("toon.vert");
fs = textFileRead("toon.frag");
const char * vv = vs;
const char * ff = fs;
glShaderSource(v, 1, &vv,NULL);
glShaderSource(f, 1, &ff,NULL);
free(vs);free(fs);
glCompileShader(v);
glCompileShader(f);
p = glCreateProgram();
glAttachShader(p,v);
glAttachShader(p,f);
glLinkProgram(p);
glUseProgram(p);
}
________________________________________
ARB 扩展:
________________________________________
void setShaders() {
char *vs,*fs;
v = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
f = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
vs = textFileRead("toon.vert");
fs = textFileRead("toon.frag");
const char * vv = vs;
const char * ff = fs;
glShaderSourceARB(v, 1, &vv,NULL);
glShaderSourceARB(f, 1, &ff,NULL);
free(vs);free(fs);
glCompileShaderARB(v);
glCompileShaderARB(f);
p = glCreateProgramObjectARB();
glAttachObjectARB(p,v);
glAttachObjectARB(p,f);
glLinkProgramARB(p);
glUseProgramObjectARB(p);
}
________________________________________
原文地址:http://www.lighthouse3d.com/opengl/glsl/index.php?oglexample1
OpenGL-创建一个Shader.pdf
(104.38 KB, 下载次数: 611)
|
|