xml地图|网站地图|网站标签 [设为首页] [加入收藏]
关于OpenGL绘制到MFC对话框的疑问,求大神帮忙
分类:编程

对话类的贰个分子函数:

难点陈述:小编在八个MFC对话框上停放了二个tabcontrol,我对那几个tabcontrol举行早先化,定义了两页,各类页面都绑定了三个child的对话框,这里暂时定义为对话框1,对话框2,对话框1自家要呈现动态图像,对话框2自家要显得数据。对话框1自己动用OpenGL进行图像的展现。这一个都做好后,发将来对话框1和对话框实行切换时,直接就内部存储器泄漏。好意外的难点。如若本人把下文中的m_pDisplay-Create(****卡塔尔国函数注释掉,窗口切换就没任何难点了。小编对对话框1的OpenGL的配备代码如下:CRectrect(150,20,500,370卡塔尔;//定义绘图区域的大小m_pDisplay-Create(NULL,NULL,//定义窗口作风WS_CHILD|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_VISIBLE,rect,this,0卡塔尔(英语:State of Qatar);为了有助于突显自身定义了OpenGL类COpenGL,基类是CWH,m_pDisplay正是多个类对象。类的兑现格局如下所示。intCOpenGL::OnCreate(LPCREATESTRUCTlpCreateStruct卡塔尔{if(CWnd::OnCreate(lpCreateStruct卡塔尔(قطر‎==-1卡塔尔(英语:State of Qatar)return-1;//TODO:在这里加多你专项使用的创制代码//设置当前的绘图像素格式MySetPixelFormat(::GetDC(m_hWnd卡塔尔卡塔尔;//设置当前的绘图像素格式hdc=::GetDC(m_hWnd卡塔尔国;//获得绘图描述表hglrc=wglCreateContext(hdc卡塔尔(英语:State of Qatar);//创立绘图描述表wglMakeCurrent(hdc,hglrc卡塔尔(قطر‎;//使绘图描述表为当前调用现程的脚下绘制描述表return0;}intCOpenGL::MySetPixelFormat(HDChdc卡塔尔(قطر‎{PIXELFORMATDESC奇骏IPTO普拉多pfd={sizeof(PIXELFORMATDESC如虎 CTR 3IPTOTiguan卡塔尔国,//数据构造的朗朗上口1,//版本号PFD_DRAW_TO_WINDOW|//窗口绘制补助PFD_SUPPORT_OPENGL|//OpenGL支持PFD_DOUBLEBUFFETucson,//双缓存扶助PFD_TYPE_TiggoGBA,//GRBA颜色形式24,//26人颜色情势0,0,0,0,0,0,//忽视颜色位0,//无Alpha缓存0,//忽视移位位0,//无积攒缓存0,0,0,0,//忽视累计位32,//三十二位深度缓存0,//无模板缓存0,//noauxiliarybuffer无扶植缓存PFD_MAIN_PLANE,//mainlayer主层0,//reserved保留0,0,0//忽视层、可以知道性及损毁掩码};intiPixelFormat;//getthedevicecontext'sbest,availablepixelformatmatch//选择相配像素格式,重返索引,为设备描述表拿到最相配的像素格式if((iPixelFormat=ChoosePixelFormat(hdc,pfd卡塔尔卡塔尔(英语:State of Qatar)==0卡塔尔{Message博克斯(NULL,_T("ChoosePixelFormatFailed"),MB_OK卡塔尔国;return0;}//makethatmatchthedevicecontext'scurrentpixelformat//设置像素格式到器械描述表,设置最相称的像素格式为方今的像素格式if(SetPixelFormat(hdc,iPixelFormat,pfd卡塔尔(英语:State of Qatar)==FALSE卡塔尔{MessageBox(NULL,_T("SetPixelFormatFailed"),MB_OK);return0;}return1;}voidCOpenGL::InitDrawArea(){glShadeModel(GL_SMOOTH);//SelectSmoothShadingglHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);//SetPerspectiveCalculationsToMostAccuratequadratic=gluNewQuadric();//CreateAPointerToTheQuadricObjectgluQuadricNormals(quadratic,GLU_SMOOTH);//CreateSmoothNormalsgluQuadricTexture(quadratic,GL_TRUE);//CreateTextureCoordsglEnable(GL_TEXTURE_2D);//EnableTextureMappingglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);//SetTextureMaxFilterglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);//SetTextureMinFilterglTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP);//SetTheTextureGenerationModeForSToSphereMappingglTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP);//SetTheTextureGenerationModeForTToSphereMapping}BOOLCOpenGL::DrawImage(intnWidth,intnHeight,intnChanel,GLubyte*pPixelData卡塔尔(英语:State of Qatar){if(nLa Prairie==1卡塔尔国{//该函数的功效是,依据钦命的参数,生成三个2D纹理//1:Koleos2:RA3:途胜GB4:奇骏GBAglTexImage2D(GL_TEXTURE_2D,0,1,nWidth,nHeight,0,GL_RED,GL_UNSIGNED_BYTE,(GLvoid*)pPixelData);}elseif(nChanel==3){glTexImage2D(GL_TEXTURE_2D,0,3,nWidth,nHeight,0,GL_RGB,GL_UNSIGNED_BYTE,(GLvoid*)pPixelData);}elseif(nChanel==2){glTexImage2D(GL_TEXTURE_2D,0,2,nWidth,nHeight,0,GL_RGB,GL_UNSIGNED_BYTE,(GLvoid*)pPixelData);}else{returnFALSE;}glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);glLoadIdentity();glBegin(GL_QUADS);{glTexCoord2f(0.0f,0.0f);glVertex3f(-1.0f,+1.0f,0.0f);glTexCoord2f(0.0f,1.0f);glVertex3f(+1.0f,+1.0f,0.0f);glTexCoord2f(1.0f,1.0f);glVertex3f(+1.0f,-1.0f,0.0f);glTexCoord2f(1.0f,0.0f);glVertex3f(-1.0f,-1.0f,0.0f);}glEnd();glFlush();SwapBuffers(hdc);returnTRUE;}

就不截图了,大致叙述一下。输入多少个假名有机关补全,不过还是不是高亮当选,只是相近有个框,那个时候回车就换行了。必得先按下方向键,然后非常框才变得高亮,那时候回车才得以,每便按方向键选一下效能太低了,怎么整?

voidCBBCDlg::OnBnClickedCheck1(){show="show";pMFrame=(CMainFrame*)GetParentFrame();pMFrame-show=show;pMFrame-Invalidate();//TODO:在此添加控件通知处理程序代码}

本文由澳门新葡亰手机版发布于编程,转载请注明出处:关于OpenGL绘制到MFC对话框的疑问,求大神帮忙

上一篇:谁可以帮忙解释一下这段代码的意思,Socket实现 下一篇:CImagelist和ListCtrl的结合使用,双按键不能跳转到
猜你喜欢
热门排行
精彩图文