計算機圖形學(xué)computer-graphics課件17_第1頁
計算機圖形學(xué)computer-graphics課件17_第2頁
計算機圖形學(xué)computer-graphics課件17_第3頁
計算機圖形學(xué)computer-graphics課件17_第4頁
計算機圖形學(xué)computer-graphics課件17_第5頁
已閱讀5頁,還剩33頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論