|
||||||||||||||||||
Add Forum to Favorites | Send Topic To a Friend | View Forum FAQ | Track this topic |
Last Thread Next Thread ![]() |
| Hosting a C D3D engine in C# Winforms |
|
![]() yrend Member since: 1/18/2002 From: Taiwan |
||||
|
|
||||
| hi how to add D3DWrap.dll to C# project? thinks |
||||
|
||||
![]() Ender1618 Member since: 4/30/2004 From: USA |
||||
|
|
||||
| Just right-click on the the solutions reference folder and add the dll (its a C++/CLI dll, so that makes sense). |
||||
|
||||
![]() billy_zelsnack Member since: 8/5/2003 From: Madison, WI, United States |
||||
|
|
||||
| You don't have to use HwndHost for D3D in WPF anymore. As of .NET 3.5 SP1 you can render with D3D in your WPF app without airspace issues. http://channel9.msdn.com/posts/AdamKinney/WPF-35-SP1-Graphics-with-David-Teitlebaum/ (Skip ahead to minute 6 for the demos.) |
||||
|
||||
![]() yrend Member since: 1/18/2002 From: Taiwan |
||||
|
|
||||
| hi thanks reply my find a question when add D3DWrap.dll to C# project follow picture from sample code debug configuration http://img168.imageshack.us/img168/7633/debugwp0.jpg release configuration http://img384.imageshack.us/img384/1940/releaseaq1.jpg auto switch path when my change configuration follow picture is my situation when add D3DWrap.dll to C# project (open solutions explorer -> c# project -> right click on References -> Add Reference -> Browse tab -> choose debug version D3DWrap.dll) http://img384.imageshack.us/img384/2678/debugerrorqf9.jpg can't auto switch path when my change configuration why ? thanks anything reply |
||||
|
||||
![]() simonloach Member since: 4/4/2006 From: Manchester, United Kingdom |
||||
|
|
||||
| I'm very new to C# (today in fact) and I'm thinking about making a level editor gui using it. I'd like to know if there's any chance of using this code with linux and mono or if there are there any guidelines I should follow when trying to make C# portable? |
||||
|
||||
![]() Scet GDNet+ Member since: 8/3/2002 From: Mississauga, Canada |
||||
|
|
||||
Quote: Pretty much the same guidelines as any other language, which is to avoid using operating system specific functions and non-portable APIs. This article uses Direct3D and a lot of Windows API code, so it isn't portable at all. Most major engines have been ported to C# though and I'm sure some of them use OpenGL/SDL and will work with Mono. |
||||
|
||||
![]() simonloach Member since: 4/4/2006 From: Manchester, United Kingdom |
||||
|
|
||||
Quote: Thanks thats good to know. |
||||
|
||||
![]() Timkin Member since: 4/29/2001 From: Melbourne, Australia |
||||
|
|
||||
| Two questions for the author: 1) I'm curious as to what degree, if any, rendering performance is hindered by this approach (as opposed to the original MFC application they developed). 2) Is there any specific reason why you linked against the .lib stub for the dll, rather than dynamic loading? It would be preferable to not require recompilation of the GUI application every time the dll was modified and recompiled. |
||||
|
||||
![]() Ender1618 Member since: 4/30/2004 From: USA |
||||
|
|
||||
Quote: 1) I am sure there is some performance hit, but I haven't noticed any. 2) No particular reason, this is just the method I typically use, dynamically loading the Win32 DLL would work as well. |
||||
|
||||
![]() AverageJoeSSU Member since: 6/30/2007 From: Santa Clara, CA, United States |
||||
|
|
||||
| Hello, Thanks a bunch for this article. I am working on a heavy engine and am going to be making an editor for it soon with c# and this lays it all out. I am using it with OpenGL and might look into doing a WPF app. Anyways, i'm excited to take a break from polygons and shaders and get going on some app development. Thanks Again. |
||||
|
||||
![]() AverageJoeSSU Member since: 6/30/2007 From: Santa Clara, CA, United States |
||||
|
|
||||
| So it has been a while, but i finally managed getting around to this tutorial. Couple of things... I am doing this in OpenGL and my initialize code is similar to "creating a window" nehe tutorial, except... I leave the hwnd as an argument and create everything else needed. here is my initialize code. EDIT: Here is the new code with some updates. still same result though. HRESULT EngineManager::Initialize(HWND inhWnd, _TCHAR * title, BOOL bRenderOnPaint, BOOL bHookWnd, int bits, bool fullscreenflag) { m_hDevWindow = inhWnd; cout << "Initialize:: "<< (int)m_hDevWindow << endl; GLuint PixelFormat; // Holds The Results After Searching For A Match // WNDCLASS wc; // Windows Class Structure DWORD dwExStyle; // Window Extended Style DWORD dwStyle; // Window Style RECT WindowRect; // Grabs Rectangle Upper Left / Lower Right Values WindowRect.left=(long)0; // Set Left Value To 0 WindowRect.right=(long)Lwidth; // Set Right Value To Requested Width WindowRect.top=(long)0; // Set Top Value To 0 WindowRect.bottom=(long)Lheight; // Set Bottom Value To Requested Height GetClientRect(m_hDevWindow,&WindowRect); Lwidth = WindowRect.right - WindowRect.left; Lheight = WindowRect.bottom - WindowRect.top; fullscreen=fullscreenflag; // Set The Global Fullscreen Flag m_hInstance = GetModuleHandle(NULL); // Grab An Instance For Our Window if(bHookWnd) hookWindow(m_hDevWindow); // Set Up Our Perspective GL Screen //wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw On Size, And Own DC For Window. //wc.lpfnWndProc = (WNDPROC) EngineManager::RenderWndProc; // WndProc Handles Messages //wc.cbClsExtra = 0; // No Extra Window Data //wc.cbWndExtra = 0; // No Extra Window Data //wc.hInstance = m_hInstance; // Set The Instance //wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); // Load The Default Icon //wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load The Arrow Pointer //wc.hbrBackground = NULL; // No Background Required For GL //wc.lpszMenuName = NULL; // We Don't Want A Menu //wc.lpszClassName = _T("OpenGL"); // Set The Class Name //if (!RegisterClass(&wc)) // Attempt To Register The Window Class //{ // MessageBox(NULL,_T("Failed To Register The Window Class."),_T("ERROR"),MB_OK|MB_ICONEXCLAMATION); // return FALSE; // Return FALSE //} //if (fullscreen) // Attempt Fullscreen Mode? //{ // DEVMODE dmScreenSettings; // Device Mode // memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); // Makes Sure Memory's Cleared // dmScreenSettings.dmSize=sizeof(dmScreenSettings); // Size Of The Devmode Structure // dmScreenSettings.dmPelsWidth = Lwidth; // Selected Screen Width // dmScreenSettings.dmPelsHeight = Lheight; // Selected Screen Height // dmScreenSettings.dmBitsPerPel = bits; // Selected Bits Per Pixel // dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT; // // Try To Set Selected Mode And Get Results. NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar. // if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL) // { // // If The Mode Fails, Offer Two Options. Quit Or Use Windowed Mode. // if (MessageBox(NULL,_T("The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?"),_T("NeHe GL"),MB_YESNO|MB_ICONEXCLAMATION)==IDYES) // { // fullscreen=FALSE; // Windowed Mode Selected. Fullscreen = FALSE // } // else // { // // Pop Up A Message Box Letting User Know The Program Is Closing. // MessageBox(NULL,_T("Program Will Now Close."),_T("ERROR"),MB_OK|MB_ICONSTOP); // return FALSE; // Return FALSE // } // } //} //if (fullscreen) // Are We Still In Fullscreen Mode? //{ // dwExStyle=WS_EX_APPWINDOW; // Window Extended Style // dwStyle=WS_POPUP; // Windows Style // ShowCursor(FALSE); // Hide Mouse Pointer //} //else //{ dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window Extended Style dwStyle=WS_OVERLAPPEDWINDOW; // Windows Style //} AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); // Adjust Window To True Requested Size //// Create The Window //if (!(hWnd=CreateWindowEx( dwExStyle, // Extended Style For The Window // _T("OpenGL"), // Class Name // title, // Window Title // dwStyle | // Defined Window Style // WS_CLIPSIBLINGS | // Required Window Style // WS_CLIPCHILDREN, // Required Window Style // 0, 0, // Window Position // WindowRect.right-WindowRect.left, // Calculate Window Width // WindowRect.bottom-WindowRect.top, // Calculate Window Height // NULL, // No Parent Window // NULL, // No Menu // hInstance, // Instance // NULL))) // Dont Pass Anything To WM_CREATE //{ // Shutdown(); // Reset The Display // MessageBox(NULL,_T("Window Creation Error."),_T("ERROR"),MB_OK|MB_ICONEXCLAMATION); // return FALSE; // Return FALSE //} static PIXELFORMATDESCRIPTOR pfd= // pfd Tells Windows How We Want Things To Be { sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor 1, // Version Number PFD_DRAW_TO_WINDOW | // Format Must Support Window PFD_SUPPORT_OPENGL | // Format Must Support OpenGL PFD_DOUBLEBUFFER, // Must Support Double Buffering PFD_TYPE_RGBA, // Request An RGBA Format bits, // Select Our Color Depth 0, 0, 0, 0, 0, 0, // Color Bits Ignored 0, // No Alpha Buffer 0, // Shift Bit Ignored 0, // No Accumulation Buffer 0, 0, 0, 0, // Accumulation Bits Ignored 32, // 16Bit Z-Buffer (Depth Buffer) 0, // No Stencil Buffer 0, // No Auxiliary Buffer PFD_MAIN_PLANE, // Main Drawing Layer 0, // Reserved 0, 0, 0 // Layer Masks Ignored }; if (!(hDC=GetDC(m_hDevWindow))) // Did We Get A Device Context? { this->Shutdown(); // Reset The Display MessageBox(NULL,_T("Can't Create A GL Device Context."),_T("ERROR"),MB_OK|MB_ICONEXCLAMATION); return FALSE; // Return FALSE } if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd))) // Did Windows Find A Matching Pixel Format? { this->Shutdown(); // Reset The Display MessageBox(NULL,_T("Can't Find A Suitable PixelFormat."),_T("ERROR"),MB_OK|MB_ICONEXCLAMATION); return FALSE; // Return FALSE } if(!SetPixelFormat(hDC,PixelFormat,&pfd)) // Are We Able To Set The Pixel Format? { this->Shutdown(); // Reset The Display MessageBox(NULL,_T("Can't Set The PixelFormat."),_T("ERROR"),MB_OK|MB_ICONEXCLAMATION); return FALSE; // Return FALSE } if (!(hRC=wglCreateContext(hDC))) // Are We Able To Get A Rendering Context? { this->Shutdown(); // Reset The Display MessageBox(NULL,_T("Can't Create A GL Rendering Context."),_T("ERROR"),MB_OK|MB_ICONEXCLAMATION); return FALSE; // Return FALSE } if(!wglMakeCurrent(hDC,hRC)) // Try To Activate The Rendering Context { this->Shutdown(); // Reset The Display MessageBox(NULL,_T("Can't Activate The GL Rendering Context."),_T("ERROR"),MB_OK|MB_ICONEXCLAMATION); return FALSE; // Return FALSE } ShowWindow(m_hDevWindow,SW_SHOW); // Show The Window SetForegroundWindow(m_hDevWindow); // Slightly Higher Priority SetFocus(m_hDevWindow); // Sets Keyboard Focus To The Window this->Resize(); if (!this->OnInit()) // Initialize Our Newly Created GL Window { Shutdown(); // Reset The Display MessageBox(NULL,_T("Initialization Failed."),_T("ERROR"),MB_OK|MB_ICONEXCLAMATION); return FALSE; // Return FALSE } return TRUE; // Success } The result is that i get a grey panel, and the engine runs (as in calls render and update but doesnt show in the panel... its grey). I can tell the engine initializes because of my couts.... which show up in the Output console for Visual Studio. [Edited by - AverageJoeSSU on April 7, 2009 1:40:33 AM] |
||||
|
||||
![]() AverageJoeSSU Member since: 6/30/2007 From: Santa Clara, CA, United States |
||||
|
|
||||
| HAHA got it! complete with not too much trouble at all! very nice article.... turned out that my main.cpp was doing swapbuffers(hdc) and when i turned my engine into a DLL... i missed that line of code. So I say you are correct... doing this for OpenGL is just the same as DX. |
||||
|
||||
All times are ET (US)![]() |
Last Thread Next Thread ![]() |
|