glutDisplayFunc(display);
glutMainLoop();
glut库中的这两行代码无法无限循环,display函数只执行了一次。glutMainLoop()函数,只有改变窗体大小才能触发glutDisplayFunc(display);
我运行程序之后,任意敲击键盘,开启无限循环
#include <stdlib.h>
#include<iostream>
#include<GL/glew.h>
#include<GL/glut.h>
void userInit(); //自定义初始化
void display(void);
GLuint VAO;
GLuint VBO;
unsigned int vertexShader;
unsigned int fragmentShader;
unsigned int shaderProgram;
float vertices[] = {
0.5f, -0.5f, 0.0f, // bottom right
-0.5f, -0.5f, 0.0f, // bottom left
0.0f, 0.5f, 0.0f // top
};
const char* vertexShaderSource = "#version 330 core\n"
"layout (location = 0) in vec3 aPos;\n"
"void main()\n"
"{\n"
" gl_Position = vec4(aPos, 1.0);\n"
"}\0";
const char* fragmentShaderSource = "#version 330 core\n"
"out vec4 FragColor;\n"
"uniform vec4 ourColor;\n"
"void main()\n"
"{\n"
" FragColor = ourColor;\n"
/*here we have the input Color. We just write it out to FragColor. FragColor is our own output variable which GL automatically bind to output 0, therefore we don't need to set it up from our C++ side of the code.*/
"}\n\0";
void keyboard