我正在浏览此视频的教程https://www.youtube.com/watch?v=6u1FkksyNCk。在将这个人的代码复制到我的视觉工作室社区2015之后,我没有在屏幕上看到三角形。只有空的黑色窗户。我有版本问题吗?我在他的第二个视频https://www.youtube.com/watch?v=vGptI11wRxE
中配置了视觉效果代码如下:
#include <windows.h>
#include <GL/GL.h>
#include <GLFW/glfw3.h>
int main(void)
{
GLFWwindow *window;
//initialisie the GLFW
if(!glfwInit())
{
return -1;
}
//create a window mode OpenGL Context
window = glfwCreateWindow(640, 480, "OpenGL Project Tutorial", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}
// make window 's context current
float vertices[] =
{
0.0, 0.5, 0.0, // top
-0.5, -0.5, 0.0, // bottom
0.5, -0.5, 0.0 // bottom right
};
//loop unitl the user closes the window
while (!glfwWindowShouldClose(window))
{
glClear(GL_COLOR_BUFFER_BIT);
// Render OpenGL here
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glDrawArrays(GL_TRIANGLES, 0, 3 );
glDisableClientState( GL_VERTEX_ARRAY);
//render the OpenGL here
//sweap front and back buffers
glfwSwapBuffers(window);
//poll for and process events
glfwPollEvents();
}
glfwTerminate();
}
答案 0 :(得分:0)
您的代码缺少
glfwMakeContextCurrent(window);
之后
// make window 's context current
评价。