OpenGL学习笔记(1)-线,三角形

运行效果:

使用xcode 创建一个command line 的工程,添加OpenGL.framework, GLUT.framework

在main.cpp中写入代码

 1 #include <iostream>
 2 #include <OpenGL/glu.h>
 3 #include <OpenGL/OpenGL.h>
 4 #include <GLUT/glut.h>
 5 
 6 void display()
 7 {
 8     glColor3f( 1.0, 0, 0);
 9     glBegin(GL_LINE_LOOP);
10     glVertex2i(0, 0);
11     glColor3f( 0.0, 1.0, 0);
12     glVertex2i(100, 100);
13     glColor3f( 0.0, 0.0, 1.0);
14     glVertex2i(100, 150);
15     glEnd();
16     glFlush();
17 }
18 
19 void init()
20 {
21     glClear(GL_COLOR_BUFFER_BIT);
22 //    glLineWidth(5);
23     glMatrixMode(GL_PROJECTION);
24     gluOrtho2D(0.0, 200, 0.0, 150);
25 }
26 
27 int main(int argc, const char * argv[]) {
28     // insert code here...
29     std::cout << "Hello, World!
";
30     glutInit(&argc, (char**)argv);
31     glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
32     glutInitWindowPosition(50, 100);
33     glutInitWindowSize(400, 300);
34     glutCreateWindow("my Glut windows");
35     
36     init();
37     glutDisplayFunc(display);
38     glutMainLoop();
39     return 0;
40 }
 
GL_LINE_LOOP 画出的线段手尾相接

项目下载地址:http://git.oschina.net/zitonglove/OpenGL-Test/tree/master/test1
原文地址:https://www.cnblogs.com/zitonglove/p/4300837.html