Home > Software engineering >  MFC environment opengl super bible gltools use problem
MFC environment opengl super bible gltools use problem

Time:09-24

New people for help: before compilation runs in the console environment all have no problem, but now want to MFC environment, gltools glGenVertexArray function of compiling can pass, but the problem is always a memory, and is a great god what might be the problem, is there a viable solution?

CodePudding user response:

Memory problems? If there were any place have a memory leak

CodePudding user response:

reference 1st floor boylafong response:
memory problems? If there's any place have a memory leak
but in the case of the console and no such problem

CodePudding user response:

//ModelView. CPP: CModelView class the implementation of the
//

# include "stdafx. H"
//SHARED_HANDLERS can achieve in the preview, thumbnails and search filter handle
//ATL project are defined, and allow the code to share with the project document,
# # ifndef SHARED_HANDLERS
# include "Model. H"
# endif

# include "ModelDoc. H"
# include "ModelView. H"

# ifdef _DEBUG
# define new DEBUG_NEW
# endif

GLBatch triangleBatch;
GLint myIdentityShader;
//CModelView

IMPLEMENT_DYNCREATE (CModelView, CView)

BEGIN_MESSAGE_MAP (CModelView, CView)
//standard print command
ON_COMMAND (ID_FILE_PRINT, & amp; The CView: : OnFilePrint)
ON_COMMAND (ID_FILE_PRINT_DIRECT, & amp; The CView: : OnFilePrint)
ON_COMMAND (ID_FILE_PRINT_PREVIEW, & amp; CModelView: : OnFilePrintPreview)
ON_WM_CONTEXTMENU ()
ON_WM_RBUTTONUP ()
ON_WM_CREATE ()
ON_WM_DESTROY ()
END_MESSAGE_MAP ()

//CModelView structure/destructor

CModelView: : CModelView ()
{
//TODO: add construction code here
My_pDC=NULL;
}

CModelView: : ~ CModelView ()
{
}

BOOL CModelView: : PreCreateWindow (CREATESTRUCT& Cs)
{
//TODO: here by modifying the
//cs to modify the CREATESTRUCT window class or style

Return the CView: : PreCreateWindow (cs);
}

//CModelView drawing

Void CModelView: : ontouch pDC (CDC */* */)
{
CModelDoc * pDoc=GetDocument ();
ASSERT_VALID (pDoc);
if (! PDoc)
return;

//TODO: here is the machine data add rendering code
The static BOOL bBusy=FALSE;
If (bBusy) return;
BBusy=TRUE;
GlClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
RenderScene ();
BBusy=FALSE;
}


//print CModelView


Void CModelView: : OnFilePrintPreview ()
{
# # ifndef SHARED_HANDLERS
AFXPrintPreview (this);
# endif
}

BOOL CModelView: : OnPreparePrinting (CPrintInfo * pInfo)
{
//the default to
Return DoPreparePrinting (pInfo);
}

Void CModelView: : OnBeginPrinting (CDC, pDC */* */pInfo CPrintInfo */* */)
{
//TODO: add additional print before initialization process
}

Void CModelView: : OnEndPrinting (CDC, pDC */* */pInfo CPrintInfo */* */)
{
//TODO: add print after the cleaning process of
}

Void CModelView: : OnRButtonUp (UINT nFlags *//* and CPoint point)
{
ClientToScreen (& amp; Point);
OnContextMenu (this point);
}

Void CModelView: : OnContextMenu (pWnd CWnd */* */, CPoint point)
{
# # ifndef SHARED_HANDLERS
TheApp. GetContextMenuManager () - & gt; ShowPopupMenu (IDR_POPUP_EDIT, point x, point y, this, TRUE);
# endif
}

Void CModelView: : SetupRC ()
{
//Blue background
GlClearColor (0.0 f, f, 0.0 0.0 f, 1.0 f);

//shaderManager InitializeStockShaders ();

//the Load up a triangle
F GLfloat vVerts []={0.5, 0.0 f, 0.0 f,
0.5 f, f 0.0, 0.0 f,
0.0 f, f 0.5, 0.0} f;

GLfloat vColors []={0.0 1.0 f, f, f 0.0, 1.0 f,
1.0 0.0 f, f, f 0.0, 1.0 f,
F 0.0, 0.0 f, f 1.0, 1.0} f;

TriangleBatch. The Begin (GL_TRIANGLES, 3);
TriangleBatch. CopyVertexData3f (vVerts);
TriangleBatch. CopyColorData4f (vColors);
TriangleBatch. End ();

MyIdentityShader=gltLoadShaderPairWithAttributes (" st. vp ", "st. fp," 2,
GLT_ATTRIBUTE_VERTEX, "vVertex GLT_ATTRIBUTE_COLOR," vColor ");
}

Void CModelView: : RenderScene ()
{
GlClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
GlUseProgram (myIdentityShader);
TriangleBatch. The Draw ();
GlutSwapBuffers ();
}


Void CModelView: : ShutdownRC ()
{
GlDeleteProgram (myIdentityShader);
}

Bool CModelView: : mypixelformat ()
{
The static PIXELFORMATDESCRIPTOR PFD=
{
Sizeof (PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
24,
0,0,0,0,0,0,
0,
0,
0,
0,0,0,0,
32,
0,
0,
PFD_MAIN_PLANE,
0,
0 0,
};
Int pixelformat;
If ((pixelformat=ChoosePixelFormat (my_pDC - & gt; GetSafeHdc (), & amp; PFD))==0)
{
MessageBox (_T (ChoosePixelFormat "failed"));
return FALSE;
}
If (SetPixelFormat (my_pDC - & gt; GetSafeHdc (), pixelformat, & amp; PFD)==FALSE)
{
MessageBox (_T (SetPixelFormat "failed"));
return FALSE;
}
Return TRUE;
}

Void CModelView... myfirst ()
{
PIXELFORMATDESCRIPTOR PFD.
int n;
HGLRC HRC.
My_pDC=new CClientDC (this);
ASSERT (my_pDC!=NULL);
if (! Mypixelformat ())
return;
N=: : GetPixelFormat (my_pDC - & gt; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related