Home > Software engineering >  Questions about OpenGL rendering to MFC dialog box
Questions about OpenGL rendering to MFC dialog box

Time:10-17

Problem description: I'm a MFC dialog box placed a TAB control, I to the TAB control is initialized, defines the two pages, each page is binding a child dialogs, tentatively defined as dialog 1 here, dialog box 2, 1 I want to show the dynamic image dialog, the dialog box 2 I want to display data and image display dialog 1 I use OpenGL,
These are done, found in the dialog box 1 and dialog switch directly to a memory leak, strange question, if I put below the m_pDisplay - & gt; Create (* * * *) function annotations, window switch don't have any problems,
I'm OpenGL dialog 1 configuration code is as follows:
CRect the rect (150, 20, 500, 370);//define the size of the drawing area
M_pDisplay - & gt; Create (NULL,
NULL,
//definition window style
WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE,
The rect,
This,
0);
Convenience to show my class defines the OpenGL COpenGL, base class is CWH, m_pDisplay is the object of a class, class implementation method is as follows,
Int COpenGL: : OnCreate (LPCREATESTRUCT LPCREATESTRUCT)
{
If (CWnd: : OnCreate (lpCreateStruct)==1)
return -1;

//TODO: here to add your special creation code
//set the current drawing pixel format
MySetPixelFormat (: : GetDC (m_hWnd));//set the current drawing pixel format
HDC=: : GetDC (m_hWnd);//get the drawing description table
HGLRC=wglCreateContext (HDC);//create the drawing description table
WglMakeCurrent (HDC, HGLRC);//make graphics context for the current call now cheng
the current drawing description table

return 0;
}

Int COpenGL: : MySetPixelFormat (HDC HDC)
{
PIXELFORMATDESCRIPTOR PFD={
Sizeof (PIXELFORMATDESCRIPTOR),//the size of the data structure
No. 1,//version
PFD_DRAW_TO_WINDOW |//window draw support
PFD_SUPPORT_OPENGL |//OpenGL support
PFD_DOUBLEBUFFER,//double cache support
PFD_TYPE_RGBA,//GRBA color mode
24,//24 color mode
0, 0, 0, 0, 0, 0,//ignore color a
0,//no Alpha cache
0,//ignore shift a
0,//no accumulation cache
0, 0, 0, 0,//ignore accumulate a
32,//32 bit depth buffer
0,//no template cache 0,//no auxiliary buffer without auxiliary cache
PFD_MAIN_PLANE,//the main layer main floor
0,//reserved reserve
0, 0, 0//ignore layers, visibility and damaged mask
};
Int iPixelFormat;
//get the device context 's best, the available pixel format match
//select matching pixel format, return to the index, to get the best match for device context of pixel format
If ((iPixelFormat=ChoosePixelFormat (HDC, & amp; PFD))==0)
{
MessageBox (NULL, _T (ChoosePixelFormat "Failed"), MB_OK);
return 0;
}

//make that match the device context 's current pixel format
//set the pixel format to a device context, setting up the matching pixel format for the current pixel format
If (SetPixelFormat (HDC, iPixelFormat, & amp; PFD)==FALSE)
{
MessageBox (NULL, _T (SetPixelFormat "Failed"), MB_OK);
return 0;
}
return 1;
}
Void COpenGL: : InitDrawArea ()
{glShadeModel (GL_SMOOTH);//Select Smooth Shading
GlHint (GL_PERSPECTIVE_CORRECTION_HINT GL_NICEST);//Set the Perspective Calculations To Most Accurate

Quadratic=gluNewQuadric ();//Create A Pointer To The Quadric Object
GluQuadricNormals (quadratic, GLU_SMOOTH);//Create Smooth Normals
GluQuadricTexture (quadratic, GL_TRUE);//Create Texture Coords
GlEnable (GL_TEXTURE_2D);//Enable Texture Mapping
GlTexParameteri (GL_TEXTURE_2D GL_TEXTURE_MAG_FILTER, GL_NEAREST);//Set Texture Max Filter
GlTexParameteri (GL_TEXTURE_2D GL_TEXTURE_MIN_FILTER, GL_NEAREST);//Set the Texture Min Filter

GlTexGeni (GL_S GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);//Set The Texture Generation Mode For S To Sphere Mapping
GlTexGeni (GL_T GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);//Set The Texture Generation Mode For T To Sphere Mapping

}

BOOL COpenGL: : DrawImage (int nWidth, int nHeight, int nChanel, GLubyte * pPixelData)
{

If (nChanel==1)
{
//this function is the function of, according to the specified parameters, generate a 2 d Texture (Texture)//1: R 2: RA 3: RGB 4: RGBA
GlTexImage2D (GL_TEXTURE_2D, 0, 1, nWidth, nHeight, 0, GL_RED, GL_UNSIGNED_BYTE, (GLvoid *) pPixelData);
}
Else if (nChanel==3)
{
GlTexImage2D (GL_TEXTURE_2D, 0, 3, nWidth, nHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid *) pPixelData);
}
Else if (nChanel==2)
{
GlTexImage2D (GL_TEXTURE_2D, 0, 2, nWidth, nHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid *) pPixelData);
}
The else
{
return FALSE;
}
GlClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
GlLoadIdentity ();
GlBegin (GL_QUADS);
{
GlTexCoord2f (0.0 0.0 f, f); GlVertex3f (0.0 + 1.0 1.0 f, f, f);
GlTexCoord2f (1.0 0.0 f, f); GlVertex3f (0.0 + 1.0 + 1.0 f, f, f);
GlTexCoord2f (1.0 1.0 f, f); GlVertex3f (0.0 + 1.0 f to 1.0 f, f);
GlTexCoord2f (0.0 1.0 f, f); GlVertex3f (0.0-1.0 f to 1.0 f, f);
}
GlEnd ();
GlFlush ();
SwapBuffers (HDC);

return TRUE;
}

CodePudding user response:

@ tiny ants

CodePudding user response:

reference 1st floor qq_34859917 response:
@ tiny ants

Just the memory leak? What phenomenon, with what tools to detect, memory leak should not leak at the end of the program to print? If a memory leak is the most obvious phenomenon in the process of switch should be memory growth,
Or do you mean collapse?
Create and commented, your OpenGL view isn't also show not to come out?
nullnullnullnullnullnull
  • Related