我正在尝试学习 OpenGL。我尝试了我在这本书中找到的一些代码,但程序的输出只是一个白屏,输出应该是谢尔宾斯基三角形。
有什么问题?我正在 Mac OS X 10.8 和 Xcode 4.5 上开发
#include "Angel.h"
#include <iostream>
const int numPoints = 5000;
typedef vec2 point2;
void init(){
point2 points[numPoints];
point2 vertices[3] = {
point2(-1.0, -1.0), point2(0.0, 1.0), point2(1.0, -1.0)
};
points[0] = point2(0.25, 0.5);
for (int k = 1; k < numPoints; k++) {
int j = rand()%3;
points[k] = (points[k-1]+vertices[j])/2.0;
}
GLuint program = InitShader("vertex.glsl", "fragment.glsl");
glUseProgram(program);
GLuint abuffer;
glGenVertexArraysAPPLE(1, &abuffer);
glBindVertexArrayAPPLE(abuffer);
GLuint buffer;
glGenBuffers(1, &buffer);
glBindBuffer(GL_ARRAY_BUFFER, buffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW);
GLuint location = glGetAttribLocation(program, "vPosition");
glEnableVertexAttribArray(location);
glVertexAttribPointer(location, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
glClearColor(1.0, 1.0, 1.0, 1.0);
}
void display(){
glClear(GL_COLOR_BUFFER_BIT);
glDrawArrays(GL_POINTS, 0, numPoints);
glFlush();
}
int main(int argc, char** argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_3_2_CORE_PROFILE);
glutInitWindowSize(640, 480);
glutCreateWindow("Sierpinski Gasket");
init();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}