




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
BuffersSoftwareCollege,ShandongUniversityInstructor:ZhouYuanfengE-mail:yuanfeng.zhou@BuffersSoftwareCollege,ShandReview2Rasterization:Polygonscanconversionalgorithm;HiddensurfaceremovalAliasingReview2Rasterization:Polygon3ObjectivesIntroduceadditionalOpenGLbuffersLearntoreadandwritebuffersLearntouseblending3ObjectivesIntroduceadditiona4BufferDefineabufferbyitsspatialresolution(nxm)anditsdepth(orprecision)k,thenumberofbits/pixelpixel4BufferDefineabufferbyits5OpenGLFrameBuffer5OpenGLFrameBuffer6OpenGLBuffersColorbufferscanbedisplayedFrontBackAuxiliaryOverlayDepthAccumulationHighresolutionbufferStencilHoldsmasks6OpenGLBuffersColorbuffersc7WritinginBuffersConceptually,wecanconsiderallofmemoryasalargetwo-dimensionalarrayofpixelsWereadandwriterectangularblockofpixelsBitblocktransfer(bitblt)operationsTheframebufferispartofthismemory(Doublebuffer)LeftandrightbuffersforStereroimagesframebuffer(destination)writingintoframebuffersourcememory7WritinginBuffersConceptuallBit-blockwritingAscan-linewritingwhilepolygonfillingCharacterdisplayClearallpixelbuffer8Bit-blockwritingAscan-linewBitBltcopyBOOLBitBlt(intx,inty,intnWidth,intnHeight,CDC*pSrcDC,intxSrc,intySrc,DWORDdwRop);//SRCCOPYCopiesabitmapfromthesourcedevicecontexttothiscurrentdevicecontext.(FromaBitmapinmemorytocurrentCDC)9BitBltcopyBOOLBitBlt(intx,10WritingModelReaddestinationpixelbeforewritingsourceSource:sDestination:d’d’=f(s,d)10WritingModelReaddestinatio11BitWritingModes(16modes)Sourceanddestinationbitsarecombinedbitwise16possiblefunctions(onepercolumnintable)replaceORXOR11BitWritingModes(16modes)Mode3&6Mode6Mode312Mode3&6Mode613XORmodeRecallfromChapter3thatwecanuseXORbyenablinglogicoperationsandselectingtheXORwritemodeS(SM)MXORisespeciallyusefulforswappingblocksofmemorysuchasmenusthatarestoredoffscreenIfSrepresentsscreenandMrepresentsamenuthesequenceSSMMSMSSMswapstheSandM13XORmodeRecallfromChapter14ThePixelPipelineOpenGLhasaseparatepipelineforpixelsWritingpixelsinvolvesMovingpixelsfromprocessormemorytotheframebufferFormatconversionsMapping,Lookups,TestsReadingpixelsFormatconversion14ThePixelPipelineOpenGLhas15RasterPositionOpenGLmaintainsarasterpositionaspartofthestateSetbyglRasterPos*()(worldcoord)glRasterPos3f(x,y,z);TherasterpositionisageometricentityPassesthroughgeometricpipelineEventuallyyieldsa2DpositioninscreencoordinatesThispositionintheframebufferiswherethenextrasterprimitiveisdrawn15RasterPositionOpenGLmainta16BufferSelectionOpenGLcandrawintoorreadfromanyofthecolorbuffers(front,back,auxiliary)DefaulttothebackbufferChangewith
glDrawBufferand
glReadBufferNotethatformatofthepixelsintheframebufferisdifferentfromthatofprocessormemoryandthesetwotypesofmemoryresideindifferentplacesNeedpackingandunpackingDrawingandreadingcanbeslow16BufferSelectionOpenGLcandOpenGLcodeLib3dsMesh
*mesh
=
f3ds->meshes[i];
//由3ds文件中讀取出需要數(shù)據(jù)
glGenBuffers(1,&m_Vertex[i]);
glGenBuffers(1,&m_Index[i]);
glBindBuffer(GL_ARRAY_BUFFER,m_Vertex[i]);
glBufferData(GL_ARRAY_BUFFER,(sizeof(float)
*
9
*
mesh->nfaces)
+
(sizeof(float)
*
3
*
mesh->nvertices),TotleV,GL_STATIC_DRAW);
glVertexPointer(3,GL_FLOAT,0,BUFFER_OFFSET(0));
glNormalPointer(GL_FLOAT,0,BUFFER_OFFSET(V_size));
glBindBuffer(GL_ARRAY_BUFFER,m_Vertex[0]);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,m_Index[0]);
glDrawElements(GL_TRIANGLES,DrawCount[0],GL_UNSIGNED_SHORT,NULL);
17OpenGLcodeLib3dsMesh
*mesh18BitmapsOpenGLtreats1-bitpixels(bitmaps)differentlyfrommulti-bitpixels(pixelmaps)Bitmapsaremasksthatdetermineifthecorrespondingpixelintheframebufferisdrawnwiththepresentrastercolor0colorunchanged1colorchangedbasedonwritingmodeBitmapsareusefulforrastertextcursor(XOR)GLUTfont:
GLUT_BIT_MAP_8_BY_1318BitmapsOpenGLtreats1-bitp19RasterColorSameasdrawingcolorsetbyglColor*()CurrentrastercolorisfixedbylastcalltoglRasterPos*()GeometrydrawninblueOnesinbitmapuseadrawingcolorofredglColor3f(1.0,0.0,0.0);glRasterPos3f(x,y,z);glColor3f(0.0,0.0,1.0);glBitmap(…….glBegin(GL_LINES);glVertex3f(…..)19RasterColorSameasdrawing20DrawingBitmapsglBitmap(width,height,x0,y0,xi,yi,bitmap)firstrasterpositionsecondrasterpositionoffsetfromrasterpositionincrementsinrasterpositionafterbitmapdrawn20DrawingBitmapsglBitmap(widtTextdefinitioninOpenGLRastertextisfasterthanvectortext;Times,Courier,ComputerModern;Size:10pt,24pt(1inch=72pt)21TextdefinitioninOpenGLRasteTextinOpenGL8x13textisdefinedinGLUT_BITMAP_8_BY_13;Thesizeoftextisrelatedwithresolutionofscreen;Define8x13text:GLubytemy_font[128][13];base=glGenLists(128);for(i=0;i<128;i++){glNewList(base+i,GL_COMPILE);glBitMap(8,13,0.0,0.0,10.0,0.0,my_font[i]);glEndList();}22TextinOpenGL8x13textisdef23Example:CheckerBoardGLubytewb[2]={0x00,0xFF};GLubytecheck[512];inti,j;for(i=0;i<64;i++)for(j=0;j<8,j++)check[i*8+j]=wb[(i/8+j)%2];glBitmap(64,64,0.0,0.0,0.0,0.0,check);23Example:CheckerBoardGLubyt24ImageFormatsWeoftenworkwithimagesinastandardformat(JPEG,TIFF,GIF,PS,EPS)Howdoweread/writesuchimageswithOpenGL?NosupportinOpenGLOpenGLknowsnothingofimageformatsSomecodeavailableonWebCanwritereaders/writersforsomesimpleformatsinOpenGL24ImageFormatsWeoftenworkwPS&EPSPostScript(PS)imageforcontrollingprinter
RGBimageconvertsto7bitsASCII;soPSimagecanbeidentifiedbyprinter,butitislarge.EncapsulatedPostScript(EPS)issimilartoPSimage.25PS&EPSPostScript(PS)imagefGIFimageCompuServeIncorporated(1987)GraphicsInterchangeFormatColorIndexImagelow-resolutionsmallanimations(imageslices)26GIFimageCompuServeIncorporatTIFFTagged(標簽)ImageFileFormatHighqualityFirstforscannedcopyLosslesscompressionCansavevectorboundaryofimage27TIFFTagged(標簽)ImageFileFormJPEGlossycompressionHighcompressionratioDiscretecosinetransform28JPEGlossycompression28SizecomparisonImage1200x1200TIFF:1440198bytes(about1.37m)JPEG:80109and38962bytes(about78kb)EPS:abouttwiceofTIFFCompressedTIFF:abouthalfsizeZIP
compression:TIFF
andEPSaresimilar29TIFFJPEG-18JPEG-37SizecomparisonImage1200x120030DisplayingaPPMImage(Linux)PPMisaverysimpleformat(24bits)EachimagefileconsistsofaheaderfollowedbyallthepixeldataHeaderP3#comment1#comment2.#commentnrowscolumnsmaxvaluepixels30DisplayingaPPMImage(Linux31ReadingtheHeaderFILE*fd;intk,nm;charc;inti;charb[100];floats; intred,green,blue;printf("enterfilename\n");scanf("%s",b);fd=fopen(b,"r");fscanf(fd,"%[^\n]",b);if(b[0]!='P'||b[1]!='3'){ printf("%sisnotaPPMfile!\n",b); exit(0);}printf("%sisaPPMfile\n",b);checkfor“P3”infirstline31ReadingtheHeaderFILE*fd;c32ReadingtheHeader(cont)fscanf(fd,"%c",&c);while(c=='#') { fscanf(fd,"%[^\n]",b); printf("%s\n",b); fscanf(fd,"%c",&c);} ungetc(c,fd);skipovercommentsbylookingfor#infirstcolumn32ReadingtheHeader(cont)fsc33ReadingtheDatafscanf(fd,"%d%d%d",&n,&m,&k);printf("%drows%dcolumnsmaxvalue=%d\n",n,m,k);nm=n*m;image=malloc(3*sizeof(GLuint)*nm);s=255./k;for(i=0;i<nm;i++){ fscanf(fd,"%d%d%d",&red,&green,&blue); image[3*nm-3*i-3]=red; image[3*nm-3*i-2]=green; image[3*nm-3*i-1]=blue;}scalefactor33ReadingtheDatafscanf(fd,"34PixelMapsOpenGLworkswithrectangulararraysofpixelscalledpixelmapsorimagesPixelsareinonebyte(8bit)chunksLuminance(grayscale)images1byte/pixelRGB3bytes/pixelThreefunctionsDrawpixels:processormemorytoframebufferReadpixels:framebuffertoprocessormemoryCopypixels:framebuffertoframebuffer34PixelMapsOpenGLworkswithPixelformatImageinmemory:RGB,RGBA,IndexFormat:intorfloatglPixelMap35PixelformatImagei
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度生豬養(yǎng)殖與農(nóng)業(yè)產(chǎn)業(yè)扶貧合作協(xié)議
- 二零二五年度制造業(yè)工傷責(zé)任保險合同
- 2025年度男方道歉夫妻共同生活保證協(xié)議
- 2025年度飯店短期勞務(wù)合同-客房服務(wù)員職業(yè)健康與安全協(xié)議
- 二零二五年度物業(yè)公司員工勞動合同(含社區(qū)文化活動)
- 監(jiān)理技術(shù)服務(wù)合同
- 綠色數(shù)據(jù)中心建設(shè)運營合同
- 環(huán)境影響評估結(jié)果展示表
- 股份制企業(yè)股權(quán)分配與管理制度文書
- 財務(wù)與成本控制管理細則
- 2025年山西省太原市衛(wèi)健委直屬單位招聘522人歷年高頻重點模擬試卷提升(共500題附帶答案詳解)
- 勞務(wù)合同協(xié)議書書
- 白城2025年吉林大安市事業(yè)單位面向上半年應(yīng)征入伍高校畢業(yè)生招聘5人筆試歷年參考題庫附帶答案詳解
- 全球人工智能產(chǎn)業(yè)發(fā)展現(xiàn)狀和趨勢
- 2025年內(nèi)蒙古化工職業(yè)學(xué)院高職單招職業(yè)技能測試近5年??及鎱⒖碱}庫含答案解析
- 民法典解讀之婚姻家庭編
- 2025年菏澤醫(yī)學(xué)??茖W(xué)校高職單招數(shù)學(xué)歷年(2016-2024)頻考點試題含答案解析
- 2025年漯河職業(yè)技術(shù)學(xué)院高職單招職業(yè)技能測試近5年??及鎱⒖碱}庫含答案解析
- Unit 2 What time is it?-A Let's spell(課件)-2024-2025學(xué)年人教PEP版英語四年級下冊
- 2024-2025學(xué)年人教版數(shù)學(xué)六年級下冊第二單元百分數(shù)(二)(含答案)
- 創(chuàng)新教案:《歌唱二小放牛郎》在2025年音樂教學(xué)中的應(yīng)用
評論
0/150
提交評論