//#include
//#include
//#include
//安全声明:并未掌握,代码可能有错误,自行辨别
int main(void)
{
GLFWwindow* window;
/* Initialize the library */
if (!glfwInit())
return -1;
/* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}
/* Make the window's context current */
glfwMakeContextCurrent(window);
if (glewInit != GLEW_OK)
std::cout << "ERROR!" << std::endl;
std::cout << glGetString(GL_VERSION) << std::endl;
/* Loop until the user closes the window */
float positions[6] = {
-0.5f, -0.5f,
0.0f, 0.5f,
0.5f, -0.5f
};
unsigned int buffer;
glGenBuffers(1, &buffer);//创建缓冲区
glBindBuffer(GL_ARRAY_BUFFER, buffer);//绑定
glBufferData(GL_ARRAY_BUFFER, 6 * sizeof(float),positions,GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, 0);
glBindBuffer(GL_ARRAY_BUFFER,0);
//0索引开始,两个点,数据类型为float,是否想要归一化,false,stride顶点之间的字节数2*4=8使用sizeof进行测量
//由于没有类似纹理坐标的额外属性,直接填0(偏移量),如果有,计算,并填写eg.加上0.5f,0.5f,2*4=8,填(const void*)8;
while (!glfwWindowShouldClose(window))
{
/* Render here */
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glVertex2f(-0.5f, -0.5f);
glVertex2f( 0.0f, 0.5f);
glVertex2f( 0.5f, -0.5f);
glEnd();
/* Swap front and back buffers */
glfwSwapBuffers(window);
/* Poll for and process events */
glfwPollEvents();
}
glfwTerminate();
return 0;
}
头文件显示异常,所以注释