glBegin( GL_QUADS ); for( m = 0; m < 4; 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 */ glFlush(); CloseTex(); } }
void CRenderView::freelist() { int i, j; for( i=0; i free(ObjectList); for(i=1; i<=texnum; i++) free(TextureList[i]); free(TextureList); } 26 extern TEXTURE_2D **TextureList; /********************************/ /* function : OpenTexImage */ /********************************/ unsigned char *CRenderView::OpenTexImage( INT2U TexIndex, INT2U *rslx, INT2U *rsly ) { unsigned char *image; FILE *fp; INT2U srcx, srcy; INT4U i, j; char ImageName[30]; unsigned char *SImageData; int rc; int width, height; strcpy( ImageName, TextureList[TexIndex]->fname); /* load a image */ fp = fopen(ImageName,\ if(!fp) return 0; fseek(fp,18L,0); rc=fread(&width,sizeof(long),1,fp); rc=fread(&height,sizeof(long),1,fp); *rslx=srcx=width; *rsly=srcy=height; fseek(fp,54L,0); image = (unsigned char *)malloc(width*height*3); rc=fread(image,width*height*3,1,fp); fclose(fp); SImageData = (unsigned char *)malloc(srcx*srcy*3); for(i=0; i 27 = (unsigned = (unsigned = (unsigned } } free(image); printf(\ return( SImageData ); } /********************************/ /* function : InitTex */ /********************************/ void CRenderView::InitTex( int TexIndex ) { INT2U TextType; unsigned char *ImageData; static int OldIndex = -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 { 28 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; } /********************************/ /* function : CloseTex */ /********************************/ void CRenderView::CloseTex() { glDisable(GL_TEXTURE_2D); } void CRenderView::LoadAllTexture() { int i; for (i=0; i void CRenderView::FreeAllTexture() { int i; for (i=0; i 5、StdAfx.cpp #include \ 6、Tool.cpp #include \ 29 #include \ #include \#include \#include \#include \ // Download by http://www.codefans.net #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif // CToolApp CToolDoc *MyDocument; BEGIN_MESSAGE_MAP(CToolApp, CWinApp) //{{AFX_MSG_MAP(CToolApp) ON_COMMAND(ID_APP_ABOUT, OnAppAbout) //}}AFX_MSG_MAP // Standard file based document commands // Standard print setup command ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup) END_MESSAGE_MAP() // CToolApp construction CToolApp::CToolApp() { // Options m_OptionColorGlBack = RGB(0,0,255); } // The one and only CToolApp object CToolApp theApp; // CToolApp initialization BOOL CToolApp::InitInstance() { AfxEnableControlContainer(); // Standard initialization 30 百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库研究生计算机图形学课程室内场景OpenGL--实验报告(6)在线全文阅读。
相关推荐: