码迷,mamicode.com
首页 > 其他好文 > 详细

【openGL】画直线

时间:2016-09-12 20:24:24      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:

 1 #include "stdafx.h"
 2 #include <GL/glut.h>
 3 #include <stdlib.h>
 4 #include <math.h>
 5 #include <stdio.h>
 6 
 7 using namespace std;
 8 
 9 
10 void myDisplay(void){ 
11     glClear(GL_COLOR_BUFFER_BIT);   
12     //glRectf(-0.5f, -0.5f, 0.5f, 0.5f);     
13     
14     glBegin(GL_LINES);     
15     glVertex2f(-0.5f, -0.5f);        //直线起始坐标 
16     glVertex2f(0.5f, 0.5f);         //直线结束坐标
17     glEnd();
18 
19     glBegin(GL_LINES);
20     glVertex2f(-0.5f, 0.5f);
21     glVertex2f(0.5f, -0.5f);
22     glEnd();
23 
24     glBegin(GL_LINES);
25     glVertex2f(-0.5f, 0.5f);
26     glVertex2f(-0.5f, -0.5f);
27     glEnd();
28 
29     glBegin(GL_LINES);
30     glVertex2f(0.5f, 0.5f);
31     glVertex2f(0.5f, -0.5f);
32     glEnd();
33 
34     glBegin(GL_LINES);
35     glVertex2f(-0.5f, 0.5f);
36     glVertex2f(0.5f, 0.5f);
37     glEnd();
38 
39     glBegin(GL_LINES);
40     glVertex2f(-0.5f, -0.5f);
41     glVertex2f(-0.5f, 0.5f);
42     glEnd();
43 
44     glBegin(GL_LINES);
45     glVertex2f(0, 0.5f);
46     glVertex2f(0, -0.5f);
47     glEnd();
48 
49     glBegin(GL_LINES);
50     glVertex2f(-0.5f, -0.5f);
51     glVertex2f(0.5, -0.5f);
52     glEnd();
53 
54     glBegin(GL_LINES);
55     glVertex2f(-0.5f, 0);
56     glVertex2f(0.5, 0);
57     glEnd();
58 
59     glFlush();
60 }
61 int main(int argc, char *argv[]) { 
62     glutInit(&argc, argv);  
63     glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);     
64     glutInitWindowPosition(100, 100);     
65     glutInitWindowSize(500, 500);     
66     glutCreateWindow("第一个 OpenGL 程序");     
67     glutDisplayFunc(&myDisplay);     
68     glutMainLoop();     
69     return 0; 
70 }

运行图像:

技术分享

 

【openGL】画直线

标签:

原文地址:http://www.cnblogs.com/dragonir/p/5865829.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!