研究生计算机图形学课程室内场景OpenGL实验报告Word格式.docx
- 文档编号:20960051
- 上传时间:2023-01-26
- 格式:DOCX
- 页数:14
- 大小:19.80KB
研究生计算机图形学课程室内场景OpenGL实验报告Word格式.docx
《研究生计算机图形学课程室内场景OpenGL实验报告Word格式.docx》由会员分享,可在线阅读,更多相关《研究生计算机图形学课程室内场景OpenGL实验报告Word格式.docx(14页珍藏版)》请在冰豆网上搜索。
DoDataExchange(CDataExchange*pDX)
CDialog:
DoDataExchange(pDX);
BEGIN_MESSAGE_MAP(CAboutDlg,CDialog)
END_MESSAGE_MAP()
2、
255.0f255.0f255.0f1.5f1.0f
intWinWidth,WinHeigth;
unsignedshortintcomp=32;
unsignedshortinttemp,texture_mapping=FALSE,
land_fogging=TRUE,flat_shading=TRUE;
floatangle,Near,ex,ey,ez,cx,cy,cz;
staticGLfloatspeed=0;
#defineFORWARD1
#defineUP2
#defineTURNLEFT3
#defineLOOKUP5
intoldmx=0,oldmy=0,mb;
0.8f400.0f500.0f0.75f0.75f1.0f1.0f1.0f500.0f0.0f1.0f0.0f5.0f1.0fvoidCRenderView:
MoveEye(inttype,GLfloatamount,intupdate)
GLfloata;
switch(type){
caseFORWARD:
a=sqrt((cx-ex)*(cx-ex)+(cz-ez)*(cz-ez));
ex=(amount*(cx-ex)+a*ex)/a;
ez=(amount*(cz-ez)+a*ez)/a;
cx=(amount*(cx-ex)+a*cx)/a;
cz=(amount*(cz-ez)+a*cz)/a;
break;
caseTURNLEFT:
cx=(cx-ex)*(float)cos(amount/360.0f)+(cz-ez)*(float)sin(amount/360.0f)+ex;
cz=(cz-ez)*(float)cos(amount/360.0f)-(cx-ex)*(float)sin(amount/360.0f)+ez;
caseUP:
ey+=amount;
caseLOOKUP:
cy+=amount;
}
if(update){
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(ex,ey,ez,cx,cy,cz,0.0f,1.0f,0.0f);
TEXTURE_2D**TextureList;
OBJECT*ObjectList;
/*ObjectList[0]:
isolatedsurfaces*/
INT4SObjectNum;
chargEnergyFile[30];
charsLookAtFN[100];
charImageName[30];
voidCRenderView:
ReadData()
{
inti,j,l;
FILE*fp;
charstemp[100];
POINT3D*plist;
INT4UnAllVertexNum;
INT4U*pchlist;
strcpy(gEnergyFile,"
);
fp=fopen(gEnergyFile,"
r"
);
if(fp==NULL)
{
printf("
\nCannotopenenergydatafile:
%s\n"
gEnergyFile);
exit(0);
}
fseek(fp,0,SEEK_SET);
/******readtexturelist******/
fscanf(fp,"
%s"
stemp);
while(strcmp(stemp,"
texnum"
)!
=0)fscanf(fp,"
%d"
&
texnum);
TextureList=(TEXTURE_2D**)malloc(sizeof(TEXTURE_2D)*(texnum+1));
for(i=1;
i<
=texnum;
i++)
{
TextureList[i]=(TEXTURE_2D*)malloc(sizeof(TEXTURE_2D));
%s%s"
TextureList[i]->
fname,stemp);
if(strcmp(stemp,"
REPEAT_TEXTURE"
)==0)
TextureList[i]->
type=1;
elseif(strcmp(stemp,"
CLAMP_TEXTURE"
type=0;
/******Readobjectlist******/
ObjectNum"
=0)fscanf(fp,"
stemp);
%ld"
ObjectNum);
ObjectList=(OBJECT*)malloc(sizeof(OBJECT)*ObjectNum);
for(i=0;
i<
ObjectNum;
i++)
fscanf(fp,"
while(strcmp(stemp,"
SurfaceNum"
(ObjectList[i].SurfNum));
ObjectList[i].surflist=(SURFACE*)malloc(sizeof(SURFACE)*ObjectList[i].SurfNum);
for(j=0;
j<
ObjectList[i].SurfNum;
j++)
/******Readsurfaceinfor******/
while(strcmp(stemp,"
TextureId"
fscanf(fp,"
(ObjectList[i].surflist[j].texId));
pointnum"
(ObjectList[i].surflist[j].pointn));
triangle"
(ObjectList[i].surflist[j].triangle));
quadrangle"
(ObjectList[i].surflist[j].quadric));
/******Readpointlist******/
ObjectList[i].surflist[j].pointlist=(POINT3D*)malloc(sizeof(POINT3D)*
ObjectList[i].surflist[j].pointn);
plist=ObjectList[i].surflist[j].pointlist;
for(l=0;
l<
ObjectList[i].surflist[j].pointn;
l++)
%f%f%f%f%f%f%f%f"
&
(plist[l].r),&
(plist[l].g),&
(plist[l].b),
&
(plist[l].u),&
(plist[l].v),
(plist[l].x),&
(plist[l].y),&
(plist[l].z));
/******Readpatchlist******/
nAllVertexNum=ObjectList[i].surflist[j].triangle*3+
ObjectList[i].surflist[j].quadric*4;
ObjectList[i].surflist[j].patchlist=(INT4U*)malloc(sizeof(INT4U)*nAllVertexNum);
pchlist=ObjectList[i].surflist[j].patchlist;
nAllVertexNum;
(pchlist[l]));
}
fclose(fp);
InitLookAt()
strcpy(sLookAtFN,"
fp=fopen(sLookAtFN,"
rb"
if(fp==NULL)
ex=ey=ez=1.0f;
cx=cy=cz=0.0f;
Near=0.1f;
angle=30.0f;
elsefscanf(fp,"
angle,&
Near,&
ex,&
ey,&
ez,&
cx,&
cy,&
cz);
InitRenderWin()
glShadeModel(GL_SMOOTH);
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glMatrixMode(GL_MODELVIEW);
gluPerspective(angle,(float)WinWidth/(float)WinHeigth,Near,;
gluLookAt(ex,ey,ez,cx,cy,cz,,,;
Render(void)
inti,j,k,l,m,TexIndex;
POINT3D*plist;
INT4U*pchlist;
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_ACCUM_BUFFER_BIT);
TexIndex=ObjectList[i].surflist[j].texId;
if(TexIndex>
0)
InitTex(TexIndex);
l=0;
for(k=0;
k<
ObjectList[i].surflist[j].triangle;
k++)
{
glBegin(GL_TRIANGLES);
for(m=0;
m<
3;
m++)
{
glColor3f(plist[pchlist[l]].r,
plist[pchlist[l]].g,
plist[pchlist[l]].b);
glTexCoord2f(plist[pchlist[l]].u,
plist[pchlist[l]].v);
glVertex3f(plist[pchlist[l]].x,
plist[pchlist[l]].y,
plist[pchlist[l]].z);
l++;
}/*m*/
glEnd();
}/*k*/
ObjectList[i].surflist[j].quadric;
glBegin(GL_QUADS);
4;
plist[pchlist[l]].g,
glFlush();
CloseTex();
freelist()
inti,j;
for(i=0;
ObjectNum;
for(j=0;
j<
ObjectList[i].SurfNum;
j++)
free(ObjectList[i].surflist[j].pointlist);
free(ObjectList[i].surflist[j].patchlist);
}
free(ObjectList[i].surflist);
free(ObjectList);
for(i=1;
free(TextureList[i]);
free(TextureList);
externTEXTURE_2D**TextureList;
/********************************/
/*function:
OpenTexImage*/
unsignedchar*CRenderView:
OpenTexImage(INT2UTexIndex,INT2U*rslx,INT2U*rsly)
unsignedchar*image;
INT2Usrcx,srcy;
INT4Ui,j;
charImageName[30];
unsignedchar*SImageData;
intrc;
intwidth,height;
strcpy(ImageName,TextureList[TexIndex]->
fname);
/*loadaimage*/
fp=fopen(ImageName,"
if(!
fp)return0;
fseek(fp,18L,0);
rc=fread(&
width,sizeof(long),1,fp);
height,sizeof(long),1,fp);
*rslx=srcx=width;
*rsly=srcy=height;
fseek(fp,54L,0);
image=(unsignedchar*)malloc(width*height*3);
rc=fread(image,width*height*3,1,fp);
SImageData=(unsignedchar*)malloc(srcx*srcy*3);
for(i=0;
srcx;
i++){
for(j=0;
srcy;
j++){
(unsignedchar)*(SImageData+i*srcx*3+j*3+0)=(unsignedchar)*(image+i*srcx*3+j*3+2);
(unsignedchar)*(SImageData+i*srcx*3+j*3+1)=(unsignedchar)*(image+i*srcx*3+j*3+1);
(unsignedchar)*(SImageData+i*srcx*3+j*3+2)=(unsignedchar)*(image+i*srcx*3+j*3+0);
free(image);
printf("
%s:
%ld=%ld\n"
ImageName,srcx*srcy*3,i*j*3);
return(SImageData);
InitTex*/
InitTex(intTexIndex)
INT2UTextType;
unsignedchar*ImageData;
staticintOldIndex=-1;
if(TexIndex<
=0)return;
if(TexIndex==OldIndex)
glEnable(GL_TEXTURE_2D);
return;
ImageData=ImageDatas[TexIndex-1];
TextType=TextureList[TexIndex]->
type;
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
if(TextType==CLAMP_TEXTURE)
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
else
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D,0,3,rslxs[TexIndex-1],rslys[TexIndex-1],
0,GL_RGB,GL_UNSIGNED_BYTE,ImageData);
glEnable(GL_TEXTURE_2D);
OldIndex=TexIndex;
CloseTex*/
CloseTex()
glDisable(GL_TEXTURE_2D);
LoadAllTexture()
inti;
for(i=0;
texnum;
ImageDatas[i]=OpenTexImage(i+1,&
rslxs[i],&
rslys[i]);
Fre
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 研究生 计算机 图形学 课程 室内 场景 OpenGL 实验 报告