Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Library : Other (not classified elsewhere) » [Proposal] Adding a GLLock struct to GLCtrl
[Proposal] Adding a GLLock struct to GLCtrl [message #54712] Wed, 02 September 2020 18:55 Go to previous message
Xemuth is currently offline  Xemuth
Messages: 387
Registered: August 2018
Location: France
Senior Member
Hello, with the new version of Glew I moved my application to GLCtrl.
However, in many part of my application, I need to get the OpenGL context to perform many actions. The actual way of executing something in the good OpenGL Context is to call ExecuteGL(Event<> paint, bool swap_buffers). Which force me to surround my code arround this function. It work but not convenient and for some part it block me and force me to change my architecture.

To allow more flexibility in the way we work with GLCtrl I propose to add a structure to GLCtrl named GLLock, which can be invoqued to get the OpenGL context and release it when the object got destroyed :

//class GLCtrl : public Ctrl{
     public:
	struct GLLock{
		private:
			HWND hwnd;
			HDC hDC;
		public:
			GLLock(GLCtrl& ctrl);
			~GLLock();
	};
//};


Win32GLCtrl.cpp :
GLCtrl::GLLock::GLLock(GLCtrl& ctrl){
	hwnd = ctrl.pane.GetHWND();
	GLCtrl::CreateContext();
	hDC = GetDC(hwnd);
	wglMakeCurrent(hDC, s_openGLContext);
}

GLCtrl::GLLock::~GLLock(){
	wglMakeCurrent(NULL, NULL);
	ReleaseDC(hwnd, hDC);
}

XGLCtrl.cpp:
GLCtrl::GLLock::GLLock(GLCtrl& ctrl){
	glXMakeCurrent(s_Display, ctrl.win, s_GLXContext);
}

GLCtrl::GLLock::~GLLock(){
	glXMakeCurrent(s_Display, None, NULL);
}


Here is a trivial exemple of how to use it :
	bool LoadSTL(){ //This function is used when a button is pressed
		try {
			GLCtrl::GLLock __(canvas); //Canvas is the GLCtrl object
			//Shaders Stuff
			//OpenGL buffer filling and loading 
			//Definition of draw
			return true;
		} catch (Exc e) {
			Exclamation(DeQtf(e));
		}
		return false;
	}




 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Changing default standard from c++14 to c++17 (2020.2 Release)
Next Topic: RegExp
Goto Forum:
  


Current Time: Thu Mar 28 23:21:16 CET 2024

Total time taken to generate the page: 0.01290 seconds