版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、1Programming in OpenGL中國(guó)地質(zhì)大學(xué)2History of OpenGLnSilicon Graphics (SGI) revolutionized the graphics workstation by implementing the pipeline in hardware (1982)nTo access the system, application programmers used a library called GLnWith GL, it was relatively simple to program three dimensional interact
2、ive applications 中國(guó)地質(zhì)大學(xué)3OpenGL: What is It?nThe success of GL lead to OpenGL (1992), a platform-independent API that was nEasy to usenClose enough to the hardware to get excellent performancenFocus on renderingnOmitted windowing and input to avoid window system dependencies 中國(guó)地質(zhì)大學(xué)4OpenGL: What is It
3、?nGL (Graphics Library): Library of 2-D, 3-D drawing primitives and operationsnAPI for 3-D hardware acceleration nGLU (GL Utilities): Miscellaneous functions dealing with camera set-up and higher-level shape descriptionsnGLUT (GL Utility Toolkit): Window-system independent toolkit with numerous util
4、ity functions, mostly dealing with user interface中國(guó)地質(zhì)大學(xué)5OpenGL ArchitectureDisplayListPolynomialEvaluatorPer VertexOperations &PrimitiveAssemblyRasterizationPer FragmentOperationsFrameBufferTextureMemoryCPUPixelOperations中國(guó)地質(zhì)大學(xué)6OpenGL as a RenderernGeometric primitivesnpoints, lines and polygons
5、nImage Primitivesnimages and bitmapsnseparate pipeline for images and geometryolinked through texture mappingnRendering depends on statencolors, materials, light sources, etc.中國(guó)地質(zhì)大學(xué)7OpenGL Geometric Primitives中國(guó)地質(zhì)大學(xué)8Specifying Geometric PrimitivesnPrimitives are specified usingglBegin(primType);.glE
6、nd();nprimType determines how vertices are combinedGLfloat red, green, blue;GLfloat x, y;glBegin(primType);for (i = 0; i nVerts; i+) glColor3f(red, green, blue); glVertex2f(x, y); . / change coord. valuesglEnd();中國(guó)地質(zhì)大學(xué)9OpenGL Vertex/Color Command FormatsglVertex3fv( v )Number ofcomponents2 - (x,y) 3
7、 - (x,y,z), (r,g,b)4 - (x,y,z,w), (r,g,b,a)Data Typeb - byteub - unsigned bytes - shortus - unsigned shorti - intui - unsigned intf - floatd - doubleVectoromit “v” forscalar form e.g.,glVertex2f(x, y)glColor3f(r, g, b)glColor3fv( v )中國(guó)地質(zhì)大學(xué)10Software OrganizationGLUTGLUGLGLX, AGLor WGLX, Win32, Mac O
8、/Ssoftware and/or hardwareapplication programOpenGL Motifwidget or similar中國(guó)地質(zhì)大學(xué)11Lack of Object OrientationnOpenGL is not object oriented so that there are multiple functions for a given logical functionnglVertex3f nglVertex2i nglVertex3dvnUnderlying storage mode is the samenEasy to create overload
9、ed functions in C+ but issue is efficiency中國(guó)地質(zhì)大學(xué)12OpenGL function formatglVertex3f(x,y,z)belongs to GL libraryfunction namex,y,z are floatsglVertex3fv(p)p is a pointer to an arraydimensions中國(guó)地質(zhì)大學(xué)OpenGLWindow management13n初始化( glutInit ) glutInit function must be called before other function use glut
10、Init(&argc, argv);n設(shè)定窗口的顯示模式( glutInitDisplayMode) glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); GLUT_DOUBLE, GLUT_INDEXnthe size and position of the window glutInitWindowPosition設(shè)置窗口在屏幕中的位置 glutInitWindowPosition(100,120) glutInitWindowSize設(shè)置窗口的大小 glutInitWindowSize(400,300)nCreate Window( glutC
11、reateWindow) glutCreateWindow(矩形); glutMainLoop( )OpenGLWindow managementOpenGLWindow managementn指定窗口的顯示內(nèi)容函數(shù)( glutDisplayFunc) glutDisplayFunc(Display)n運(yùn)行框架( glutMainLoop) 啟動(dòng)主GLUT事件處理循環(huán)OpenGLGraphics rendering16n指定窗口背景色( glClearColor)nglClearColor(1.0f, 1.0f, 1.0f, 1.0f);OpenGLGraphics rendering17混合
12、色紅色成分(R)綠色成分(G)藍(lán)色成分(B)黑0.00.00.0紅1.00.00.0綠0.01.00.0黃1.01.00.0藍(lán)0.00.01.0紫1.00.01.0青0.01.01.0深灰5淺灰0.750.750.75棕0.600.400.12南瓜橙0.980.6250.12粉紅0.980.040.70紫紅0.600.400.70白1.01.01.0OpenGLGraphics rendering18n刷新窗口的緩沖區(qū)( glClear)n設(shè)定投影參數(shù) glMatrixMode(GL_PROJECTION); gluOrtho2D(0.0,200.0,0.0,150.0)
13、;n繪制圖形 glRectf(50.0f, 100.0f, 150.0f, 50.0f);OpenGL程序?qū)嵗?繪制矩形#include void Initial(void)glClearColor(1.0f, 1.0f, 1.0f, 1.0f); /設(shè)置窗口背景顏色為白色glMatrixMode(GL_PROJECTION); /設(shè)置投影參數(shù)gluOrtho2D(0.0,200.0,0.0,150.0);void Display(void)glClear(GL_COLOR_BUFFER_BIT); /用當(dāng)前背景色填充窗口glColor3f(1.0f, 0.0f, 0.0f); /設(shè)置當(dāng)前的繪
14、圖顏色為紅色glRectf(50.0f, 100.0f, 150.0f, 50.0f); /繪制一個(gè)矩形 glFlush(); /處理所有的OpenGL程序OpenGL程序?qū)嵗?繪制矩形int main(int argc, char* argv)glutInit(&argc, argv);glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); /初始化窗口的顯示模式glutInitWindowSize(400,300); /設(shè)置窗口的尺寸glutInitWindowPosition(100,120); /設(shè)置窗口的位置glutCreateWindow(
15、矩形); /創(chuàng)建一個(gè)名為矩形的窗口glutDisplayFunc(Display); /設(shè)置當(dāng)前窗口的顯示回調(diào)函數(shù)Initial(); /完成窗口初始化glutMainLoop(); /啟動(dòng)主GLUT事件處理循環(huán)return 0;OpenGL程序?qū)嵗?繪制奧運(yùn)五環(huán)#include GLuint OlympicRings;void Initial(void)glClearColor(1.0f, 1.0f, 1.0f, 1.0f); OlympicRings = glGenLists(1);glNewList(OlympicRings, GL_COMPILE);glColor3f(1.0, 1.0
16、, 0.0);glTranslatef(-22.0, 0.0, 0.0);glutSolidTorus(0.5, 20.0, 15, 50); /繪制黃色環(huán) glColor3f(0.0, 1.0, 0.0);glTranslatef(44.0, 0.0, 0.0);glutSolidTorus(0.5, 20.0, 15, 50); /繪制綠色環(huán)glColor3f(0.0, 0.0, 0.0);glTranslatef(-22.0, 30.0, 0.0);glutSolidTorus(0.5, 20.0, 15, 50); /繪制黑色環(huán)glColor3f(0.0, 0.0, 1.0);glTr
17、anslatef(-42.0, 0.0, 0.0);glutSolidTorus(0.5, 20.0, 15, 50); /繪制藍(lán)色環(huán)glColor3f(1.0, 0.0, 0.0);glTranslatef(84.0, 0.0, 0.0);glutSolidTorus(0.5, 20.0, 15, 50); /繪制紅色環(huán)glEndList();OpenGL程序?qū)嵗?繪制奧運(yùn)五環(huán)void ChangeSize(int w, int h)glViewport(0, 0, w, h);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluOrtho2D (
18、-70.0f, 70.0f, -70.0f, 70.0f);OpenGL程序?qū)嵗?繪制奧運(yùn)五環(huán)void Display(void)glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_MODELVIEW);glLoadIdentity();glCallList(OlympicRings); /調(diào)用顯示列表glFlush(); OpenGL程序?qū)嵗?繪制奧運(yùn)五環(huán)int main(int argc, char* argv)glutInit(&argc, argv);glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
19、 glutInitWindowSize(400,400); glutInitWindowPosition(100,100); glutCreateWindow(OpenGL模型繪制函數(shù)示例); glutDisplayFunc(Display);glutReshapeFunc(ChangeSize);Initial(); glutMainLoop(); return 0;OpenGL程序?qū)嵗?繪制奧運(yùn)五環(huán)Coordinate transformation sequence中國(guó)地質(zhì)大學(xué)26nOpenGL Matrix OperationsnGLU Clipping windownOpenGL Vi
20、ewport2d Viewing in OpenGL中國(guó)地質(zhì)大學(xué)27nglMatrixMode(GL_PROJECTION)nglLoadIdentity();OpenGL Matrix Operations中國(guó)地質(zhì)大學(xué)28ngluOtho2D(xwmin, xwmax, ywmin, ywmax); Coordinate positions for the clipping window boundaries are given as double precision numbers.nThe default clipping window: wxl=-1.0,wxr=1.0, wyt=-1
21、.0, wyb=1.0GLU Clipping window中國(guó)地質(zhì)大學(xué)29nglViewPort(xvmin,yvmin,vpWidth,vpHeighht) All parameter values are given in integer screen coordinates relative to the display window.OpenGL Viewport中國(guó)地質(zhì)大學(xué)3031OpenGL CameranRight-handed systemnFrom point of view of camera looking out into scene:nOpenGL places a
22、 camera at the origin in object space pointing in the negative z directionnPositive rotations are counterclockwise around axis of rotation中國(guó)地質(zhì)大學(xué)32Coordinate SystemsnThe units in glVertex are determined by the application and are called object or problem coordinatesnThe viewing specifications are als
23、o in object coordinates and it is the size of the viewing volume that determines what will appear in the imagenInternally, OpenGL will convert to camera (eye) coordinates and later to screen coordinates中國(guó)地質(zhì)大學(xué)33Transformations in OpenGlnModeling transformationnRefer to the transformation of models (i
24、.e., the scenes, or objects)nViewing transformationnRefer to the transformation on the cameranProjection transformationnRefer to the transformation from scene to image中國(guó)地質(zhì)大學(xué)34Model/View TransformationsnModel-view transformations are usually visualized as a single entitynBefore applying modeling or v
25、iewing transformations, need to set glMatrixMode(GL_MODELVIEW)nModeling transforms the objectoTranslation:glTranslate(x,y,z)oScale: glScale(sx,sy,sz)oRotation: glRotate(theta, x,y,z)nViewing transfers the object into camera coordinates(定義觀察坐標(biāo)系)ogluLookAt (eyeX, eyeY, eyeZ, centerX, centerY, centerZ,
26、 upX, upY, upZ)中國(guó)地質(zhì)大學(xué)nViewing transfers the object into camera coordinates(定義觀察坐標(biāo)系)ogluLookAt (eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ)oP0( eyeX, eyeY, eyeZ )觀察坐標(biāo)系原點(diǎn)oPref( , centerX, centerY, centerZ )reference positiono upX, upY, upZ 定義觀察正向矢量Model/View Transformations中國(guó)地質(zhì)大學(xué)3536Mo
27、del/View transformationCourtesy: Neider, Davis and Woo, “The OpenGL Programming Guide”中國(guó)地質(zhì)大學(xué)37Projection TransformationnTransformation of the 3D scene into the 2D rendered image planenBefore applying projection transformations, need to setglMatrixMode(GL_PROJECTION)nOrthographic projectionoglOrtho(l
28、eft, right, bottom, top, near, far)nPerspective projectionoglFrustum (left, right, bottom, top, near, far)中國(guó)地質(zhì)大學(xué)38Projection TransformationF.S.Hill, “Computer Graphics using OpenGL”O(jiān)rthographic projectionPerspective projection中國(guó)地質(zhì)大學(xué)nvoid gluPerspective (GLdouble fovy, GLdouble aspect, GLdouble zNear
29、, GLdouble zFar);OpenGL symmetric perspective projection function.Projection Transformation中國(guó)地質(zhì)大學(xué)3940GLUT event loopnLast line in main.c for a program using GLUT is the infinite event loopglutMainLoop();nIn each pass through the event loop, GLUT nlooks at the events in the queuenfor each event in th
30、e queue, GLUT executes the appropriate callback function if one is definednif no callback is defined for the event, the event is ignorednIn glutDisplayFunc(mydisplay) identifies the function to be executednEvery GLUT program must have a display callback中國(guó)地質(zhì)大學(xué)41Posting redisplaysnMany events may invoke the display callback functionnCan lead to multiple executions of the display callback on a single pass through the event loopnWe can avoid this problem by instead usingglutPostRedisplay(); which sets a flag. nGLUT checks to see if the flag is set at the e
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五版暨南大學(xué)離婚心理學(xué)研究與應(yīng)用合同3篇
- 二零二五年度電梯門套綠色環(huán)保材料采購(gòu)合同3篇
- 二零二五年度集團(tuán)高層管理人員聘任與職務(wù)調(diào)整合同6篇
- 二零二五年股票代持與反洗錢義務(wù)合同3篇
- 二零二五年駕駛員勞務(wù)派遣與車輛充電樁油耗管理服務(wù)合同3篇
- 二零二五版戶外拓展訓(xùn)練特色課程開(kāi)發(fā)與推廣合同3篇
- 二零二五年度玻璃器皿生產(chǎn)設(shè)備租賃合同3篇
- 2025年度國(guó)際教育培訓(xùn)機(jī)構(gòu)合作合同6篇
- 展會(huì)展位搭建服務(wù)合同(2篇)
- 2025年度餐飲設(shè)施設(shè)備租賃合同書3篇
- 醫(yī)院手術(shù)室醫(yī)院感染管理質(zhì)量督查評(píng)分表
- 心內(nèi)電生理導(dǎo)管及器械
- 稱量與天平培訓(xùn)試題及答案
- 超全的超濾與納濾概述、基本理論和應(yīng)用
- 2020年醫(yī)師定期考核試題與答案(公衛(wèi)專業(yè))
- 2022年中國(guó)育齡女性生殖健康研究報(bào)告
- 各種靜脈置管固定方法
- 消防報(bào)審驗(yàn)收程序及表格
- 教育金規(guī)劃ppt課件
- 呼吸機(jī)波形分析及臨床應(yīng)用
- 常用緊固件選用指南
評(píng)論
0/150
提交評(píng)論