Skip to content

Commit

Permalink
fixed cleanup, fixed unused context
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Ershov committed Jun 29, 2015
1 parent 3f68787 commit 8ed4560
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
31 changes: 11 additions & 20 deletions samples/opengl/opengl_interop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,14 @@ class GLWinApp : public WinApp

~GLWinApp() {}

int onClose(void)
virtual void cleanup()
{
m_shutdown = true;
cleanup();
#if defined(WIN32) || defined(_WIN32)
::DestroyWindow(m_hWnd);
#elif defined(__linux__)
#if defined(__linux__)
glXMakeCurrent(m_display, None, NULL);
glXDestroyContext(m_display, m_glctx);
XDestroyWindow(m_display, m_window);
XCloseDisplay(m_display);
#endif
return 0;
WinApp::cleanup();
}

#if defined(WIN32) || defined(_WIN32)
Expand All @@ -75,12 +70,14 @@ class GLWinApp : public WinApp
}
else if (wParam == VK_ESCAPE)
{
return onClose();
cleanup();
return 0;
}
break;

case WM_CLOSE:
return onClose();
cleanup();
return 0;

case WM_DESTROY:
::PostQuitMessage(0);
Expand Down Expand Up @@ -117,7 +114,7 @@ class GLWinApp : public WinApp
if ((Atom)e.xclient.data.l[0] == m_WM_DELETE_WINDOW)
{
m_end_loop = true;
onClose();
cleanup();
}
else
{
Expand All @@ -144,7 +141,7 @@ class GLWinApp : public WinApp
break;
case XK_Escape:
m_end_loop = true;
onClose();
cleanup();
break;
}
break;
Expand All @@ -155,7 +152,7 @@ class GLWinApp : public WinApp
}
#endif

int init(void)
int init()
{
#if defined(WIN32) || defined(_WIN32)
m_hDC = GetDC(m_hWnd);
Expand All @@ -180,7 +177,7 @@ class GLWinApp : public WinApp

if (cv::ocl::haveOpenCL())
{
m_oclCtx = cv::ogl::ocl::initializeContextFromGL();
(void) cv::ogl::ocl::initializeContextFromGL();
}

m_oclDevName = cv::ocl::useOpenCL() ?
Expand Down Expand Up @@ -342,11 +339,6 @@ class GLWinApp : public WinApp
return 0;
}

int cleanup(void)
{
return 0;
}

protected:

#if defined(WIN32) || defined(_WIN32)
Expand Down Expand Up @@ -415,7 +407,6 @@ class GLWinApp : public WinApp
cv::VideoCapture m_cap;
cv::Mat m_frame_bgr;
cv::Mat m_frame_rgba;
cv::ocl::Context m_oclCtx;
cv::String m_oclDevName;
};

Expand Down
10 changes: 10 additions & 0 deletions samples/opengl/winapp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ class WinApp
return init();
}

virtual void cleanup()
{
#if defined(WIN32) || defined(_WIN32)
::DestroyWindow(m_hWnd);
#elif defined(__linux__)
XDestroyWindow(m_display, m_window);
XCloseDisplay(m_display);
#endif
}

#if defined(WIN32) || defined(_WIN32)
virtual LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) = 0;
#endif
Expand Down

0 comments on commit 8ed4560

Please sign in to comment.