GLTestWnd.cpp
Go to the documentation of this file.
00001 
00002 //      File:           GLTestWnd.cpp
00003 //      Author:         Changchang Wu
00004 //      Description : implementation of the GLTestWnd class.
00005 //
00006 //
00007 //
00008 //      Copyright (c) 2007 University of North Carolina at Chapel Hill
00009 //      All Rights Reserved
00010 //
00011 //      Permission to use, copy, modify and distribute this software and its
00012 //      documentation for educational, research and non-profit purposes, without
00013 //      fee, and without a written agreement is hereby granted, provided that the
00014 //      above copyright notice and the following paragraph appear in all copies.
00015 //      
00016 //      The University of North Carolina at Chapel Hill make no representations
00017 //      about the suitability of this software for any purpose. It is provided
00018 //      'as is' without express or implied warranty. 
00019 //
00020 //      Please send BUG REPORTS to ccwu@cs.unc.edu
00021 //
00023 
00024 
00025 #define WIN32_LEAN_AND_MEAN
00026 
00027 #include <windows.h>
00028 #include <windowsx.h>
00029 #include "GL/gl.h"
00030 #include <stdlib.h>
00031 
00033 #include "BasicTestWin.h"
00034 #include "GLTestWnd.h"
00035 
00036 #ifdef _WINDOWS
00037 int APIENTRY WinMain(HINSTANCE hInstance,   HINSTANCE hPrevInstance,
00038                      LPSTR     lpCmdLine,   int       nCmdShow)
00039 {
00041         //create a window
00042         GLTestWnd win(lpCmdLine);
00043 #else
00044 int main(int argc, char** argv)
00045 {
00046     GLTestWnd win(argc, argv);
00047 #endif
00048 
00050     MSG msg;    //
00051         while (GetMessage(&msg, NULL, 0, 0)) 
00052         {
00053                 TranslateMessage(&msg);
00054                 DispatchMessage(&msg);  
00055         //on idle
00056                 if(PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE)==0)SendMessage(GetActiveWindow(), WM_MY_IDLE, 0, 0);
00057         }
00058         return (int) msg.wParam;
00059 }
00060 
00062 // Construction/Destruction
00064 
00065 
00066 GLTestWnd::GLTestWnd(LPSTR cmd)
00067 {
00069         //Parse Command Line
00070         if(cmd) ParseCommandLine(cmd);
00071 
00073         //create the window
00074     CreateWindowGL();
00075 }
00076 
00077 GLTestWnd::GLTestWnd(int argc, char**argv)
00078 {
00079         BasicTestWin::ParseSiftParam(argc, argv);
00080     CreateWindowGL();
00081 }
00082 
00083 GLTestWnd::~GLTestWnd()
00084 {
00085 
00086 }
00087 
00088 void GLTestWnd::CreateWindowGL()
00089 {
00090         _hWndMain = NULL;
00091     RegisterWindowClass();
00092         HWND hWnd = CreateWindow("SIFT_GPU_WND", "SIFT_GPU", 
00093                 WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN,
00094                 CW_USEDEFAULT,  CW_USEDEFAULT, 
00095                 600, 450,       NULL, NULL,  NULL,      this);
00096         ShowWindow(hWnd,  SW_SHOW);
00097         UpdateWindow(hWnd);
00098 
00099 }
00100 LRESULT CALLBACK GLTestWnd::___WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
00101 {
00102         static int nWnd=0;
00103         GLTestWnd *pWnd;
00104         if(message==WM_CREATE)
00105         {
00106         LPCREATESTRUCT cs = (LPCREATESTRUCT)lParam;
00107                 pWnd = (GLTestWnd*)cs->lpCreateParams;
00108                 pWnd->_hWndMain = hWnd;
00109                 SetWindowLong(hWnd,0,(long)(pWnd));
00110                 nWnd++;
00111 
00112         }else if(message== WM_DESTROY)
00113         {
00114                 pWnd=(GLTestWnd*)GetWindowLong(hWnd,0);
00115                 delete pWnd;
00116                 SetWindowLong(hWnd,0,0);
00117                 nWnd--;
00118                 if(nWnd==0)
00119                         PostQuitMessage(0);
00120                 pWnd = NULL;
00121         }else
00122         {
00123                 pWnd=(GLTestWnd*)GetWindowLong(hWnd,0);
00124         }
00125         if(pWnd)
00126                 return pWnd->_WndProc(message,wParam,lParam);
00127         else
00128                 return DefWindowProc(hWnd, message, wParam, lParam);
00129         
00130 }
00131 
00132 void GLTestWnd::RegisterWindowClass()
00133 {
00134     static int registered = 0;
00135     if(registered) return;
00136         WNDCLASSEX wcex;
00137         wcex.cbSize                     = sizeof(WNDCLASSEX); 
00138         wcex.style                      = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
00139         wcex.lpfnWndProc        = (WNDPROC)___WndProc;
00140         wcex.cbClsExtra         = 0;
00141         wcex.cbWndExtra         = 4;
00142         wcex.hInstance          = 0;
00143         wcex.hIcon                      = NULL;
00144         wcex.hCursor            = LoadCursor(NULL, IDC_ARROW);
00145         wcex.hbrBackground      = (HBRUSH)(COLOR_WINDOW+1);
00146         wcex.lpszMenuName       = NULL;;
00147         wcex.lpszClassName      = "SIFT_GPU_WND";
00148         wcex.hIconSm            = NULL;
00149         RegisterClassEx(&wcex);
00150         registered = 1;
00151 }
00152 
00153 
00154 LRESULT GLTestWnd::_WndProc(UINT message, WPARAM wParam, LPARAM lParam)
00155 {
00156 
00157 
00158         switch (message) 
00159         {
00160                 case WM_CREATE:
00161                         {
00162                 if(_win_x !=-1)
00163                 {
00164                     LPCREATESTRUCT cs = (LPCREATESTRUCT)lParam;
00165                     MoveWindow(_hWndMain, _win_x, _win_y, cs->cx, cs->cy, 0);
00166                 }
00167                                 SetDisplaySize(600, 450);
00168                                 HDC hdc =       GetDC(_hWndMain);
00169                                 glCreateRC(hdc);
00170                                 if(_hglrc == NULL) exit(0);
00171                                 ReleaseDC(_hWndMain,hdc);
00172 
00173                         }
00174                         break;
00175                 case WM_SIZE:
00176                         {
00177                                 glResize(LOWORD(lParam),HIWORD(lParam));
00178                         }
00179                         break;
00180                 case WM_PAINT:
00181                         {
00182                                 PAINTSTRUCT ps;
00183                                 HDC hdc = BeginPaint(_hWndMain, &ps);
00185                                 glPaint(hdc);
00187                                 EndPaint(_hWndMain, &ps);
00188                         }
00189                         break;
00190                 case WM_CHAR:
00191                         KeyInput((int) wParam);
00192                         InvalidateRect(_hWndMain, NULL, FALSE);
00193                         break;
00194                 case WM_LBUTTONDOWN:
00195                         {
00196                                 int xPos = GET_X_LPARAM(lParam); 
00197                                 int yPos = GET_Y_LPARAM(lParam); 
00198                                 StartMotion(xPos, yPos);
00199                         }
00200                         break;
00201                 case WM_LBUTTONUP:
00202                         EndMotion();
00203                         break;
00204                 case WM_MOUSEMOVE:
00205                         if( wParam & MK_LBUTTON)
00206                         {
00207                                 int xPos = GET_X_LPARAM(lParam); 
00208                                 int yPos = GET_Y_LPARAM(lParam); 
00209                                 MoveMouse(xPos, yPos);
00210                         }
00211                 case WM_ERASEBKGND:
00212                         return TRUE;
00213                 case WM_MY_IDLE:
00214                         OnIdle();
00215                         return TRUE;
00216                 case WM_DESTROY:
00217                         PostQuitMessage(0);
00218                         break;
00219                 default:
00220                         return DefWindowProc(_hWndMain, message, wParam, lParam);
00221         }
00222         return 0;
00223 }
00224 void GLTestWnd::glCreateRC(HDC hdc)
00225 {
00226     int pixelformat;
00227         PIXELFORMATDESCRIPTOR pfd = 
00228         {
00229         sizeof(PIXELFORMATDESCRIPTOR),1,                             
00230         PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER,               
00231         PFD_TYPE_RGBA,24,0, 0, 0, 0, 0, 0,0,0,0,0, 0, 0, 0,16,0,0,                          
00232         PFD_MAIN_PLANE,0,0, 0, 0                     
00233     };
00234     if ((pixelformat = ChoosePixelFormat(hdc, &pfd)) ==0)return ;
00235     if (SetPixelFormat(hdc, pixelformat, &pfd) == FALSE)return ;
00236         pixelformat =::GetPixelFormat(hdc);
00237         ::DescribePixelFormat(hdc, pixelformat, sizeof(pfd), &pfd);
00238 
00239         //
00240     _hglrc = wglCreateContext(hdc);
00241         wglMakeCurrent(hdc, _hglrc);
00242 
00243         glMatrixMode(GL_MODELVIEW);
00244         glLoadIdentity();
00245 
00246         RunSiftGPU();
00247 
00248         wglMakeCurrent(NULL, NULL);
00249  
00250 }
00251 
00252 void GLTestWnd::glResize(int w, int h)
00253 {
00254         ReShape(w, h);
00255 }
00256 
00257 void GLTestWnd::glPaint(HDC hdc)
00258 {
00259         wglMakeCurrent(hdc,HGLRC(_hglrc));
00260         Display();
00261         SwapBuffers(hdc);
00262 }
00263 
00264 void GLTestWnd::ParseCommandLine(LPSTR cmd)
00265 {
00266         int argc=0;
00267         char**argv = new char*[256];
00268         if(*cmd == 0) return;
00269         do
00270         {
00271                 while(*cmd ==' ') cmd++;
00272                 if(*cmd)
00273                 {
00274                         argv[argc++] = cmd;
00275                 }
00276                 while(*cmd && *cmd != ' ') cmd++;
00277                 if(*cmd==' ')   *cmd++ = 0;
00278 
00279         }while(*cmd && argc <256);
00280         BasicTestWin::ParseSiftParam(argc, argv);
00281 }
00282 
00283 void GLTestWnd::SetDisplaySize(int w, int h)
00284 {
00285         RECT rc;        int dw,  dh;
00286         GetClientRect(_hWndMain, &rc);
00287 
00288         dw = w - rc.right;
00289         dh = h - rc.bottom;
00290         GetWindowRect(_hWndMain, &rc);
00291         
00292         MoveWindow(_hWndMain, rc.left, rc.top, rc.right - rc.left + dw,
00293                 rc.bottom - rc.top + dh, TRUE);
00294 
00295 }
00296 
00297 void GLTestWnd::SetWindowTitle(char *title)
00298 {
00299         SetWindowText(_hWndMain, title);
00300 }
00301 
00302 void GLTestWnd::UpdateDisplay()
00303 {
00304         InvalidateRect(_hWndMain, NULL,0);
00305 }
00306 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


rgbd_registration
Author(s): Ross Kidson
autogenerated on Sun Oct 6 2013 12:00:39