我正在尝试使用GLFW和GLEW(可选地是GLM)在OGL中细分一组顶点。我遇到的问题是,我似乎找不到用于将顶点颜色和位置数组传递给GLSL着色器脚本的教程,这样我就可以在屏幕上显示镶嵌。
我可以很好地处理数组缓冲区和索引缓冲区,但是我不知道如何快速将自相交顶点数组细分为正3D或2D结构。谁能提供一些示例代码?谢谢。
void display(void)
{
//glfwMakeContextCurrent(wavebricks_window); glLoadIdentity();
//glTranslatef(1.5f, 0.0f, -7.0f);
for (int it =0; it<instruments.size();it++){
alGetSourcef(instruments[it].soundsource, AL_SEC_OFFSET, &tracking);
instruments[it].currentStep=tracking*(60/tempo);
instruments[it].currentStep=tracking;
instruments[it].tempo=tempo;
instruments[it].render();
float verts[instruments[it].voices_spinner*3];
float colors[instruments[it].voices_spinner*4];
std::string vertexShader;
std::string fragmentShader;
unsigned int indices[instruments[it].voices_spinner*3];
for (int i=0;i<instruments[it].voices_spinner;i++){
indices[i]=i;
}
for (int i=instruments[it].voices_spinner-1;i>=0;i--){
indices[instruments[it].voices_spinner+i]=instruments[it].voices_spinner-1-i;
}
for (int i=instruments[it].voices_spinner-1;i>=0;i--){
indices[instruments[it].voices_spinner*2+i]=i;
}
for(int i=0; i<instruments[it].voices_spinner; i++){
verts[3*i]=instruments[it].instrumentPoly[i][0];
cout<<"\n"<<verts[3*i]<<",";
verts[3*i+1]=instruments[it].instrumentPoly[i][1];
cout<<verts[3*i+1]<<",";
verts[3*i+2]=instruments[it].instrumentPoly[i][2];
cout<<verts[3*i+2]<<":";
colors[4*i]=-instruments[it].instrumentPoly[i][3];
cout<<colors[4*i]<<",";
colors[4*i+1]=-instruments[it].instrumentPoly[i][4];
cout<<colors[4*i+1]<<",";
colors[4*i+2]=-instruments[it].instrumentPoly[i][5];
cout<<colors[4*i+2]<<";\n";
colors[4*i+3]=1.0f;
}
GLint MaxPatchVertices = 0;
glGetIntegerv(GL_MAX_PATCH_VERTICES, &MaxPatchVertices);
printf("Max supported patch vertices %d\n", MaxPatchVertices);
glPatchParameteri(GL_PATCH_VERTICES, instruments[it].voices_spinner);
Renderer renderer;
renderer.Clear();
VertexArray va;
VertexBuffer vb(verts, instruments[it].voices_spinner*3*4);
Shader shader("shade.shader");
VertexBufferLayout layout;
layout.Push<float>(3);
va.AddBuffer(vb, layout);
IndexBuffer ib(indices,instruments[it].voices_spinner * 3*4);
shader.Bind();
va.Bind();
ib.Bind();
shader.SetUniform4f("u_Color",0.8f,0.3f,0.8f,1.0f);
renderer.Draw(va, ib, shader);
float r = 0.0f;
float increment=0.05f;
/*va.Unbind();
vb.Unbind();
ib.Unbind();
shader.Unbind();*/
}
}
我的抽奖电话是:
glDrawElements(GL_PATCHES, ib.getCount(),GL_UNSIGNED_INT, nullptr);
我希望看到合适的形状,但是什么都没有出现。