图形学opengl绘图入门代码.doc_第1页
图形学opengl绘图入门代码.doc_第2页
图形学opengl绘图入门代码.doc_第3页
图形学opengl绘图入门代码.doc_第4页
图形学opengl绘图入门代码.doc_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

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

文档简介

/ opg1.cpp : Defines the entry point for the console application./#include stdafx.h/*#include void display(void) glClear (GL_COLOR_BUFFER_BIT);/ clear all pixels glColor3f (1.0, 1.0, 1.0); glBegin(GL_POLYGON);/draw white polygon glVertex3f (0.25, 0.25, 0.0); glVertex3f (0.75, 0.25, 0.0); glVertex3f (0.75, 0.75, 0.0); glVertex3f (0.25, 0.75, 0.0); glEnd(); glFlush ();/ start processing buffered OpenGL routines void init (void) glClearColor (0.0, 0.0, 0.0, 0.0);/ select clearing color glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);/ initialize viewing values int main(int argc, char* argv) glutInit(&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize (250, 250); /Declare initial window size. glutInitWindowPosition (100, 100);/Declare initial window position. glutCreateWindow (hello);/Open window with helloin its title bar. init ();/Call initialization routines. glutDisplayFunc(display); /*Register callback function to display graphics. glutMainLoop();/Enter main loop and process events. return 0; / ANSI C requires main to return int. */ GL_2_17.cpp : Defines the entry point for the console application./*#include #include #include #include const int screenWidth=640;const int screenHeight=480;GLdouble A,B,C,D;void myInit(void)glClearColor(1.0,1.0,1.0,0.0);glColor3f(0.0f,0.0f,0.0f);glPointSize(2.0);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluOrtho2D(0.0,screenWidth,0.0,screenHeight);A=screenWidth/4.0;B=0.0;C=D=screenHeight/2.0;void myDisplay(void)glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBegin(GL_POINTS);for(GLdouble x=0;x4.0;x+=0.001)GLdouble func=exp(-x)*cos(2*3.14159265*x);glVertex2d(A*x+B,C*func+D);glEnd();glFlush();void main(int argc, char* argv)glutInit(&argc,argv);glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);glutInitWindowSize(640,480);glutInitWindowPosition(100,150);glutCreateWindow(Dot plot of a function);glutDisplayFunc(myDisplay);myInit();glutMainLoop();*/图形学第三课-opengl绘图入门代码#include #include #include #include #include void myInit(void)glClearColor(0.0,0.0,0.0,0.0);glClear(GL_COLOR_BUFFER_BIT);void myReshape(GLsizei w,GLsizei h)glViewport(0,0,w,h);glMatrixMode(GL_PROJECTION);glLoadIdentity();if(w=h)glOrtho(-1.5,1.5,-1.5*(GLfloat)h/(GLfloat)w, 1.5*(GLfloat)h/(GLfloat)w,-10.0,10.0);elseglOrtho(-1.5*(GLfloat)h/(GLfloat)w, 1.5*(GLfloat)h/(GLfloat)w,-1.5,1.5,-10.0,10.0);glMatrixMode(GL_MODELVIEW); glLoadIdentity();void myDisplay(void)glColor3f(1.0,1.0,0.0);/auxWireSphere(1.0);auxSolidTeapot(1.0);glFlush();void main(int argc, char* argv)glutInit(&argc,argv);glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);glutInitWindowSize(640,480);glutInitWindowPosition(100,150);glutCreateWindow(AUX_SAMPLE);myInit();glutReshapeFunc(myReshape); glutDisplayFunc(myDisplay);glutMainLoop();图形学opengl入门-建模代码#include #include #include #include #include void DrawMyObjects(void)/* draw some points */glBegin(GL_POINTS);glColor3f(1.0,0.0,0.0);glVertex2f(-10.0,11.0);glColor3f(1.0,1.0,0.0);glVertex2f(-9.0,10.0);glColor3f(0.0,1.0,1.0);glVertex2f(-8.0,12.0);glEnd();/* draw some line_segments */glBegin(GL_LINES); glColor3f(1.0,1.0,0.0);glVertex2f(-11.0,8.0);glVertex2f(-7.0,7.0);glColor3f(1.0,0.0,1.0);glVertex2f(-11.0,9.0);glVertex2f(-8.0,6.0);glEnd();/* draw one opened_line */glBegin(GL_LINE_STRIP); glColor3f(0.0,1.0,0.0);glVertex2f(-3.0,9.0);glVertex2f(2.0,6.0);glVertex2f(3.0,8.0);glVertex2f(-2.5,6.5);glEnd();/* draw one closed_line */glBegin(GL_LINE_LOOP); glColor3f(0.0,1.0,1.0);glVertex2f(7.0,7.0);glVertex2f(8.0,8.0);glVertex2f(9.0,6.5);glVertex2f(10.3,7.5);glVertex2f(11.5,6.0);glVertex2f(7.5,6.0);glEnd();/* draw one filled_polygon */glBegin(GL_POLYGON); glColor3f(0.5,0.3,0.7);glVertex2f(-7.0,2.0);glVertex2f(-8.0,3.0);glVertex2f(-10.3,0.5);glVertex2f(-7.5,-2.0);glVertex2f(-6.0,-1.0);glEnd();/* draw some filled_quandrangles */glBegin(GL_QUADS); glColor3f(0.7,0.5,0.2);glVertex2f(0.0,2.0);glVertex2f(-1.0,3.0);glVertex2f(-3.3,0.5);glVertex2f(-0.5,-1.0);glColor3f(0.5,0.7,0.2);glVertex2f(3.0,2.0);glVertex2f(2.0,3.0);glVertex2f(0.0,0.5);glVertex2f(2.5,-1.0);glEnd();/* draw some filled_strip_quandrangles */glBegin(GL_QUAD_STRIP); glVertex2f(6.0,-2.0); glVertex2f(5.5,1.0);glVertex2f(8.0,-1.0);glColor3f(0.8,0.0,0.0);glVertex2f(9.0,2.0);glVertex2f(11.0,-2.0);glColor3f(0.0,0.0,0.8);glVertex2f(11.0,2.0);glVertex2f(13.0,-1.0);glColor3f(0.0,0.8,0.0);glVertex2f(14.0,1.0);glEnd();/* draw some filled_triangles */glBegin(GL_TRIANGLES); glColor3f(0.2,0.5,0.7);glVertex2f(-10.0,-5.0);glVertex2f(-12.3,-7.5);glVertex2f(-8.5,-6.0);glColor3f(0.2,0.7,0.5);glVertex2f(-8.0,-7.0);glVertex2f(-7.0,-4.5);glVertex2f(-5.5,-9.0);glEnd();/* draw some filled_strip_triangles */glBegin(GL_TRIANGLE_STRIP); glVertex2f(-1.0,-8.0);glVertex2f(-2.5,-5.0);glColor3f(0.8,0.8,0.0);glVertex2f(1.0,-7.0);glColor3f(0.0,0.8,0.8);glVertex2f(2.0,-4.0);glColor3f(0.8,0.0,0.8);glVertex2f(4.0,-6.0);glEnd();/* draw some filled_fan_triangles */glBegin(GL_TRIANGLE_FAN); glVertex2f(8.0,-6.0);glVertex2f(10.0,-3.0);glColor3f(0.8,0.2,0.5);glVertex2f(12.5,-4.5);glColor3f(0.2,0.5,0.8);glVertex2f(13.0,-7.5);glColor3f(0.8,0.5,0.2);glVertex2f(10.5,-9.0);glEnd();void myInit(void)glClearColor(0.0,0.0,0.0,0.0);glClear(GL_COLOR_BUFFER_BIT);glShadeModel(GL_FLAT);void myReshape(GLsizei w,GLsizei h)glViewport(0,0,w,h);glMatrixMode(GL_PROJECTION);glLoadIdentity();if(w=h)glOrtho(-20.0,20.0,-20.0*(GLfloat)h/(GLfloat)w, 20.0*(GLfloat)h/(GLfloat)w,-50.0,50.0);elseglOrtho(-20.0*(GLfloat)h/(GLfloat)w, 20.0*(GLfloat)h/(GLfloat)w,-20.0,20.0,-50.0,50.0);glMatrixMode(GL_MODELVIEW); glLoadIdentity();void myDisplay(void)glColor3f(1.0,1.0,0.0);DrawMyObj

温馨提示

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

评论

0/150

提交评论