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++ Widgets - General questions or Mixed problems » [GLCtrl] Adding an Initilisation function to GLPaint
[GLCtrl] Adding an Initilisation function to GLPaint [message #53115] Tue, 03 March 2020 11:32 Go to previous message
Xemuth is currently offline  Xemuth
Messages: 387
Registered: August 2018
Location: France
Senior Member
Hello community,

When we have to deal with OpenGL, it is often interesting to load a certain amount of data (Texture / Vertex / Shaders) before rendering a scene.

Nowaday, to load thoses things, I must declare a boolean in my derived class of GLCtrl and use it to perform many load at the first loop in GLPaint, as Follow :
	bool isLoaded = false;
	virtual void GLPaint() {
		if(!isLoaded){
			/* Loading Few things  ! */
			isLoaded=true;
		}
		
		/* Code to perform draw */
		Refresh();
	}


Even if this way of working is functional, Having to write many and many code and routine of loading in GLPaint() is annoying and don't help in code readability.

That's why I started to dig out the GLCtrl to implement a virtual function called Initialisation() wich can be overwritted. The purpose of it is to be called right after OpenGL context Initialisation. My first way of doing this was Adding the call of function here (GLCtrl.cpp line 33):
void GLCtrl::Init()
{
	Transparent();
#ifdef PLATFORM_WIN32
	pane.ctrl = this;
	Add(pane.SizePos());
#endif
	restore_gl_viewport__ = SetCurrentViewport;
	Initialisation(); //--> I call Initialisation Here 
}

But (It seems) due to Ctrl creation, the function wich is called at this moment is the non overwritted Initialisation() from GLCtrl and not the one I have overwritted in my derived class from GLCtrl.

So my next try was to implement it here (Win32GLCtrl.cpp) :
void GLCtrl::GLPane::State(int reason)
{
	DHCtrl::State(reason);
	
	if(reason == OPEN) {
		HWND hwnd = GetHWND();
		CreateContext();
		HDC hDC = GetDC(hwnd);
		if(!SetPixelFormat(hDC, s_pixelFormatID, &s_pfd))
			return;
		ReleaseDC(hwnd, hDC);
		static_cast<GLCtrl*>(parent)->Initialisation();//--> I call Initialisation Here
	}
}

This time, it call the overwritted Initialisation() but OpenGL Context is not yet well initialised, consequence is every call to OpenGL api (all call to allocate some memory in vram) fail !

So far I dig, I didn't find the proper way of adding this function, so I need your help ! If someone have an idea...

Thanks in advance.
Best regard

Xemuth

[Updated on: Wed, 04 March 2020 08:40]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: [SOLVED]Removing glaux lib from GLctrl
Next Topic: How to draw random images in ArrayCtrl-cell using Display? [SOLVED]
Goto Forum:
  


Current Time: Sat Apr 20 04:24:25 CEST 2024

Total time taken to generate the page: 0.02820 seconds