資源描述:
《圖形學opengl繪圖入門代碼》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、//opg1.cpp:Definestheentrypointfortheconsoleapplication.//#include"stdafx.h"/*#includevoiddisplay(void){glClear(GL_COLOR_BUFFER_BIT);//clearallpixelsglColor3f(1.0,1.0,1.0);glBegin(GL_POLYGON);//drawwhitepolygonglVertex3f(0.25,0.25,0.0);glVertex3f(0.75,0.25,0
2、.0);glVertex3f(0.75,0.75,0.0);glVertex3f(0.25,0.75,0.0);glEnd();glFlush();//startprocessingbufferedOpenGLroutines}voidinit(void){glClearColor(0.0,0.0,0.0,0.0);//selectclearingcolorglMatrixMode(GL_PROJECTION);glLoadIdentity();glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0);//initiali
3、zeviewingvalues}intmain(intargc,char**argv){glutInit(&argc,argv);glutInitDisplayMode(GLUT_SINGLE
4、GLUT_RGB);glutInitWindowSize(250,250);//Declareinitialwindowsize.glutInitWindowPosition(100,100);//Declareinitialwindowposition.glutCreateWindow("hello");//Openwindowwith"h
5、ello"initstitlebar.init();//Callinitializationroutines.glutDisplayFunc(display);/*Registercallbackfunctiontodisplaygraphics.glutMainLoop();//Entermainloopandprocessevents.return0;//ANSICrequiresmaintoreturnint.}*///GL_2_17.cpp:Definestheentrypointfortheconsoleapplicati
6、on.///*#include#include#include#includeconstintscreenWidth=640;constintscreenHeight=480;GLdoubleA,B,C,D;voidmyInit(void){glClearColor(1.0,1.0,1.0,0.0);glColor3f(0.0f,0.0f,0.0f);glPointSize(2.0);glMatrixMode(GL_PROJECTION);glLoadId
7、entity();gluOrtho2D(0.0,screenWidth,0.0,screenHeight);A=screenWidth/4.0;B=0.0;C=D=screenHeight/2.0;}voidmyDisplay(void){glClear(GL_COLOR_BUFFER_BIT
8、GL_DEPTH_BUFFER_BIT);glBegin(GL_POINTS);for(GLdoublex=0;x<4.0;x+=0.001){GLdoublefunc=exp(-x)*cos(2*3.14159265*x);glVertex
9、2d(A*x+B,C*func+D);}glEnd();glFlush();}voidmain(intargc,char**argv){glutInit(&argc,argv);glutInitDisplayMode(GLUT_SINGLE
10、GLUT_RGB);glutInitWindowSize(640,480);glutInitWindowPosition(100,150);glutCreateWindow("Dotplotofafunction");glutDisplayFunc(myDisplay);myInit();glu
11、tMainLoop();}*/圖形學第三課--opengl繪圖入門代碼#include#include#include#include#include