再次应用他们相当大的帮助解决一个问题。这是我的代码:
float ctex[] = {0.0,0.0,
0.0,1.0,
1.0,1.0,
1.0,0.0};
float data[] = {1.0, 1.0,-5.0,
-1.0,-1.0,-5.0,
1.0,-1.0,-5.0,
-1.0, 1.0,-5.0};
GLuint ind[] = {0,1,2,0,3,1};
LoadTexture();
glGenBuffers(1,&triangleVBO);
glBindBuffer(GL_ARRAY_BUFFER,triangleVBO);
glBufferData(GL_ARRAY_BUFFER,sizeof(data),data,GL_STATIC_DRAW);
glGenBuffers(1,&triangleIND);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,triangleIND);
glBufferData(GL_ELEMENT_ARRAY_BUFFER,sizeof(ind),ind,GL_STATIC_DRAW);
glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,0,0);
glGenBuffers(1,&triangleT[0]);
glBindBuffer(GL_ARRAY_BUFFER,triangleT[0]);
glBufferData(GL_ARRAY_BUFFER,sizeof(ctex),ctex,GL_STATIC_DRAW);
glVertexAttribPointer(1,2,GL_FLOAT,GL_FALSE,0,0);
GLuint v,f,p;
v = glCreateShader(GL_VERTEX_SHADER);
f = glCreateShader(GL_FRAGMENT_SHADER);
p = glCreateProgram();
char *vsFuente = LeeShader("shaders/shader.vert");
char *fsFuente = LeeShader("shaders/shader.frag");
const char *vs = vsFuente;
const char *fs = fsFuente;
glShaderSource(v,1,&vs,NULL);
glShaderSource(f,1,&fs,NULL);
free(vsFuente);free(fsFuente);
glCompileShader(v);
glCompileShader(f);
glAttachShader(p,v);
glAttachShader(p,f);
glLinkProgram(p);
//main loop
while(1){
...etc.
glUseProgram(p);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER,triangleVBO);
glDrawElements(GL_TRIANGLES,6,GL_UNSIGNED_INT,0);
glDisableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glBindBuffer(GL_ARRAY_BUFFER,triangleTex);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D,idtextere);
glEnable(GL_TEXTURE_2D);
glDisableVertexAttribArray(1);
glUseProgram(0);
...etc.
}
这是我的顶点着色器:
void main(){
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
}
这是我的片段着色器:
统一的sampler2D tex;
void main(){
vec4 color = texture2D(tex,gl_TexCoord[0].st);
gl_FragColor = color;
}
问题是没有出现纹理或其他任何东西。我可以说有什么问题吗?
非常感谢您提前。