我正在建立一个用于产生音乐的数字视听工作站。我需要从奇数顶点渲染形状。尽管我认为屏幕上应该没有任何内容,但我还没有找到如何细分相交顶点的方法。我仍然出现黑屏。另外,我的GLUI窗口闪烁,仅在单击时激活。如何使我的数据显示在屏幕上?
我已经尝试了许多不推荐使用的GL函数,现在正在尝试使用现代GL函数。我在屏幕上仍然看不到任何东西。
代码: https://pastebin.com/pAeGynGL
void display(void)
{
//glfwMakeContextCurrent(wavebricks_window);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Set background color to black
and opaque
glLoadIdentity();
//glTranslatef(1.5f, 0.0f, -7.0f);
glClear(GL_COLOR_BUFFER_BIT );
glLoadIdentity();//
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*3];
std::string vertexShader;
std::string fragmentShader;
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[3*i]=-instruments[it].instrumentPoly[i][3];
cout<<colors[3*i]<<",";
colors[3*i+1]=-instruments[it].instrumentPoly[i][4];
cout<<colors[3*i+1]<<",";
colors[3*i+2]=-instruments[it].instrumentPoly[i][5];
cout<<colors[3*i+2]<<";\n";
}
unsigned int buffer;
glGenBuffers(it, &buffer);
glBindBuffer(GL_ARRAY_BUFFER,buffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(verts),verts, GL_DYNAMIC_DRAW);
glDrawArrays(GL_TRIANGLES, 0, instruments[it].voices_spinner);
vertexShader="#version 330 core\n"
"\n"
"layout(location=0) in vec4 position;\n"
"\n"
"void main()"
"{\n"
"gl_Position=position;\n"
"}\n";
fragmentShader="#version 330 core\n"
"\n"
"layout(location=0) out vec4 color;\n"
"\n"
"void main()"
"{\n"
"color =
vec4(colors[i*3],colors[i*3+1],colors[i*3+2],1.0);\n"
"}\n";
glEnableVertexAttribArray(0);
glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,sizeof(float)*3,0);
unsigned int shader= CreateShader(vertexShader, fragmentShader);
glUseProgram(shader);
}
//glFinish();
glutSwapBuffers();
}
int main(int argc, char **argv)
{
cout << " WaveBricks v 1.0\n copyright 2019 Noah
King(wittymoniker.com)\nmain console window. begin init gl:";
glutInit(&argc, argv);
alutInit(&argc, argv);
glfwInit();
// glewInit();
WBInit();
initMainBoard();
//
///////////sldjadajsdjjsdaldjsjddjlwdjljw;
glfwMakeContextCurrent(wavebricks_window);
while(!glfwWindowShouldClose(wavebricks_window)){
glutSetWindow(mainboard_pane);
glutMainLoopEvent();
glfwMakeContextCurrent(wavebricks_window);
glClear(GL_COLOR_BUFFER_BIT);
display();
glfwSwapBuffers(wavebricks_window);
glfwPollEvents();
}
return EXIT_SUCCESS;
}
相关功能是display()
和main()
。
我希望在屏幕上看到形状,但是无论我如何操作顶点,它都是黑色的,没有数据绘制。答案可能是,GLFW窗口的默认摄像机范围是什么?如何确定我的物品在屏幕上是否均匀? 我的顶点看起来像这样: https://gyazo.com/fbe4408693b1b2c72f127912425ad247