Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

sckid

Managed C++ & DirectX9 Getting Started...

This topic is 5494 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey All, The tutorials for managed DirectX9 are geared more towards C# than C++. There are a few little gotchas for getting the tutorials to compile under C++. I am posting a working version of the 1st tutorial (creating a device) so people don''t have to struggle with it. Remeber to include the Microsoft.DirectX & Microsoft.DirectX.Direct3D assemblies as well. Also include an icon named "directx.ico" in the directory for this thing. Cheers, -M //----------------------------------------------------------------------------- // File: CreateDevice.cs // // Desc: This is the first tutorial for using Direct3D. In this tutorial, all // we are doing is creating a Direct3D device and using it to clear the // window. // // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- #include "stdafx.h" #include <windows.h> #using #using #using #ifdef MessageBox #undef MessageBox #endif // GETS RID OF THE STUPID MESSAGEBOXA NAME CONFLICT ! using namespace System; using namespace System::Diagnostics; using namespace System::Drawing; using namespace System::Windows::Forms; using namespace Microsoft::DirectX; using namespace Microsoft::DirectX::Direct3D; public __gc class CreateDevice : public System::Windows::Forms::Form { // Our global variables for this project static Device *device = NULL; // Our rendering device public: CreateDevice() { // Set the initial size of our form this->ClientSize = System::Drawing::Size(400,300); // And it''s caption this->Text = "D3D Tutorial 01: CreateDevice"; // Load our icon from the directory this thing is run from this->Icon = new System::Drawing::Icon("directx.ico"); } public: bool InitializeGraphics(void) { try { // Now let''s setup our D3D stuff PresentParameters *presentParams[] = new PresentParameters *[1]; presentParams[0] = new PresentParameters; presentParams[0]->Windowed = true; presentParams[0]->SwapEffect = SwapEffect::Discard; device = new Device(0, DeviceType::Hardware, this->get_Handle(), CreateFlags::SoftwareVertexProcessing, presentParams ); return true; } catch (DirectXException *pev) { Debug::WriteLine(String::Format("HORRIBLE DEVICE CREATION ERROR !!! {0}",pev->get_ErrorString() )); return false; } } public: void Render(void) { if (device == NULL) return; //Clear the backbuffer to a blue color device->Clear(ClearFlags::Target, System::Drawing::Color::Blue, 1.0f, 0); //Begin the scene device->BeginScene(); // Rendering of scene objects can happen here //End the scene device->EndScene(); device->Present(); } protected: System::Void OnPaint(System::Windows::Forms:aintEventArgs *e) { this->Render(); // Render on painting } protected: System::Void OnKeyPress(System::Windows::Forms::KeyPressEventArgs *e) { if ((int)(byte) e->KeyChar == (int)System::Windows::Forms::Keys::Escape) this->Close(); // Esc was pressed } }; int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { CreateDevice *frm = new CreateDevice; if (!frm->InitializeGraphics()) // Initialize Direct3D { System::Windows::Forms::MessageBox::Show("Could not initialize Direct3D. This tutorial will exit."); return -1; } frm->Show(); // While the form is still valid, render and process messages while( frm->get_Created() ) { frm->Render(); Application::DoEvents(); } return 0; }

Share this post


Link to post
Share on other sites
Advertisement

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!