OpenGL基本图形的绘制.docx_第1页
OpenGL基本图形的绘制.docx_第2页
OpenGL基本图形的绘制.docx_第3页
OpenGL基本图形的绘制.docx_第4页
OpenGL基本图形的绘制.docx_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1.使用glColor,glPointSize函数绘制三个不同颜色和大小的点/ T.cpp : Defines the entry point for the console application./#include stdafx.h#include void Display(void) glClear(GL_COLOR_BUFFER_BIT); glPointSize(5.0f); glBegin(GL_POINTS); glColor3f(1.0,0.0,0.0); glVertex2f(0.3f,0.5f); glEnd(); glPointSize(8.0f); glBegin(GL_POINTS); glColor3f(0.0,1.0,0.0); glVertex2f(0.0f,0.0f); glEnd(); glPointSize(10.0f); glBegin(GL_POINTS); glColor3f(0.0,0.0,1.0); glVertex2f(-0.3f,-0.5f); glEnd(); glFlush(); int main(int argc,char* argv) glutInit(&argc,argv); glutInitDisplayMode(GLUT_RGB); glutInitWindowPosition(200,200); glutInitWindowSize(400,400); glutCreateWindow(Three Point); glutDisplayFunc(&Display); glutMainLoop(); return 0; 2.使用glColor,glLineWidth,glLineStripple函数绘制实心、虚线及渐变色线(1)实心线/ T.cpp : Defines the entry point for the console application./#include stdafx.h#include void Display(void) glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0,0.0,0.0); glEnable(GL_LINE_STIPPLE); glShadeModel(GL_SMOOTH); glLineStipple(2,0xFFFF); glLineWidth(2); glBegin(GL_LINES); glVertex2i(-100,0); glVertex2i(100,0); glEnd(); glFlush(); int main(int argc,char* argv) glutInit(&argc,argv); glutInitDisplayMode(GLUT_RGB); glutInitWindowPosition(200,200); glutInitWindowSize(400,400); glutCreateWindow(Solid Line); glutDisplayFunc(&Display); glutMainLoop(); return 0; (2)虚线/ T.cpp : Defines the entry point for the console application./#include stdafx.h#include void Display(void) glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0,0.0,0.0); glEnable(GL_LINE_STIPPLE); glShadeModel(GL_SMOOTH); glLineStipple(4,0xAAAA); glLineWidth(2); glBegin(GL_LINES); glVertex2i(-100,0); glVertex2i(100,0); glEnd(); glFlush(); int main(int argc,char* argv) glutInit(&argc,argv); glutInitDisplayMode(GLUT_RGB); glutInitWindowPosition(200,200); glutInitWindowSize(400,400); glutCreateWindow(Dotted Line); glutDisplayFunc(&Display); glutMainLoop(); return 0; (3)渐变线/ T.cpp : Defines the entry point for the console application./#include stdafx.h #include GLuint Line; void Initial(void) glClearColor(0.0f, 0.0f, 0.0f, 0.0f); Line = glGenLists(1); glNewList(Line, GL_COMPILE); glTranslatef(-50.0, 20.0, 0.0); glColor3f(255.0, 0.0, 0.0); glLineWidth(2); glBegin(GL_LINES);glColor3f(255.0, 0.0, 0.0);glVertex2i(0,-20);glColor3f(0.0, 0.0, 255.0);glVertex2i(100,-20); glEnd(); glEndList(); void ChangeSize(int w, int h) glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D (-70.0f, 70.0f, -70.0f, 70.0f); void Display(void) glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0, 0.0, 0.0); glCallList(Line); glFlush(); int main(int argc, char* argv) glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(600,450); glutInitWindowPosition(100,100); glutCreateWindow(渐变色线); glutDisplayFunc(Display); glutReshapeFunc(ChangeSize); Initial(); glutMainLoop(); return 0; 3.使用glColor,glPolygonMode函数绘制纯色、渐变色、轮廓多边形(1)纯色六边形/ a.cpp : Defines the entry point for the console application./#include stdafx.h#include void init() glClearColor (1.0, 1.0, 1.0, 0.0); glMatrixMode (GL_PROJECTION); gluOrtho2D (0.0, 200.0, 0.0, 150.0);void polygon(void) glClear(GL_COLOR_BUFFER_BIT); int p1 = 20, 75; int p2 = 60, 5; int p3 = 140, 5; int p4 = 180, 75; int p5 = 140, 145; int p6 = 60, 145; glColor3f(0.0, 0.5, 1.0); glBegin(GL_POLYGON); glVertex2iv(p1); glVertex2iv(p2); glVertex2iv(p3); glVertex2iv(p4); glVertex2iv(p5); glVertex2iv(p6); glEnd(); glFlush();void main(int argc, char *argv) glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(400, 300); glutCreateWindow(纯色六边形); init(); glutDisplayFunc(polygon); glutMainLoop();(2)渐变色六边形/ a.cpp : Defines the entry point for the console application./#include stdafx.h#include void init() glClearColor (1.0, 1.0, 1.0, 0.0); glMatrixMode (GL_PROJECTION); gluOrtho2D (0.0, 200.0, 0.0, 150.0);void polygon(void) glClear(GL_COLOR_BUFFER_BIT); int p1 = 20, 75; int p2 = 60, 5; int p3 = 140, 5; int p4 = 180, 75; int p5 = 140, 145; int p6 = 60, 145; glColor3f(0.0, 0.5, 1.0); glBegin(GL_POLYGON); glColor3f(0.0,0.0,1.0); glVertex2iv(p1); glColor3f(0.0,1.0,0.0); glVertex2iv(p2); glColor3f(1.0,0.0,0.0); glVertex2iv(p3); glColor3f(0.0,0.0,1.0); glVertex2iv(p4); glColor3f(0.0,1.0,0.0); glVertex2iv(p5); glColor3f(1.0,0.0,0.0); glVertex2iv(p6); glEnd(); glFlush();void main(int argc, char *argv) glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(400, 300); glutCreateWindow(渐变色六边形); init(); glutDisplayFunc(polygon); glutMainLoop();(3)轮廓渐变色六边形/ a.cpp : Defines the entry point for the console application./#include stdafx.h#include void init() glClearColor (1.0, 1.0, 1.0, 0.0); glPolygonMode (GL_FRONT_AND_BACK,GL_LINE); gluOrtho2D (0.0, 200.0, 0.0, 150.0);void polygon(void) glClear(GL_COLOR_BUFFER_BIT); int p1 = 20, 75; int p2 = 60, 5; int p3 = 140, 5; int p4 = 180, 75; int p5 = 140, 145; int p6 = 60, 145; glColor3f(0.0, 0.5, 1.0); glBegin(GL_POLYGON); glColor3f(0.0,0.0,1.0); glVertex2iv(p1); glColor3f(0.0,1.0,0.0); glVertex2iv(p2); glColor3f(1.0,0.0,0.0); glVertex2iv(p3); glColor3f(0.0,0.0,1.0); glVertex2iv(p4); glColor3f(0.0,1.0,0.0); glVertex2iv(

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论