Wrox Programmer Forums
|
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old February 11th, 2014, 06:22 PM
Authorized User
 
Join Date: Dec 2013
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default Directx Initialization

I have a project that I worked on a while ago, that worked fine at that time. I decided to open it up and run it again, and its crashing and giving me an error saying that my device isn't initialize using IDirect3DDevice9*. Basically an unhandled exception of 0x0000000. According to my code I am still using the same function that I used previously to initialize the device. Here is some of my code. It crashed right were it sets the transform. Maybe its something easy that I am missing. Any help would be appreciated
thanks.

Code:
	// Grab the window width and height from the HWND
	RECT r;
	GetWindowRect(hWnd, &r);
	m_nWidth = r.right - r.left;
	m_nHeight = r.bottom - r.top;

	m_bVSync = false;

	// Create the D3D Object
	Object1 = Direct3DCreate9(D3D_SDK_VERSION);

	// Create our presentation parameters for our D3D Device
	D3Dpp.hDeviceWindow = hWnd;					// Handle to the window
	D3Dpp.Windowed = bWindowed;					// Windowed or Full-screen?
	D3Dpp.BackBufferCount = 1;					// Number of back-buffers
	D3Dpp.BackBufferFormat = D3DFMT_X8R8G8B8;	// Back-buffer pixel format
	D3Dpp.BackBufferWidth = m_nWidth;			// Back-buffer width
	D3Dpp.BackBufferHeight = m_nHeight;			// Back-buffer height
	D3Dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;	// Swap effect
	D3Dpp.PresentationInterval = m_bVSync ? D3DPRESENT_INTERVAL_DEFAULT : D3DPRESENT_INTERVAL_IMMEDIATE;
	D3Dpp.FullScreen_RefreshRateInHz = bWindowed ? 0 : D3DPRESENT_RATE_DEFAULT;
	D3Dpp.EnableAutoDepthStencil = TRUE;		// Enable depth and stencil buffer
	D3Dpp.AutoDepthStencilFormat = D3DFMT_D24S8; // Depth/Stencil buffer bit format
	D3Dpp.Flags = D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL; // Discard the depth/stencil buffer upon Present()
	D3Dpp.MultiSampleQuality = 0;					// MSAA quality
	D3Dpp.MultiSampleType = D3DMULTISAMPLE_NONE;	// MSAA type

	// TODO: Determine supported vertex processing modes

	// Create D3D Device
	Object1->CreateDevice(
		D3DADAPTER_DEFAULT,			// Default display adapter
		D3DDEVTYPE_HAL,				// Device type to use
		hWnd,						// Handle to our window
		D3DCREATE_HARDWARE_VERTEXPROCESSING,		// Vertex Processing Behavior Flags (PUREDEVICE, HARDWARE_VERTEXPROCESSING, SOFTWARE_VERTEXPROCESSING)
		&D3Dpp,						// Presentation parameters
		&Device1);				// Return a created D3D Device

	///////////////////////////////////////////////////////
	//eye position, look at position, etc for e3 image
	/////////////////////////////////////////////////////
		eyePos = D3DXVECTOR3(0, 2, -10);
		LookAt = D3DXVECTOR3(0, 0, 0);
		upVec = D3DXVECTOR3(0, 1, 0);

	///////////////////////////////////////////////////
	//call the functions to display 3d images
	//////////////////////////////////////////////////
		D3DXMatrixLookAtLH(&WorldMat, &eyePos, &LookAt, &upVec);
		Device1->SetTransform(D3DTS_VIEW, &WorldMat);
		D3DXMatrixPerspectiveFovLH(&ProjMat, D3DX_PI/3, float(m_nWidth)/float(m_nHeight), 1.0f, 1000.0f);
		Device1->SetTransform(D3DTS_PROJECTION, &ProjMat);
		Device1->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE); 

		// create the sprite COM object 
	D3DXCreateSprite(Device1, &Sprite1);

	////////////////////////////////////////////////
	//initalize the font object
	///////////////////////////////////////////////
	D3DXCreateFont(Device1, 30, 0, FW_BOLD, 0, true, DEFAULT_CHARSET,
		OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, TEXT("Delicious-Roman"), &Font);

Last edited by crossfire19; February 11th, 2014 at 06:50 PM..
Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
about directx Innaorouk C# 2 August 27th, 2007 08:39 PM
Help. How to play media files using DirectX dextergaisie Pro VB 6 0 May 15th, 2007 06:09 AM
managed directx 9drawsubset problem? mmmobasher C# 0 December 1st, 2005 05:29 AM
How to speed up 10 times using directX? czw6296 C++ Programming 2 October 19th, 2005 10:47 PM
directx programing bcmaverik VB.NET 5 January 28th, 2004 07:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.