计算机图形学computer-graphics课件17

PPT
  • 阅读 140 次
  • 下载 0 次
  • 页数 38 页
  • 大小 1.123 MB
  • 2022-12-01 上传
  • 收藏
  • 违规举报
  • © 版权认领
下载文档25.00 元 加入VIP免费下载
此文档由【小橙橙】提供上传,收益归文档提供者,本网站只提供存储服务。若此文档侵犯了您的版权,欢迎进行违规举报版权认领
计算机图形学computer-graphics课件17
可在后台配置第一页与第二页中间广告代码
计算机图形学computer-graphics课件17
可在后台配置第二页与第三页中间广告代码
计算机图形学computer-graphics课件17
可在后台配置第三页与第四页中间广告代码
计算机图形学computer-graphics课件17
计算机图形学computer-graphics课件17
还剩10页未读,继续阅读
【这是免费文档,您可以免费阅读】
/ 38
  • 收藏
  • 违规举报
  • © 版权认领
下载文档25.00 元 加入VIP免费下载
文本内容

【文档说明】计算机图形学computer-graphics课件17.ppt,共(38)页,1.123 MB,由小橙橙上传

转载请保留链接:https://www.ichengzhen.cn/view-77497.html

以下为本文档部分文字说明:

BuffersSoftwareCollege,ShandongUniversityInstructor:ZhouYuanfengE-mail:yuanfeng.zhou@gmail.comReview2•Rasterization:Polygonscanconversi

onalgorithm;•Hiddensurfaceremoval•Aliasing3Objectives•IntroduceadditionalOpenGLbuffers•Learntoreadandwritebuffers•Learntouseblending4Bu

fferDefineabufferbyitsspatialresolution(nxm)anditsdepth(orprecision)k,thenumberofbits/pixelpixel5OpenGLFrameBuffer6OpenGLBu

ffers•Colorbufferscanbedisplayed-Front-Back-Auxiliary-Overlay•Depth•Accumulation-Highresolutionbuffer•Stencil-Holdsmasks7WritinginBuff

ers•Conceptually,wecanconsiderallofmemoryasalargetwo-dimensionalarrayofpixels•Wereadandwriterectangularblockofpixels-Bitblocktransfer(bitblt)operati

ons•Theframebufferispartofthismemory(Doublebuffer)•LeftandrightbuffersforStereroimagesframebuffer(destination)writingintoframebuffersou

rcememoryBit-blockwriting•Ascan-linewritingwhilepolygonfilling•Characterdisplay•Clearallpixelbuffer8BitBltcopy•BOOLBitB

lt(intx,inty,intnWidth,intnHeight,CDC*pSrcDC,intxSrc,intySrc,DWORDdwRop);//SRCCOPY•Copiesabitmapfromthesourcedevicecontexttothiscurre

ntdevicecontext.(FromaBitmapinmemorytocurrentCDC)910WritingModelReaddestinationpixelbeforewritingsourceSource:sDestination:d’

d’=f(s,d)11BitWritingModes(16modes)•Sourceanddestinationbitsarecombinedbitwise•16possiblefunctions(onepercolumnintable)replaceORXORMode3&6Mode6Mode3

1213XORmode•RecallfromChapter3thatwecanuseXORbyenablinglogicoperationsandselectingtheXORwritemodeS(SM)M•XORisespecia

llyusefulforswappingblocksofmemorysuchasmenusthatarestoredoffscreenIfSrepresentsscreenandMrepresentsamenuthesequenceSSMMSMSSMswapstheSand

M14ThePixelPipeline•OpenGLhasaseparatepipelineforpixels-Writingpixelsinvolves•Movingpixelsfromprocessormemoryt

otheframebuffer•Formatconversions•Mapping,Lookups,Tests-Readingpixels•Formatconversion15RasterPosition•OpenGLmaintainsarasterpositionaspartofthestat

e•SetbyglRasterPos*()(worldcoord)-glRasterPos3f(x,y,z);•Therasterpositionisageometricentity-Passesthroughgeometricpipeline-Eventuall

yyieldsa2Dpositioninscreencoordinates-Thispositionintheframebufferiswherethenextrasterprimitiveisdrawn16Buffe

rSelection•OpenGLcandrawintoorreadfromanyofthecolorbuffers(front,back,auxiliary)•Defaulttothebackbuffer•ChangewithglDrawBuf

ferandglReadBuffer•Notethatformatofthepixelsintheframebufferisdifferentfromthatofprocessormemoryandthesetwotypesofmemoryresideindif

ferentplaces-Needpackingandunpacking-DrawingandreadingcanbeslowOpenGLcodeLib3dsMesh*mesh=f3ds->meshes[i];//由3ds文件中读取出需要数

据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_BUFFE

R,m_Index[0]);glDrawElements(GL_TRIANGLES,DrawCount[0],GL_UNSIGNED_SHORT,NULL);1718Bitmaps•OpenGLtreats1-bitpixels(bitmaps)differe

ntlyfrommulti-bitpixels(pixelmaps)•Bitmapsaremasksthatdetermineifthecorrespondingpixelintheframebufferisdrawnwit

