[DEV] Windows: windows is displayed but no event was grabbed
This commit is contained in:
parent
1e4472b33a
commit
8a8c2cc352
@ -50,59 +50,100 @@ class WindowsContext : public gale::Context {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int32_t run() {
|
int32_t run() {
|
||||||
HINSTANCE hInstance = 0;
|
HINSTANCE hInstance = GetModuleHandle(nullptr);
|
||||||
WNDCLASS wc;
|
|
||||||
HWND hWnd;
|
HWND hWnd;
|
||||||
HDC hDC;
|
HDC hDC;
|
||||||
HGLRC hRC;
|
HGLRC hRC;
|
||||||
MSG msg;
|
|
||||||
|
|
||||||
// register window class
|
// register a new windows class (need it to define external callback)
|
||||||
wc.style = CS_OWNDC;
|
WNDCLASSEX windowClass;
|
||||||
wc.lpfnWndProc = WndProc;
|
windowClass.cbSize = sizeof(WNDCLASSEX);
|
||||||
wc.cbClsExtra = 0;
|
windowClass.style = CS_HREDRAW | CS_VREDRAW;//CS_OWNDC;
|
||||||
wc.cbWndExtra = 0;
|
windowClass.lpfnWndProc = WndProc;
|
||||||
wc.hInstance = hInstance;
|
windowClass.cbClsExtra = 0;
|
||||||
wc.hIcon = LoadIcon( nullptr, IDI_APPLICATION );
|
windowClass.cbWndExtra = 0;
|
||||||
wc.hCursor = LoadCursor( nullptr, IDC_ARROW );
|
windowClass.hInstance = hInstance;
|
||||||
wc.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH );
|
windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
|
||||||
wc.lpszMenuName = nullptr;
|
windowClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
|
||||||
wc.lpszClassName = "GaleMainWindows";
|
windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||||
RegisterClass( &wc );
|
windowClass.hbrBackground = NULL; // (HBRUSH)GetStockObject(BLACK_BRUSH);
|
||||||
|
windowClass.lpszMenuName = NULL;
|
||||||
// create main window
|
windowClass.lpszClassName = "GaleMainWindows";
|
||||||
hWnd = CreateWindow( "GaleMainWindows", "Gale ... TODO Title",
|
//Register window class
|
||||||
WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE | WS_SIZEBOX,
|
if (!RegisterClassEx(&windowClass)) {
|
||||||
0, 0, 800, 600,
|
GALE_ERROR("Can not register windows class");
|
||||||
nullptr, nullptr, hInstance, nullptr);
|
MessageBox(hWnd, "Error creating window class\n(gale internal error #65231)", "Error", MB_ICONEXCLAMATION);
|
||||||
|
PostQuitMessage(0);
|
||||||
|
}
|
||||||
|
// Now we use the created windows class "GaleMainWindows" to create the wew windows with callback ... ==> use "STATIC" to not use generic callback ...
|
||||||
|
hWnd = CreateWindowEx(WS_EX_APPWINDOW, // The extended window style of the window being created.
|
||||||
|
"STATIC", // A null-terminated string or a class atom created by a previous call to the RegisterClass or RegisterClassEx function.
|
||||||
|
"Gale ... TODO Title", // The window name.
|
||||||
|
WS_CAPTION // Enable title bar
|
||||||
|
// | WS_DISABLED // Disable receive Windows event !! need to active EnableWindow
|
||||||
|
| WS_POPUPWINDOW // The window is a pop-up window
|
||||||
|
//| WS_POPUP // The windows is a pop-up window
|
||||||
|
//| WS_VISIBLE // Start in visible mode
|
||||||
|
//| WS_CLIPSIBLINGS //
|
||||||
|
//| WS_CLIPCHILDREN //
|
||||||
|
| WS_SIZEBOX //
|
||||||
|
, // The style of the window being created.
|
||||||
|
10, 10, // start position
|
||||||
|
800, 600, // start size
|
||||||
|
nullptr, // A handle to the parent or owner window of the window being created
|
||||||
|
nullptr, // A handle to a menu, or specifies a child-window identifier, depending on the window style
|
||||||
|
hInstance, // A handle to the instance of the module to be associated with the window.
|
||||||
|
nullptr //A pointer to a value to be passed to the window through the CREATESTRUCT structure
|
||||||
|
);
|
||||||
|
if(hWnd == nullptr) {
|
||||||
|
GALE_ERROR("Can not create windows");
|
||||||
|
MessageBox(hWnd, "Error creating window\n(gale internal error #45211)", "Error", MB_ICONEXCLAMATION);
|
||||||
|
PostQuitMessage(0);
|
||||||
|
}
|
||||||
int border_thickness = GetSystemMetrics(SM_CXSIZEFRAME);
|
int border_thickness = GetSystemMetrics(SM_CXSIZEFRAME);
|
||||||
int title_size = GetSystemMetrics(SM_CYCAPTION);
|
int title_size = GetSystemMetrics(SM_CYCAPTION);
|
||||||
m_currentHeight = 600-2*border_thickness -title_size;
|
m_currentHeight = 600-2*border_thickness -title_size;
|
||||||
OS_Resize(vec2(800-2*border_thickness, m_currentHeight));
|
OS_Resize(vec2(800-2*border_thickness, m_currentHeight));
|
||||||
|
|
||||||
// enable openGL for the window
|
// enable openGL for the window
|
||||||
enableOpenGL( hWnd, &hDC, &hRC );
|
enableOpenGL(hWnd, &hDC, &hRC);
|
||||||
|
GLenum err = glewInit();
|
||||||
|
if (GLEW_OK != err) {
|
||||||
|
// Problem: glewInit failed, something is seriously wrong.
|
||||||
|
GALE_CRITICAL("Error:" << glewGetErrorString(err));
|
||||||
|
MessageBox(hWnd, "Error initilizing open GL\n(gale internal error #8421)", "Error", MB_ICONEXCLAMATION);
|
||||||
|
PostQuitMessage(0);
|
||||||
|
}
|
||||||
|
if (!glewIsSupported("GL_VERSION_2_0")) {
|
||||||
|
GALE_ERROR("OpenGL 2.0 not available");
|
||||||
|
MessageBox(hWnd, "Error initilizing open GL\n OPENGL 2.0 not availlable ...\n(gale internal error #75124)", "Error", MB_ICONEXCLAMATION);
|
||||||
|
PostQuitMessage(0);
|
||||||
|
}
|
||||||
|
// Now we can show it ...
|
||||||
|
ShowWindow(hWnd, SW_SHOW);
|
||||||
|
//EnableWindow(hWnd, TRUE);
|
||||||
|
ShowCursor(TRUE);
|
||||||
|
MSG msg;
|
||||||
// program main loop
|
// program main loop
|
||||||
while(true == m_run) {
|
while(m_run == true) {
|
||||||
// check for messages
|
// check for messages
|
||||||
if ( PeekMessage( &msg, nullptr, 0, 0, PM_REMOVE )) {
|
if (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) {
|
||||||
// handle or dispatch messages
|
// handle or dispatch messages
|
||||||
if ( msg.message == WM_QUIT ) {
|
if (msg.message == WM_QUIT) {
|
||||||
m_run = false;
|
m_run = false;
|
||||||
} else {
|
} else {
|
||||||
TranslateMessage( &msg );
|
TranslateMessage(&msg);
|
||||||
DispatchMessage( &msg );
|
DispatchMessage(&msg);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
OS_Draw(true);
|
OS_Draw(true);
|
||||||
SwapBuffers( hDC );
|
SwapBuffers(hDC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// shutdown openGL
|
// shutdown openGL
|
||||||
disableOpenGL( hWnd, hDC, hRC );
|
disableOpenGL(hWnd, hDC, hRC);
|
||||||
// destroy the window explicitly
|
// destroy the window explicitly
|
||||||
DestroyWindow( hWnd );
|
DestroyWindow(hWnd);
|
||||||
return msg.wParam;
|
return msg.wParam;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,7 +173,7 @@ class WindowsContext : public gale::Context {
|
|||||||
OS_ClipBoardArrive(gale::context::clipBoard::clipboardSelection);
|
OS_ClipBoardArrive(gale::context::clipBoard::clipboardSelection);
|
||||||
break;
|
break;
|
||||||
case gale::context::clipBoard::clipboardStd:
|
case gale::context::clipBoard::clipboardStd:
|
||||||
if (false == m_clipBoardOwnerStd) {
|
if (m_clipBoardOwnerStd == false) {
|
||||||
// generate a request TO the OS
|
// generate a request TO the OS
|
||||||
// TODO : Send the message to the OS "We disire to receive the copy buffer ...
|
// TODO : Send the message to the OS "We disire to receive the copy buffer ...
|
||||||
} else {
|
} else {
|
||||||
@ -153,7 +194,7 @@ class WindowsContext : public gale::Context {
|
|||||||
break;
|
break;
|
||||||
case gale::context::clipBoard::clipboardStd:
|
case gale::context::clipBoard::clipboardStd:
|
||||||
// Request the clipBoard :
|
// Request the clipBoard :
|
||||||
if (false == m_clipBoardOwnerStd) {
|
if (m_clipBoardOwnerStd == false) {
|
||||||
// TODO : Inform the OS that we have the current buffer of copy ...
|
// TODO : Inform the OS that we have the current buffer of copy ...
|
||||||
m_clipBoardOwnerStd = true;
|
m_clipBoardOwnerStd = true;
|
||||||
}
|
}
|
||||||
@ -164,44 +205,44 @@ class WindowsContext : public gale::Context {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// enable openGL
|
// enable openGL
|
||||||
void enableOpenGL(HWND _hWnd, HDC* _hDC, HGLRC* _hRC) {
|
void enableOpenGL(HWND _hWnd, HDC* _hDC, HGLRC* _hRC) {
|
||||||
// get the device context (DC)
|
// get the device context (DC)
|
||||||
*_hDC = GetDC( _hWnd );
|
*_hDC = GetDC(_hWnd);
|
||||||
|
// Configure the color set ...
|
||||||
PIXELFORMATDESCRIPTOR pfd;
|
PIXELFORMATDESCRIPTOR pfd;
|
||||||
// set the pixel format for the DC
|
// set the pixel format for the DC
|
||||||
ZeroMemory(&pfd, sizeof( pfd ) );
|
ZeroMemory(&pfd, sizeof(PIXELFORMATDESCRIPTOR));
|
||||||
pfd.nSize = sizeof( pfd );
|
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
|
||||||
pfd.nVersion = 1;
|
pfd.nVersion = 1;
|
||||||
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
|
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
|
||||||
pfd.iPixelType = PFD_TYPE_RGBA;
|
pfd.iPixelType = PFD_TYPE_RGBA;
|
||||||
pfd.cColorBits = 24;
|
pfd.cColorBits = 32;
|
||||||
pfd.cDepthBits = 16;
|
pfd.cDepthBits = 16;
|
||||||
pfd.iLayerType = PFD_MAIN_PLANE;
|
pfd.iLayerType = PFD_MAIN_PLANE;
|
||||||
int format = ChoosePixelFormat( *_hDC, &pfd );
|
int format = ChoosePixelFormat(*_hDC, &pfd);
|
||||||
SetPixelFormat( *_hDC, format, &pfd );
|
SetPixelFormat(*_hDC, format, &pfd);
|
||||||
|
|
||||||
// create and enable the render context(RC)
|
// create and enable the render context(RC)
|
||||||
*_hRC = wglCreateContext( *_hDC );
|
*_hRC = wglCreateContext(*_hDC);
|
||||||
wglMakeCurrent( *_hDC, *_hRC );
|
wglMakeCurrent(*_hDC, *_hRC);
|
||||||
|
if (wglGetCurrentContext() == nullptr) {
|
||||||
|
GALE_ERROR("can not create OPEN gL context...");
|
||||||
|
MessageBox(_hWnd, "Error initilizing open GL\n openGL context creation error...\n(gale internal error #3526)", "Error", MB_ICONEXCLAMATION);
|
||||||
|
PostQuitMessage(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// disable openGL
|
// disable openGL (fisnish application ...
|
||||||
|
|
||||||
void disableOpenGL(HWND _hWnd, HDC _hDC, HGLRC _hRC) {
|
void disableOpenGL(HWND _hWnd, HDC _hDC, HGLRC _hRC) {
|
||||||
wglMakeCurrent( nullptr, NULL );
|
wglMakeCurrent(nullptr, nullptr);
|
||||||
wglDeleteContext( _hRC );
|
wglDeleteContext(_hRC);
|
||||||
ReleaseDC( _hWnd, _hDC );
|
ReleaseDC(_hWnd, _hDC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Window Procedure
|
// Window Procedure
|
||||||
static LRESULT CALLBACK WndProc(HWND _hWnd, UINT _message, WPARAM _wParam, LPARAM _lParam) {
|
static LRESULT CALLBACK WndProc(HWND _hWnd, UINT _message, WPARAM _wParam, LPARAM _lParam) {
|
||||||
// TODO : set this function really work...
|
// TODO : set this function really work...
|
||||||
|
GALE_ERROR("get event ...");
|
||||||
// TODO : return classPointer->WndProcReal(_hWnd, _message, _wParam, _lParam);
|
// TODO : return classPointer->WndProcReal(_hWnd, _message, _wParam, _lParam);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -497,15 +538,6 @@ class WindowsContext : public gale::Context {
|
|||||||
*/
|
*/
|
||||||
int gale::run(gale::Application* _application, int _argc, const char *_argv[]) {
|
int gale::run(gale::Application* _application, int _argc, const char *_argv[]) {
|
||||||
etk::init(_argc, _argv);
|
etk::init(_argc, _argv);
|
||||||
GLenum err = glewInit();
|
|
||||||
if (GLEW_OK != err) {
|
|
||||||
// Problem: glewInit failed, something is seriously wrong.
|
|
||||||
GALE_ERROR("Error:" << glewGetErrorString(err));
|
|
||||||
}
|
|
||||||
if (!glewIsSupported("GL_VERSION_2_0")) {
|
|
||||||
GALE_ERROR("OpenGL 2.0 not available");
|
|
||||||
//return 1;
|
|
||||||
}
|
|
||||||
WindowsContext* localInterface = new WindowsContext(_application, _argc, _argv);
|
WindowsContext* localInterface = new WindowsContext(_application, _argc, _argv);
|
||||||
if (localInterface == nullptr) {
|
if (localInterface == nullptr) {
|
||||||
GALE_CRITICAL("Can not create the 'Windows' interface ... MEMORY allocation error");
|
GALE_CRITICAL("Can not create the 'Windows' interface ... MEMORY allocation error");
|
||||||
|
@ -60,7 +60,7 @@ bool gale::resource::Shader::updateContext() {
|
|||||||
m_shader = -1;
|
m_shader = -1;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
GALE_INFO("Create Shader : '" << m_name << "'");
|
GALE_DEBUG("Create Shader : '" << m_name << "'");
|
||||||
m_shader = gale::openGL::shader::create(m_type);
|
m_shader = gale::openGL::shader::create(m_type);
|
||||||
if (m_shader < 0) {
|
if (m_shader < 0) {
|
||||||
GALE_CRITICAL(" can not load shader");
|
GALE_CRITICAL(" can not load shader");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user