版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、OPENGL編程指導(dǎo),3.1 二維圖形顯示,像素操作函數(shù)(畫像素和讀像素) 最基本的繪圖函數(shù) 畫(寫)像素: SetPixel ( int x, int y, int color ) 讀像素: int GetPixel ( int x, int y) 注意:(1)具體的語言環(huán)境使用的函數(shù)名可能不同,這里的函數(shù)名僅用于課堂教學(xué),(2)屏幕坐標(biāo)系統(tǒng),坐標(biāo) 原點(diǎn),為了方便表示,課堂上使用常用坐標(biāo)系統(tǒng)。 OpenGL中的坐標(biāo)系統(tǒng)可變化。,O,Y,X,課堂 采用,Windows GDI,3.1 二維圖形顯示,用OpenGL實(shí)現(xiàn)讀/寫像素函數(shù),void SetPixel(int x, int y, flo
2、at r, float g, float b ) glColor3f(r,g,b); glBegin(GL_POINTS) glVertex2i(x,y); glEnd(); float* GetPixel(int x, int y) float *rgb= new float3; glReadPixels(x,y,1,1,GL_RGB,GL_FLOAT,rgb); return rgb; ,3.5 OpenGL相關(guān)函數(shù),坐標(biāo)系:gluOrtho2D(xmin, xmax,ymin,ymax) 函數(shù)設(shè)定屏幕顯示窗口的二維笛卡兒坐標(biāo)系 同時(shí)gluOrtho2D指定投影方式為正交投影 正交投影是一
3、種投影變換(直接去掉一個(gè)坐標(biāo)分量),采用矩陣運(yùn)算,因此初始狀態(tài)要設(shè)矩陣為單位矩陣 使用方法,一般在初始化OpenGL時(shí)調(diào)用,應(yīng)用程序窗口大小發(fā)生變化時(shí)也需要調(diào)用 glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(xmin, xmax,ymin, ymax);,(xmin, ymin),(xmax, ymax),Viewport,參數(shù)為絕對(duì)坐標(biāo),圖元坐標(biāo)超出部分將不顯示,例3-5-1,3.5 OpenGL相關(guān)函數(shù),#include int iWindowWidth=300,iWindowHeight=300; void init
4、(void) glClearColor (1.0, 1.0, 1.0, 0.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-iWindowWidth/2, iWindowWidth/2, -iWindowHeight/2, iWindowHeight/2); ,void keyboard(unsigned char key, int x, int y) switch (key) case 27:/ESC鍵 exit(0); break; ,void Reshape(int width, int height)/改變窗
5、口大小 glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-width/2, width/2, -height/2, height/2); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClear (GL_COLOR_BUFFER_BIT); iWindowWidth = width; iWindowHeight = height; ,3.5 OpenGL相關(guān)函數(shù),void display (void) glCle
6、ar (GL_COLOR_BUFFER_BIT); /繪制坐標(biāo)系 glLineWidth(2); glColor3f (0.0, 0.0, 0.0); glBegin(GL_LINES); glVertex2i(iWindowWidth/2-5,0); glVertex2i(-iWindowWidth/2+5,0);/X glVertex2i(iWindowWidth/2-20,5); glVertex2i(iWindowWidth/2-5,0);/Arrow glVertex2i(iWindowWidth/2-5,0); glVertex2i(iWindowWidth/2-20,-5); g
7、lVertex2i(0,iWindowHeight/2-5); glVertex2i(0,-iWindowHeight/2+5);/Y glVertex2i(-5,iWindowHeight/2-20); glVertex2i(0,iWindowHeight/2-5);/Arrow glVertex2i(0,iWindowHeight/2-5);glVertex2i(5,iWindowHeight/2-20); glEnd(); glPointSize(10);/Centre glBegin(GL_POINTS); glColor3f(1,0,0); glVertex2i(0,0); glEn
8、d(); glFlush(); ,3.5 OpenGL相關(guān)函數(shù),int main(int argc, char* argv) glutInit( ,3.5 OpenGL相關(guān)函數(shù),圖元繪制 指定圖元的類型(glBegin(type)指定) 定義頂點(diǎn)(坐標(biāo)glVertex,顏色glColor等) 結(jié)束(glEnd()) 編碼方法 glBegin(type); glVertex*(); /指定頂點(diǎn)坐標(biāo)1 glVertex*(); /指定頂點(diǎn)坐標(biāo)2 glEnd();,3.5 OpenGL相關(guān)函數(shù),type類型,3.5 OpenGL相關(guān)函數(shù),畫點(diǎn) glBegin中的參數(shù)為GL_POINTS glVert
9、ex的后綴組成 n (i|s|f|d) v n指定坐標(biāo)位數(shù),一般取2或3 (i|s|f|d)數(shù)值類型 i(整數(shù));s(短整數(shù));f(浮點(diǎn)數(shù));d(雙精度浮點(diǎn)數(shù)) v:坐標(biāo)數(shù)據(jù)是向量形式 例: (1)glBegin(GL_POINTS) (2)int point1=50,100; glVertex2i(50,100); int point2=750,150; glVertex2i(75,150); int point2=100,200; glVertex2i(100,200); glBegin(GL_POINTS) glEnd(); glVertex2iv(point1); ,3.5 OpenG
10、L相關(guān)函數(shù),點(diǎn)的屬性 顏色函數(shù) (1) glColor(3|4)(b|d|f|i|s|ub|ui|us)(TYPE r,TYPE g,TYPE b ) (2) glColor(3|4)(b|d|f|i|s|ub|ui|us)v(TYPE *rgb ) 其中:u表示無符號(hào) RGB色立方體 顏色模式:RGB(RGBA)和顏色表模式 大小:glPointSize(GLfloat size),3.5 OpenGL相關(guān)函數(shù),畫線 glBegin中的參數(shù)為:GL_LINES、GL_LINE_STRIP、 GL_LINE_LOOP GL_LINES:一組直線段; GL_LINE_STRIP:折線 GL_LI
11、NE_LOOP:封閉折線 例:頂點(diǎn)序列p1,p2,p3,p4,p5 glBegin(GL_LINES) glVertex2iv(p1); glVertex2iv(p2); glVertex2iv(p3); glVertex2iv(p4); glVertex2iv(p5); glEnd();,3.5 OpenGL相關(guān)函數(shù),GL_LINES,GL_LINE_STRIP,GL_LINE_LOOP,線的屬性 顏色:由點(diǎn)的顏色決定 寬度:glLineWidth(GLfloat width ) 只能用在glBegin之前,不能用在glBegin和glEnd之間 線型:void glLineStipple(
12、GLint factor, GLushort pattern); 使用前需要激活:glEnable(GL_LINE_STIPPLE); pattern: 16位掩碼 factor:每位重復(fù)次數(shù),3.5 OpenGL相關(guān)函數(shù),程序:(繪制回調(diào)函數(shù)) GLfloat y; / Storage for varying Y coordinate GLint factor = 1; / Stippling factor GLushort pattern = 0 x31df;/f38d; / Stipple pattern glEnable(GL_LINE_STIPPLE); glLineWidth(2)
13、; for(y = 30.0f; y 190.0f; y += 20.0f) / Reset the repeat factor and pattern glLineStipple(factor ,pattern); / Draw the line glBegin(GL_LINES); glVertex2f(80.0f, y); glVertex2f(240.0f, y); glEnd(); factor+; ,3.5 OpenGL相關(guān)函數(shù),掃描轉(zhuǎn)換的概念 直線的掃描轉(zhuǎn)換算法 DDA算法 中點(diǎn)算法 圓弧的掃描轉(zhuǎn)換算法 中點(diǎn)算法 逼近算法 圖元屬性表示 OpenGL基本繪制圖元函數(shù),小結(jié),4.8
14、 OpenGL相關(guān)函數(shù),區(qū)域函數(shù)(填充作用) 矩形函數(shù):glRecti|s|f|dv() glBegin()中的參數(shù) GL_POLYGON、GL_TRIANGLES、 GL_TRIANGLE_STRIP、 GL_TRIANGLE_FAN 三角形的三種繪制參數(shù),int p1=20,100,p2=50,50; int p3=110,50,p4=140,100; int p5=110,150,p6=50,150; glBegin(GL_TRIANGLES); glVertex2iv(p1); glVertex2iv(p2); glVertex2iv(p3); glVertex2iv(p4); glV
15、ertex2iv(p5); glVertex2iv(p6); glEnd();,GL_TRIANGLE_STRIP,GL_TRIANGLES,GL_TRIANGLE_FAN,p1,p1,p1,菜單函數(shù) int glutCreateMenu(void (*func)(int value);/創(chuàng)建菜單 void glutAddMenuEntry(char *name, int value);/添加菜單項(xiàng) void glutAddSubMenu(char *name, int menu);/添加子菜單 glutAttachMenu(int button); 例:,4.8 OpenGL相關(guān)函數(shù),voi
16、d MenuInit() int sub_menu1 = glutCreateMenu(objectMenu); glutAddMenuEntry(直線,11); glutAddMenuEntry(多邊形,12); glutCreateMenu(topMenu); glutAddSubMenu(圖形,sub_menu1); glutAddMenuEntry(退出,2); glutAttachMenu(GLUT_RIGHT_BUTTON); ,void objectMenu(int id) if (id=11) GraphicsType = 11; else if (id=12) Graphic
17、sType = 12; else GraphicsType = 0; void topMenu(int id) if (id=2) exit(0); ,線框圖與填充圖 函數(shù):glPloygonMode(face,displayMode) face:指定前后面??蛇x值:GL_FRONT、GL_BACK和GL_FRONT_AND_BACK displayMode:GL_FILL和GL_LINE,4.8 OpenGL相關(guān)函數(shù),void display (void) glClearColor (1.0, 1.0, 1.0, 0.0); glClear (GL_COLOR_BUFFER_BIT); gl
18、PolygonMode(GL_FRONT, GL_LINE); glBegin(GL_POLYGON); glColor3f(1.0,0,0); glVertex2f(0.5,0); glVertex2f(-0.5,0.5); glVertex2f(-0.5,-0.5); glVertex2f(0.6,-0.5); glEnd(); glFlush(); ,前向面:頂點(diǎn)序列逆時(shí)針順序排列,顏色插值模式 函數(shù):glShadeModel(mode) Mode: GL_FLAT和GL_SMOOTH 例:,4.8 OpenGL相關(guān)函數(shù),void display (void) glClearColor
19、(1.0, 1.0, 1.0, 0.0); glClear (GL_COLOR_BUFFER_BIT); glShadeModel(GL_FLAT);/默認(rèn)為GL_SMOOTH glBegin(GL_POLYGON); glColor3f(1,0,0); glVertex2f(-0.5,0.5); glColor3f(0,1,0); glVertex2f(-0.5,-0.5); glColor3f(0,0,1); glVertex2f(0.5,-0.5); glColor3f(1,1,1); glVertex2f(0.5,0.5); glEnd(); glFlush(); ,GL_FLAT方式
20、下以第1個(gè)點(diǎn)顏色填充,頂點(diǎn)數(shù)組 原因:復(fù)雜圖形需要很多坐標(biāo)描述,導(dǎo)致函數(shù)調(diào)用量大增,影響程序的執(zhí)行效率 采用頂點(diǎn)數(shù)組減少函數(shù)調(diào)用 方法 調(diào)用函數(shù)glEnableClientState(GL_VERTEX_ARRAY), 激活頂點(diǎn)數(shù)組特性 調(diào)用glVertexPointer指定頂點(diǎn)坐標(biāo)的位置和數(shù)據(jù)格式 使用與數(shù)組相關(guān)的函數(shù)繪制圖形,4.8 OpenGL相關(guān)函數(shù),例: glClear (GL_COLOR_BUFFER_BIT); glColor3f (1.0, 0.0, 0.0); vertex2 pt=20,100,50,50,110,50,140,100,110,150,50,150; glE
21、nableClientState(GL_VERTEX_ARRAY); glVertexPointer(2,GL_INT,0,pt); GLubyte vertIndex=0,1,2,3,4,5; glDrawElements(GL_TRIANGLES,24,GL_UNSIGNED_BYTE, vertIndex); glFlush ( );,4.8 OpenGL相關(guān)函數(shù),4.8 OpenGL相關(guān)函數(shù),寫像素模式 16種,默認(rèn)方式為GL_COPY 模式改變時(shí),需要調(diào)用glEnable(GL_COLOR_LOGIC_OP) 設(shè)置模式:glLogicOp(GL_XOR) 例:異或模式,背景,正方形,
22、4.8 OpenGL相關(guān)函數(shù),填充圖案函數(shù) 啟用函數(shù):glEnable(GL_POLYGON_STIPPLE) 關(guān)閉函數(shù):glDisable( GL_POLYGON_STIPPLE) 設(shè)置掩模(mask):glPolygonStipple(fillPattern) 注意:filePattern類型為GLubyte,大小為3232,GLubyte fillPattern= 0 x96,0 x96,0 x96,0 x96, 0 x84,0 x84,0 x84,0 x84, 0 x48,0 x48,0 x48,0 x48, 0 x20,0 x20,0 x20,0 x20, 0 x10,0 x10,0
23、 x10,0 x10, 0 x10,0 x10,0 x10,0 x10, 0 x18,0 x18,0 x18,0 x18, 0 x64,0 x64,0 x64,0 x64, 。(重復(fù)3次) ,4.8 OpenGL相關(guān)函數(shù),OpenGL位圖函數(shù) void glRasterPos234SIFDV(TYPE x, TYPE y, TYPE z, TYPE w); 設(shè)置當(dāng)前所畫位圖或圖像的原點(diǎn) glBitmap(width, height, x0,y0,xOffset,yOffset,bitShape) 設(shè)定當(dāng)前光柵位置 該函數(shù)顯示二值位圖。bitShape中的元素值為0或1,當(dāng)為1時(shí),用設(shè)定的顏色繪
24、制對(duì)應(yīng)的像素,否則對(duì)應(yīng)像素不受影響 位圖的存儲(chǔ)模式:字節(jié) glPixelStorei ( GL_UNPACK_ALIGNMENT, 1 ) ;,4.8 OpenGL相關(guān)函數(shù),程序,void display() glPixelStorei (GL_UNPACK_ALIGNMENT, 1); glColor3f (0.0, 0.0, 0.0); glRasterPos2i (100, 200); glBitmap (8, 12, 0.0, 0.0, 20.0, 20.0, rasters); glColor3f (1.0, 0.0, 0.0); glRasterPos2i (120, 220);
25、glBitmap (8, 12, 0.0, 0.0, 0.0, 0.0, rasters); glColor3f (0.0, 0.0, 1.0); glRasterPos2i (150, 200); glBitmap (8, 12, 0.0, 0.0, 0.0, 0.0, rasters); glFlush ( ); ,rasters,4.8 OpenGL相關(guān)函數(shù),繪制字符 OpenGL基本庫:位圖方法,需要自己創(chuàng)建字庫 GLUT工具包:位圖和輪廓字體 位圖字符函數(shù):glutBitmapCharacter(font, character) font:指定字型,常量(如GLUT_BITMAP_8
26、_BY_13) Character:字符的ASCII碼值 輪廓字符函數(shù):glutStrokeCharacter(font, character) font:指定字型,常量(如GLUT_STROKE_ROMAN) Character:字符的ASCII碼值 位圖和輪廓字符比較 前者速度快,后者放大縮小不變形,4.8 OpenGL相關(guān)函數(shù),程序,void display() glColor3f (1.0, 0.0, 0.0); glRasterPos2i (50, 50); glutBitmapCharacter (GLUT_BITMAP_9_BY_15,66); glRasterPos2i (80
27、, 50); glutBitmapCharacter (GLUT_BITMAP_TIMES_ROMAN_10,66); glColor3f (0.0, 0.0, 1.0); glPushMatrix(); glTranslatef(50,100,0);glScalef(0.2,0.2,1); glutStrokeCharacter(GLUT_STROKE_ROMAN,66); glPopMatrix(); glTranslatef(100,100,0); glScalef(0.6,0.6,1); glutStrokeCharacter(GLUT_STROKE_ROMAN,66); glutSw
28、apBuffers(); ,小結(jié),多邊形的掃描轉(zhuǎn)換 點(diǎn)是否在區(qū)域內(nèi)的判斷方法(射線法) 掃描線算法(思想、步驟和算法實(shí)現(xiàn)) 多邊形的區(qū)域填充 種子填充(連通性) 扇形區(qū)域的掃描轉(zhuǎn)換 字符的繪制方法 OpenGL函數(shù),5.2 反走樣方法,OpenGL實(shí)例,(a)走樣,(b)反走樣,5.3 OpenGL函數(shù),函數(shù) 啟動(dòng)反走樣:glEnable(),參數(shù)為GL_POINT、GL_LINE_SMOOTH或GL_POLYGON_SMOOTH 質(zhì)量控制:glHint(GLenum target, GLenum hint ), 參數(shù)target為:GL_POINT_SMOOTH_HINT、GL_LINE_S
29、MOOTH_HINT、GL_POLYGON_SMOOTH_HINT 等 參數(shù)hint為GL_FASTEST、GL_NICEST、GL_DONT_CARE 啟動(dòng)混合: glEnable(GL_BLEND) 選擇混合因子:glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);(還有其它選擇),5.3 OpenGL函數(shù),程序例,void display (void) glColor3f(0,0,0); glLineWidth(7); glBegin(GL_LINES); glVertex2i(10,10); glVertex2i(150,70); gl
30、End(); glEnable (GL_LINE_SMOOTH); glHint (GL_LINE_SMOOTH_HINT, GL_NICEST); glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glTranslatef(160,0,0); glBegin(GL_LINES); glVertex2i(10,10); glVertex2i(150,70); glEnd(); glDisable (GL_LINE_SMOOTH); glDisable (GL_BLEND); glFlush(); ,
31、小結(jié),三種走樣現(xiàn)象 反走樣方法 提高分辨率 非加權(quán)采樣 加權(quán)采樣 利用OpenGL函數(shù)進(jìn)行反走樣處理 啟動(dòng)函數(shù) 質(zhì)量控制函數(shù),6.8 OpenGL幾何變換函數(shù),說明 在核心庫中,每種幾何變換是一個(gè)獨(dú)立的函數(shù) 所有變換都是在三維坐標(biāo)系中定義 基本幾何變換函數(shù) 平移函數(shù):glTranslatefd(tx, ty, tz) 對(duì)二維變換而言,取tz0 旋轉(zhuǎn)函數(shù):glRotatefd(theta, vx, vy, vz) 向量(vx, vy, vz)為通過坐標(biāo)原點(diǎn)旋轉(zhuǎn)軸 theta為旋轉(zhuǎn)角的度數(shù) 放縮函數(shù):glScalefd(sx, sy, sz) 相對(duì)坐標(biāo)原點(diǎn)的縮放 當(dāng)參數(shù)為負(fù)時(shí),相對(duì)于平面進(jìn)行對(duì)稱變
32、換,6.8 OpenGL幾何變換函數(shù),例程序 6-1,void display (void) glColor3f (0.0, 0.0, 1.0); glRecti (20, 50, 100, 80); glColor3f (1.0, 0.0, 0.0); glTranslatef (-120.0, -40.0, 0.0); glRecti (20, 50, 100, 80); glLoadIdentity ( ); glColor3f (1.0, 0.0, 1.0); glRotatef (135.0, 0.0, 0.0, 1.0);glRecti (20, 50, 100, 80); glL
33、oadIdentity ( ); glColor3f ( 0.0, 1.0,0.0); glScalef (0.5, -1.0, 1.0); glRecti (20, 50, 100, 80); glColor3f(0,0,0); glLoadIdentity ( ); glBegin(GL_LINES); glVertex2i(0,-Y/2+5); glVertex2i(0,Y/2-5); glVertex2i(X/2-5,0); glVertex2i(-X/2+5,0); glEnd(); glutSwapBuffers(); ,注意: 幾何變換矩陣只有1個(gè),6.8 OpenGL幾何變換函
34、數(shù),例6-1(續(xù)),#include #include #include int X=0,Y=0; void Reshape(int width, int height) glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-width/2, width/2, -height/2, height/2); glMatrixMode(GL_MODELVIEW);/定義模型觀察變換矩陣 glLoadIdentity(); glClear (GL_COLOR_BUFFER_
35、BIT); X=width, Y=height; ,void init (void) glClearColor (1.0, 1.0, 1.0, 0.0); glMatrixMode(GL_PROJECTION); gluOrtho2D(0.0, 250.0, 0.0, 250.0); ,例6-1(續(xù)),6.8 OpenGL幾何變換函數(shù),int main(int argc, char* argv) glutInit( ,矩陣操作 模型觀察矩陣:glMatrixMode(GL_MODELVIEW) 建立當(dāng)前觀察矩陣 還有兩種方式:投影、紋理模式,默認(rèn)為觀察模式 設(shè)置當(dāng)前矩陣為單位矩陣:glLoad
36、Identity() 矩陣棧 3種:觀察、投影、紋理 初始狀態(tài)下,每棧僅包含一單位棧 壓棧:glPushMatrix() 出棧:glPopMatrix(),6.8 OpenGL幾何變換函數(shù),6.8 OpenGL幾何變換函數(shù),例62 機(jī)器人 手臂,#include #define BASE_HEIGHT 2.0 #define BASE_RADIUS 1.0 #define LOWER_ARM_HEIGHT 5.0 #define LOWER_ARM_WIDTH 0.5 #define UPPER_ARM_HEIGHT 5.0 #define UPPER_ARM_WIDTH 0.5 typede
37、f float point3; GLfloat theta = 0.0,0.0,0.0; GLint axis = 0; GLUquadricObj *p; /* pointer to quadric(二次曲面) object */ void myinit() glClearColor(1.0, 1.0, 1.0, 1.0); glColor3f(1.0, 0.0, 0.0); p=gluNewQuadric(); /* allocate quadric object */ gluQuadricDrawStyle(p, GLU_LINE); /* render it as wireframe
38、*/ ,6.8 OpenGL幾何變換函數(shù),例62(續(xù)),void base() glPushMatrix();/* rotate cylinder to align with y axis */ glRotatef(-90.0, 1.0, 0.0, 0.0);/* cyliner aligned with z axis*/ gluCylinder(p, BASE_RADIUS, BASE_RADIUS, BASE_HEIGHT, 5, 5); glPopMatrix(); void upper_arm() glPushMatrix(); glTranslatef(0.0, 0.5*UPPER_
39、ARM_HEIGHT, 0.0); glScalef(UPPER_ARM_WIDTH, UPPER_ARM_HEIGHT, UPPER_ARM_WIDTH); glutWireCube(1.0); glPopMatrix(); void lower_arm() glPushMatrix(); glTranslatef(0.0, 0.5*LOWER_ARM_HEIGHT, 0.0); glScalef( LOWER_ARM_WIDTH, LOWER_ARM_HEIGHT, LOWER_ARM_WIDTH); glutWireCube(1.0); glPopMatrix(); ,void gluC
40、ylinder( GLUquadricObj *qobj, GLdouble baseRadius, GLdouble topRadius, GLdouble height, GLint slices, GLint stacks );,6.8 OpenGL幾何變換函數(shù),void display(void) /* Accumulate ModelView Matrix as we traverse tree */ glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); glColor3f(1.0, 0.0, 0.0); glRotatef(theta0,
41、0.0, 1.0, 0.0); base(); glTranslatef(0.0, BASE_HEIGHT, 0.0); glRotatef(theta1, 0.0, 0.0, 1.0); lower_arm(); glTranslatef(0.0, LOWER_ARM_HEIGHT, 0.0); glRotatef(theta2, 0.0, 0.0, 1.0); upper_arm(); glutSwapBuffers(); ,void mouse(int btn, int state, int x, int y) /* left button increase joint angle, r
42、ight button decreases it */ if(btn=GLUT_LEFT_BUTTON ,思考:如果按照 upper_arm(); lower_arm(); base(); 次序繪制,如何修改程序?,6.8 OpenGL幾何變換函數(shù),void menu(int id) /* menu selects which angle to change or whether to quit */ if(id = 1 ) axis=0; if(id = 2) axis=1; if(id = 3 ) axis=2; if(id =4 ) exit(0); void myReshape(int
43、 w, int h) glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if (w = h) glOrtho(-10.0, 10.0, -5.0 * (GLfloat) h / (GLfloat) w, 15.0 * (GLfloat) h / (GLfloat) w, -10.0, 10.0); else glOrtho(-10.0 * (GLfloat) w / (GLfloat) h, 10.0 * (GLfloat) w / (GLfloat) h, -5.0, 15.0, -10.0, 10.
44、0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); ,6.8 OpenGL幾何變換函數(shù),void main(int argc, char *argv) glutInit( ,使用雙緩沖 以GLUT_DOUBLE為參數(shù)調(diào)用glutInitDisplayMode,設(shè)置雙緩存的窗口模式 在顯示回調(diào)函數(shù)的最后調(diào)用glutSwapBuffers()函數(shù) 空閑函數(shù)(回調(diào)函數(shù)) 定義:如 void spinCube() 功能:程序不受用戶干預(yù)時(shí)執(zhí)行spinCube()函數(shù) 注冊(cè):glutIdleFunc(spinCube) (在main函數(shù)中調(diào)用) 重繪制函數(shù)
45、 glutPostRedisplay(),6.8 OpenGL幾何變換函數(shù),例63:旋轉(zhuǎn)的立方體 8個(gè)頂點(diǎn)的顏色不同 不停地旋轉(zhuǎn) 鼠標(biāo)控制改變方向,6.8 OpenGL幾何變換函數(shù),#include #include /定義頂點(diǎn)坐標(biāo)和顏色 GLfloat vertices3 = -1.0,-1.0,-1.0,1.0,-1.0,-1.0, 1.0,1.0,-1.0, -1.0,1.0,-1.0, -1.0,-1.0,1.0, 1.0,-1.0,1.0, 1.0,1.0,1.0, -1.0,1.0,1.0; GLfloat colors3 = 0.0,0.0,0.0,1.0,0.0,0.0, 1.0,1.0,0.0, 0.0,1.0,0.0, 0.0,0.0,1.0, 1.0,0.0,1.0, 1.0,1.0,1.0, 0.0,1.0,1.0;,6.8 OpenGL幾何變換函數(shù),void polygon(int a, int b, int c , int d) /
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2026年江西航空職業(yè)技術(shù)學(xué)院?jiǎn)握芯C合素質(zhì)考試題庫附答案
- 2026年江西泰豪動(dòng)漫職業(yè)學(xué)院?jiǎn)握新殬I(yè)技能測(cè)試模擬測(cè)試卷附答案
- 2026年嘉興職業(yè)技術(shù)學(xué)院?jiǎn)握新殬I(yè)適應(yīng)性測(cè)試模擬測(cè)試卷及答案1套
- 2026年四川托普信息技術(shù)職業(yè)學(xué)院?jiǎn)握芯C合素質(zhì)考試模擬測(cè)試卷附答案
- 2026年心理健康測(cè)考試題庫及答案一套
- 2026年武漢海事職業(yè)學(xué)院?jiǎn)握新殬I(yè)適應(yīng)性考試模擬測(cè)試卷及答案1套
- 2026年山東科技職業(yè)學(xué)院?jiǎn)握新殬I(yè)技能考試題庫及答案1套
- 2026東盟海產(chǎn)品交易所有限公司福建福州招聘6人筆試備考題庫及答案解析
- 2025廣東中共深圳市委統(tǒng)戰(zhàn)部面向市內(nèi)選調(diào)公務(wù)員3人備考題庫附答案
- 2026福建龍巖連城縣委黨校公開選拔工作人員2人筆試模擬試題及答案解析
- 電力線通信技術(shù)
- 教師三筆字培訓(xùn)課件
- 中國(guó)醫(yī)藥行業(yè)中間體出口全景分析:破解政策難題深挖全球紅利
- 數(shù)學(xué)課如何提高課堂教學(xué)容量
- 監(jiān)理規(guī)劃畢業(yè)設(shè)計(jì)(論文)
- 京港澳高速公路段改擴(kuò)建工程施工保通方案(總方案)
- 醫(yī)用設(shè)備EMC培訓(xùn)資料課件
- RoHS培訓(xùn)資料課件
- 2020年廣東學(xué)位英語考試真題及答案
- 鍋爐防磨防爆工作專項(xiàng)檢查方案
- 《儀表本安防爆技術(shù)》課件
評(píng)論
0/150
提交評(píng)論