hthepresentrastercolor-0colorunchanged-1colorchangedbasedonwritingmode•Bitmapsareusefulforrastertextcursor(XOR)-GLUTfont:GLUT_BIT_MAP_8_BY_1319Rast

erColor•SameasdrawingcolorsetbyglColor*()•CurrentrastercolorisfixedbylastcalltoglRasterPos*()•Geometrydrawnin

blue•OnesinbitmapuseadrawingcolorofredglColor3f(1.0,0.0,0.0);glRasterPos3f(x,y,z);glColor3f(0.0,0.0,1.0);

glBitmap(…….glBegin(GL_LINES);glVertex3f(…..)20DrawingBitmapsglBitmap(width,height,x0,y0,xi,yi,bitmap)fi

rstrasterpositionsecondrasterpositionoffsetfromrasterpositionincrementsinrasterpositionafterbitmapdrawnTextdefinitioninO

penGL•Rastertextisfasterthanvectortext;•Times,Courier,ComputerModern;•Size:10pt,24pt(1inch=72pt)21TextinOpenGL•8x13textisdefinedin

GLUT_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();•}2223Exa

mple: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];glBitma

p(64,64,0.0,0.0,0.0,0.0,check);24ImageFormats•Weoftenworkwithimagesinastandardformat(JPEG,TIFF,GIF,PS,EPS)•Howdoweread/writesuchima

geswithOpenGL?•NosupportinOpenGL-OpenGLknowsnothingofimageformats-SomecodeavailableonWeb-Canwritereaders/writersforsomesimpleformatsinO

penGLPS&EPS•PostScript(PS)imageforcontrollingprinterRGBimageconvertsto7bitsASCII;soPSimagecanbeidentifi

edbyprinter,butitislarge.•EncapsulatedPostScript(EPS)issimilartoPSimage.25GIFimage•CompuServeIncorporated(1987)GraphicsInterch

angeFormatColorIndexImagelow-resolutionsmallanimations(imageslices)26TIFF•Tagged(标签)ImageFileFormat•Highquality•Firstforscannedcopy•Loss

lesscompression•Cansavevectorboundaryofimage27JPEG•lossycompression•Highcompressionratio•Discretecosinetra

nsform28Sizecomparison•Image1200x1200•TIFF:1440198bytes(about1.37m)•JPEG:80109and38962bytes(about78kb)•EPS:abouttwiceofTIFF•Comp

ressedTIFF:abouthalfsize•ZIPcompression:TIFFandEPSaresimilar29TIFFJPEG-18JPEG-3730DisplayingaPPMImage(Linux)•PPMisaverysim

pleformat(24bits)•Eachimagefileconsistsofaheaderfollowedbyallthepixeldata•HeaderP3#comment1#comment2.#commentnrowscolumnsmaxvaluepixels3

1ReadingtheHeaderFILE*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("%sisaPPMf

ile\n",b);checkfor“P3”infirstline32ReadingtheHeader(cont)fscanf(fd,"%c",&c);while(c=='#'){fscanf(fd,"%[^\n]",b);print

f("%s\n",b);fscanf(fd,"%c",&c);}ungetc(c,fd);skipovercommentsbylookingfor#infirstcolumn33ReadingtheDat

afscanf(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;}scalefactor34PixelMaps•OpenGLworkswithrectangulararraysofpixelscalledpixelmapsorimages•Pixelsareino

nebyte(8bit)chunks-Luminance(grayscale)images1byte/pixel-RGB3bytes/pixel•Threefunctions-Drawpixels:processormemorytoframeb

uffer-Readpixels:framebuffertoprocessormemory-Copypixels:framebuffertoframebufferPixelformat•Imageinmemory:RGB,RGB

A,Index•Format:intorfloat•glPixelMap3536OpenGLPixelFunctionsglReadPixels(x,y,width,height,format,type,myimage)startpixelinframebuffersizetypeofimage

typeofpixelspointertoprocessormemoryGLubytemyimage[512][512][3];glReadPixels(0,0,512,512,GL_RGB,GL_UNSIGNED_BYTE,myimage);glDrawPixels(w

idth,height,format,type,myimage)startsatrasterposition37ScalingtheImageDataWecanscaletheimageinthepipelineglPixelTransferf(GL_R

ED_SCALE,s);glPixelTransferf(GL_GREEN_SCALE,s);glPixelTransferf(GL_BLUE_SCALE,s);Wemayhavetoswapbyteswhenwegofromproce

ssormemorytotheframebufferdependingontheprocessor.Ifso,wecanuseglPixelStorei(GL_UNPACK_SWAP_BYTES,GL_TRUE);38Thedisplaycallbackvoid

display(){glClear(GL_COLOR_BUFFER_BIT);glRasterPos2i(0,0);glDrawPixels(n,m,GL_RGB,GL_UNSIGNED_INT,image);glFlush();}

小橙橙
小橙橙
文档分享,欢迎浏览!
  • 文档 25747
  • 被下载 7
  • 被收藏 0
相关资源
广告代码123
若发现您的权益受到侵害,请立即联系客服,我们会尽快为您处理。侵权客服QQ:395972555 (支持时间:9:00-21:00) 公众号
Powered by 太赞文库
×
确认删除?