Re: [Plib-users] R: Problem with a PUI-Win32-Native
Brought to you by:
sjbaker
From: <pos...@ca...> - 2008-02-29 14:54:10
|
> I'm not a PUI user so I don't know if this could be useful, yet in your code > I reported below: > > case WM_LBUTTONDOWN: > oldMousePos.x = currentMousePos.x = LOWORD (lParam); > oldMousePos.y = currentMousePos.y = HIWORD (lParam); > if( puMouse ( 1, PU_DOWN, currentMousePos.x, > currentMousePos.y )) > ==>> //{ }//MessageBox(NULL,"DOWN","down",MB_OK); } > isMouseActive = true; > > Looking at the pointed line, are you sure you want to set isMouseActive = > true when the call to puMouse returns 1? This is what actually happens since > the subject line is commented out. Which is different, I see, from the > similar code line for the button up case. > > Paolo > Thanks. You are right. The line was twice commented. However this boolean controled only the activation of the later drawn triangle manipulator. I discarded the calls to the gl drawings and manipulation in the following code (below), keeping only PUI renderings. The problem remains : the PUI display correcly, yet no callbacks. I'm wondering about this warning in the documentation : "[...] #define PU_USE_NATIVE before you include pu.h - and PUI will try to figure out what it needs to know using native commands such as those in the wgl/glX/agl library - in the absence of a windowing library. This may result in "some problems" if you want to do "certain operations" for which PUI needs to query the windowing library. Use of PU_USE_NATIVE is not recommended in systems that allow you to resize the window or open multiple windows." /* a problem with a pui win32 native application */ #pragma comment ( lib, "fnt.lib" ) #pragma comment ( lib, "pui.lib" ) #pragma comment ( lib, "sg.lib" ) #pragma comment ( lib, "ul.lib" ) #define PU_USE_NATIVE #include <plib/pu.h> #include<windows.h> #include<gl/gl.h> #include<gl/glu.h> void Render(); bool InitializeGL(); HDC g_HDC; int gWidth = 0; int gHeight = 0; void button_cb (puObject *) {MessageBox(NULL,"ok","ok",MB_OK);} void foo_cb (puObject *) {MessageBox(NULL,"foo","foo",MB_OK);} void bar_cb (puObject *) {MessageBox(NULL,"bar","bar",MB_OK);} void exit_cb (puObject *) {exit(0);} char *file_submenu [] = { "Exit","foo","bar", NULL } ; puCallback file_submenu_cb[] = { exit_cb, foo_cb, bar_cb, NULL } ; char * PUIlabels[5] = { "Label1", "Label2", "This is Label3", "Four", NULL } ; puMenuBar * menu; puOneShot *b; puButtonBox * checkList; void SetupPixelFormat(HDC hDC) { int nPixelFormat; static PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), // size of structure. 1, // always 1. PFD_DRAW_TO_WINDOW | // support window PFD_SUPPORT_OPENGL | // support OpenGl PFD_DOUBLEBUFFER, // support double buffering PFD_TYPE_RGBA, // support RGBA 16, // bit color mode 0, 0, 0, 0, 0, 0, // ignore color bits 0, // no alpha buffer 0, // ignore shift bit 0, // no accumulation buffer 0, 0, 0, 0, // ignore accumulation bits. 16, // number of depth buffer bits. 0, // number of stencil buffer bits. 0, // 0 means no auxiliary buffer PFD_MAIN_PLANE, // The main drawing plane 0, // this is reserved 0, 0, 0 }; // layer masks ignored. // this chooses the best pixel format and returns index. nPixelFormat = ChoosePixelFormat(hDC, &pfd); // This set pixel format to device context. SetPixelFormat(hDC, nPixelFormat, &pfd); } LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static HGLRC hRC; // Rendering context. static HDC hDC; // Device context. int width, height; // The window width and height. static POINT oldMousePos; // Last mouse position. static POINT currentMousePos; // Current mouse position. static bool isMouseActive; // Is the left mouse button down. switch(message) { case WM_CREATE: // Windows creation. hDC = GetDC(hwnd); // This gets the device context for our window. g_HDC = hDC; // Assigns the global device context to this one. SetupPixelFormat(hDC); // Call the pixel format function. hRC = wglCreateContext(hDC); // Creates the rendering context. wglMakeCurrent(hDC, hRC); // Makes the rendering context. return 0; break; case WM_CLOSE: // Close message. case WM_DESTROY: wglMakeCurrent(hDC, NULL); wglDeleteContext(hRC); // Deletes the rendering context. PostQuitMessage(0); // Says close the program. return 0; break; case WM_SIZE: // re-size message. height = HIWORD(lParam); // This gets the height of the window. width = LOWORD(lParam); // This gets the width of the window. if(height == 0) // we don't want it to be possible for a { // height of 0. If it is 0 me make it 1. height = 1; } gHeight = height; gWidth = width; puSetWindowSize ( width, height ) ; glViewport(0, 0, width, height);// resets the viewport to new dimensions. glMatrixMode(GL_PROJECTION); // Sets the projection matrix. glLoadIdentity(); // Reset the modelview matrix. // calculate the aspect ratio of the window. gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, 0.1f, 1000.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); return 0; break; case WM_KEYDOWN: switch(wParam) { case VK_ESCAPE: PostQuitMessage(0); break; } break; case WM_LBUTTONDOWN: oldMousePos.x = currentMousePos.x = LOWORD (lParam); oldMousePos.y = currentMousePos.y = HIWORD (lParam); if( puMouse ( 1, PU_DOWN, currentMousePos.x, currentMousePos.y )) { }//MessageBox(NULL,"DOWN","down",MB_OK); } break; case WM_LBUTTONUP: currentMousePos.x = LOWORD (lParam); currentMousePos.y = HIWORD (lParam); if( puMouse ( 1, PU_UP, currentMousePos.x, currentMousePos.y )) {}// MessageBox(NULL,"UP","UP",MB_OK); } break; case WM_MOUSEMOVE: currentMousePos.x = LOWORD (lParam); currentMousePos.y = HIWORD (lParam); oldMousePos.x = currentMousePos.x; oldMousePos.y = currentMousePos.y; puMouse(currentMousePos.x,currentMousePos.y); break; default: break; } // What this does is pass all of the unhandled messages to DefWindowProc return (DefWindowProc(hwnd, message, wParam, lParam)); } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { MSG msg; // A message variable. WNDCLASSEX windowClass; // Your Window class. HWND hwnd; // The Window handle. bool isFinished; // True then exit. windowClass.cbSize = sizeof(WNDCLASSEX); // size of the WNDCLASSEX structure. windowClass.style = CS_HREDRAW | CS_VREDRAW; // style of the window. windowClass.lpfnWndProc = WndProc; // Address to the windows procedure. windowClass.cbClsExtra = 0; // Extra class information. windowClass.cbWndExtra = 0; // Extra window information. windowClass.hInstance = hInstance; // Handle of application Instance. windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);// Handle of application Icon. windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);// mouse cursor windowClass.hbrBackground = NULL; // background color. windowClass.lpszMenuName = NULL; // name of the main menu. windowClass.lpszClassName = "puitest";// window class name. windowClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);// icon when minimized. if(!RegisterClassEx(&windowClass)) return 0; // Create the window. hwnd = CreateWindowEx(NULL,// The extended window style. "puitest",// window Class name. "a problem",// window name. WS_OVERLAPPEDWINDOW | WS_VISIBLE |// The window style. WS_SYSMENU | WS_CLIPCHILDREN |// window style. WS_CLIPSIBLINGS,// window style. 100, 100,// window x, y coordinate. 640, 480,// window width and height. NULL,// handle to parent window. NULL,// menu. hInstance,// handle to app instance. NULL); // pointer to window creation data. if(!hwnd) return 0; ShowWindow(hwnd, SW_SHOW); UpdateWindow(hwnd); isFinished = false; if(!InitializeGL()) isFinished = true; while(!isFinished) { if(PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE)) { if(msg.message == WM_QUIT) { isFinished = true; } TranslateMessage(&msg); DispatchMessage(&msg); } else Render(); } return (int)msg.wParam; } bool InitializeGL() { puInit (); menu = new puMenuBar(-1); menu->add_submenu ( "File", file_submenu, file_submenu_cb ) ; menu->close(); b = new puOneShot ( 0, 0, "say hello") ; b -> setCallback ( button_cb ) ; checkList = new puButtonBox ( 50, 50, 200, 200, PUIlabels, 0 ) ; glClearColor(0.6f, 0.6f, 0.8f, 0.0f); // Clear the screen to black. glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); return true; } void Render() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); puDisplay (); SwapBuffers(g_HDC); } |