/* Hello World for OpenGL. * Following Cedric Fung's tutorial * * Sadly he seems to have stopped after the first part… * also following * * which gives me segfaults, and so I'm trying * * which doesn't use glDrawArrays but also then my code doesn’t segfault. */ #include #include #include // This #define allows us to get glVertexAttribPointer and the like // without resorting to GLEW. #define GL_GLEXT_PROTOTYPES #include #include #include void draw(int _) { glClearColor(0, 1, 0, 1); // RGBA glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // ??? struct timeval now; gettimeofday(&now, NULL); double theta = now.tv_sec % 6283 + .000001 * now.tv_usec; glLoadIdentity(); // gluLookAt(0, 0, 3, 0, 0, 0, 0, 1, 0); glRotatef(theta*100, 0, 1, 0); glRotatef(theta*61, 0, 0, 1); glBegin(GL_TRIANGLES); glVertex3f(-.5, -.5, 0); glVertex3f(+.5, 0, 0); glVertex3f( 0, +.5, 0); glEnd(); /* GLfloat geometry[] = */ /* { */ /* -.5, +.5, 0, 1, */ /* +.5, -5 , 0, 1, */ /* 0 , +.5, 0, 1, */ /* }; */ /* GLuint buf; */ /* glGenBuffers(1, &buf); */ /* glBindBuffer(GL_ARRAY_BUFFER, buf); */ /* glBufferData(GL_ARRAY_BUFFER, sizeof(geometry), geometry, GL_STATIC_DRAW); */ /* glBindBuffer(GL_ARRAY_BUFFER, 0); */ /* glBindBuffer(GL_ARRAY_BUFFER, buf); */ /* glEnableVertexAttribArray(0); // ??? */ /* // https://www.opengl.org/sdk/docs/man/html/glVertexAttribPointer.xhtml */ /* int index = 0, componentsPerAttribute = 4, strideBytes = 0; */ /* glVertexAttribPointer(index, */ /* componentsPerAttribute, */ /* GL_FLOAT, */ /* GL_FALSE, /\* not normalized ints *\/ */ /* strideBytes, */ /* 0); /\* offset into buffer *\/ */ /* GLenum err = glGetError(); */ /* if (err != GL_NO_ERROR) { */ /* fprintf(stderr, "%d: %s\n", err, gluErrorString(err)); */ /* abort(); */ /* } */ /* glDrawArrays(GL_TRIANGLES, 0, 3); // ??? */ /* glBindBuffer(GL_ARRAY_BUFFER, 0); */ glutSwapBuffers(); glutTimerFunc(22, draw, 0); } int main(int argc, char **argv) { glutInit(&argc, argv); // glutInitDisplayMode(GLUT_DOUBLE | // Double-buffering. GLUT_ALPHA | GLUT_DEPTH | // Depth-buffering. GLUT_STENCIL // “Stencil buffering”, whatever that is. ); glutInitWindowSize(512, 512); glutInitWindowPosition(64, 128); glutCreateWindow(argv[0]); glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Without this gluPerspective call, the gluLookAt call results in // seeing nothing. gluPerspective(45, 1, 0.1, 100); glMatrixMode(GL_MODELVIEW); draw(0); glutMainLoop(); return 0; }