Lost Password?


Go Back   CodeCall Programming Forum > Software Development > C and C++

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-25-2007, 02:59 PM
felixme86's Avatar   
felixme86 felixme86 is offline
Newbie
 
Join Date: Sep 2007
Location: Seattle WA
Posts: 11
Rep Power: 0
felixme86 is on a distinguished road
Exclamation A Not So Simple Problem

I am using visual studio 2003 to create an application. I am using a win32 application with DirectX 9.0c. I have a class that allows me to load sprites so that they are drawn each frame using the directx D3DXSPRITE class. However after loading approximately 1000 sprites to the screen the sprites are begining to distort. The window is a popup window with no frame and i am making it look like a window using an image. The image I am using is posted below.
(it has been reduced in quality for bandwidth reasons)
It is being drawn to a window that is they exact size of the image and the result is also posted below

If I load this image before the other sprites then it displays correctly and the others do not. I have already checked the source and destination rectangles for directX. The entire project is approximately 200 pages worth of code so i am not sure what to post. if you have any idea why i am getting these distortions or would like to see any part of the code please let me know asap.

Mitchell

Correct image


Rendered Image

Last edited by felixme86; 09-25-2007 at 03:38 PM. Reason: added images
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 09-25-2007, 03:01 PM
felixme86's Avatar   
felixme86 felixme86 is offline
Newbie
 
Join Date: Sep 2007
Location: Seattle WA
Posts: 11
Rep Power: 0
felixme86 is on a distinguished road
Default Images

Oops

Last edited by felixme86; 09-27-2007 at 01:36 PM. Reason: removed
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-27-2007, 03:24 PM
felixme86's Avatar   
felixme86 felixme86 is offline
Newbie
 
Join Date: Sep 2007
Location: Seattle WA
Posts: 11
Rep Power: 0
felixme86 is on a distinguished road
Default Responses

So far no one has replied to my post. I have added some samples of code hoping this will spark some interest.

Windows Application Setup
Code:
Initialize(EngineData *Data)						//|
{																			//|
	ClassName = CopybyValue((char*)Data->sAppName);							//|
	m_hInstance=Data->hInstance;											//|
	WNDCLASSEX wc;	// The window class used to create our window			//|
																			//|
	// The name of our class and also the title window						//|
	//static char strAppName[] = "First Windows App, Zen Style";			//|
																			//|
	// Fill in the window class with the attributes for our main window		//|
																			//|
	// The size of this structure in bytes									//|
	wc.cbSize = sizeof( WNDCLASSEX );										//|
																			//|
	// The style of the window												//|
	wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;							//|
																			//|
	// Useless info set to 0												//|
	wc.cbClsExtra = 0;														//|
																			//|
	// More Useless info													//|
	wc.cbWndExtra = 0;														//|
																			//|
	// The name of our event handler										//|
	wc.lpfnWndProc = WndProc;												//|
																			//|
	// A handle to the applications instance								//|
	wc.hInstance = Data->hInstance;											//|
																			//|
	// A handle to the brush to use for the window background				//|
	wc.hbrBackground = (HBRUSH)GetStockObject(DKGRAY_BRUSH);				//|
																			//|
	// A handle to the icon used for the window								//|
	wc.hIcon = Data->hIcon;													//|
																			//|
	// A handle to the small version of the window icon						//|
	wc.hIconSm = Data->hIconSm;												//|
																			//|
	// A handle to the cursor to use while the mouse is over our window		//|
	wc.hCursor = Data->hCursor;												//|
																			//|
	// A handle to the resource to use as our menu							//|
	wc.lpszMenuName = 0;													//|
																			//|
	// The human readable name for this class								//|
	wc.lpszClassName = Data->sAppName;										//|
																			//|
	// Register the class with windows										//|
	RegisterClassEx( &wc );													//|
																			//|
	DWORD WStyle;															//|
	if(Data->Windowed)														//|
	{																		//|
		//WStyle=WS_BORDER|WS_SYSMENU|WS_MINIMIZEBOX|WS_EX_TOOLWINDOW;		
		WStyle=WS_POPUP;
	}																		//|
	else																	//|
	{																		//|
		WStyle=WS_POPUP;													//|
	}																		//|
	// Create the window based on the previous class						//|
	m_hWnd = CreateWindowEx(	NULL,			// Advanced style settings	//|
		Data->sAppName,			// The name of the class					//|
		Data->sAppName,			// The window Caption						//|
		WStyle,		// The window style										//|
		CW_USEDEFAULT,			// The Initial x position					//|
		CW_USEDEFAULT,			// The Initial y position					//|
		Data->Width,				// The initial width					//|
		Data->Height,				// The initial height					//|
		NULL,				// Handle to the parent window					//|
		NULL,				// Handle to the menu							//|
		Data->hInstance,			// Handle to the apps instance			//|
		NULL );				// Advanced Context								//|
	if(m_hWnd == NULL)														//|
	{																		//|
		return E_FAIL;														//|
	}																		//|
	//m_hDC= GetDC(m_hWnd);		// Device Context							//|
																			//|
		// Display the window we just created								//|
	ShowWindow(m_hWnd, Data->iCmdShow );									//|
																			//|
	// Draw the window contents for the first time							//|
	UpdateWindow( m_hWnd );													//|
																			//|
	// Tell Windows We want to be in front now								//|
	SetForegroundWindow(m_hWnd);											//|
																			//|
	m_Running=true;															//|
	return S_OK;
DirectX setup
Code:
Initialize(HWND hWnd,EngineData *Data)					//|
{																			//|
	bool NeedAssetReset=false;												//|
	if(m_Data!=NULL)														//|
	{																		//|
		if(m_Data->Windowed==Data->Windowed)								//|
		{																	//|
			// The width of the back buffer in pixels						//|
			m_d3dpp.BackBufferWidth = Data->Width;							//|
			// The height of the back buffer in pixels						//|
			m_d3dpp.BackBufferHeight = Data->Height;						//|
			// The handle to the window we want to render to				//|
			m_d3dpp.hDeviceWindow = hWnd;									//|
			// Windowed mode												//|
			m_d3dpp.Windowed = Data->Windowed;								//|
			return ResetResources();										//|
		}																	//|
		m_pDevice->Release();												//|
		m_pD3D->Release();													//|
		NeedAssetReset=true;												//|
	}																		//|
	// get the number of counts per second									//|
	QueryPerformanceFrequency((LARGE_INTEGER*)&m_Frequency);				//|
	m_LastExecute=0;														//|
	// if the frequency is NULL there is no timer							//|
	if(m_Frequency==NULL)													//|
	{																		//|
		m_Frequency=NULL;													//|
		QueryPerformanceFrequency((LARGE_INTEGER*)&m_Frequency);			//|
		if(m_Frequency==NULL)												//|
		{																	//|
			throw -1;														//|
		}																	//|
	}																		//|
																			//|
	m_Data=Data;															//|
	// Structure holding info about the current display mode				//|
	D3DDISPLAYMODE d3ddm;													//|
																			//|
	// aquire a pointer to Idirect3d9										//|
	m_pD3D = Direct3DCreate9( D3D_SDK_VERSION );							//|
																			//|
	// sets up hardware acceleration										//|
	//m_pD3D->CheckDeviceType(D3DADAPTER_DEFAULT,D3DDEVTYPE_REF, 			//|
	//			D3DFMT_X8R8G8B8, D3DFMT_X8R8G8B8,FALSE);					//|
																			//|
	//if(m_pD3D == NULL)													//|
	//{																		//|
	// error																//|
	//	return E_FAIL;														//|
	//}																		//|
																			//|
	// Get the current settings for the default display adapter				//|
	m_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&d3ddm);				//|
																			//|
	// Initiailze the struct to 0											//|
	ZeroMemory(&m_d3dpp,sizeof(D3DPRESENT_PARAMETERS));						//|
																			//|
	// The width of the back buffer in pixels								//|
	m_d3dpp.BackBufferWidth = Data->Width;									//|
	// The height of the back buffer in pixels								//|
	m_d3dpp.BackBufferHeight = Data->Height;								//|
	// set the back buffer format to e the same as the primary surface		//|
	m_d3dpp.BackBufferFormat = d3ddm.Format;								//|
																			//|
	// The number of back buffers											//|
	m_d3dpp.BackBufferCount = 1;											//|
	// The type of multisampling											//|
	m_d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;							//|
	// Tell Direct3d it is free to mess with the back buffer				//|
	m_d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;								//|
																			//|
	// The handle to the window we want to render to						//|
	m_d3dpp.hDeviceWindow = hWnd;											//|
	// Windowed mode														//|
	m_d3dpp.Windowed = Data->Windowed;										//|
																			//|
	// 3D doesnt work with this....											//|
																			//|
	// Let Direct3d manage the depth buffer									//|
	m_d3dpp.EnableAutoDepthStencil = true;									//|
	// Set the auto depth buffer to 16 bit									//|
	m_d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;//d3ddm.Format;			//|
																			//|
	//.... 3D doesnt work with this											//|
																			//|
	// Use the default refresh rate											//|
	m_d3dpp.FullScreen_RefreshRateInHz=0;									//|
																			//|
	// Present the information as fast as possible							//|
	m_d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;			//|
	// allow the back buffer to be accessed for 2d work						//|
	m_d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;						//|
																			//|
	// Acquire a pointer to IDirect3DDevice9								//|
	if(FAILED(m_pD3D->CreateDevice( D3DADAPTER_DEFAULT, 					//|
		D3DDEVTYPE_HAL,hWnd,												//|
		D3DCREATE_HARDWARE_VERTEXPROCESSING, 								//|
		&m_d3dpp, &m_pDevice )))											//|
	{																		//|
		if(FAILED(m_pD3D->CreateDevice( D3DADAPTER_DEFAULT, 				//|
			D3DDEVTYPE_HAL,hWnd,											//|
			D3DCREATE_MIXED_VERTEXPROCESSING, 								//|
			&m_d3dpp, &m_pDevice )))										//|
		{																	//|
			if(FAILED(m_pD3D->CreateDevice( D3DADAPTER_DEFAULT, 			//|
				D3DDEVTYPE_HAL,hWnd,										//|
				D3DCREATE_SOFTWARE_VERTEXPROCESSING, 						//|
				&m_d3dpp, &m_pDevice )))									//|
			{																//|
				return E_FAIL;												//|
			}																//|
		}																	//|
	}																		//|
																			//|
	// Turn on the Lights													//|
	m_pDevice->SetRenderState(D3DRS_LIGHTING, false);						//|
	// Turn on 3D															//|
	m_pDevice->SetRenderState(D3DRS_ZENABLE,true);							//|
	// Create our Sprite Manager											//|
	D3DXCreateSprite(m_pDevice,&m_SpriteManager);							//|
	if(NeedAssetReset)
	{																		//|
		return ResetResources();
	}
	return S_OK;															//|
}
Sprite Rendering
Code:
// Draw our Sprites													//|
		if(m_SpriteList)													//|
		{																	//|
			m_SpriteManager->Begin(D3DXSPRITE_ALPHABLEND|D3DXSPRITE_SORT_DEPTH_BACKTOFRONT|D3DXSPRITE_SORT_TEXTURE);
			bool MoreInSpriteList = m_SpriteList->ToFirst();				//|
			while(MoreInSpriteList)											//|
			{																//|
				CSprite* TempSprite=NULL;									//|
				TempSprite = m_SpriteList->GetData();						//|
				if(TempSprite!=NULL)										//|
				{															//|
					if(TempSprite->Visible)									//|
					{														//|
						if(TempSprite->m_CurFrame<TempSprite->GetNumCols()	//|
							*TempSprite->GetNumRows()&&						//|
							TempSprite->m_CurFrame>=0)						//|
						{													//|

							if(Compare(TempSprite->GetSpriteName(),"Console Window"))
							{
								int stophere=0;
							}
							// rectangle to copy the sprite					//|
							RECT srcRect;									//|
							// create the rectangle for the sprite			//|
							srcRect.left=(									//|
								TempSprite->GetTexture()->GetWidth()/		//|
								TempSprite->GetNumCols())*					//|
								(TempSprite->m_CurFrame% 					//|
								TempSprite->GetNumCols());					//|
							if(TempSprite->m_CurFrame==0)					//|
							{												//|
								srcRect.top=0;								//|
							}												//|
							else											//|
							{												//|
								srcRect.top=(								//|
									TempSprite->GetTexture()->GetHeight()/	//|
									TempSprite->GetNumRows())*				//|
									(int)(TempSprite->m_CurFrame/ 			//|
									TempSprite->GetNumCols());				//|
							}												//|
																			//|
							srcRect.right= srcRect.left+					//|
								TempSprite->GetTexture()->GetWidth()/		//|
								TempSprite->GetNumCols();					//|
							srcRect.bottom= srcRect.top+					//|
								TempSprite->GetTexture()->GetHeight()/		//|
								TempSprite->GetNumRows();					//|
																			//|
							D3DXVECTOR3 CenterPosition;						//|
							/*if(TempSprite->DrawIn3dSpace)					//|
							{												//|
							if(TempSprite->BillBoarded)						//|
							{												//|
							m_SpriteManager->Begin(							//|
							D3DXSPRITE_ALPHABLEND|D3DXSPRITE_OBJECTSPACE|	//|
							D3DXSPRITE_BILLBOARD);							//|
							CenterPosition=D3DXVECTOR3(						//|
							(float)(TempSprite->GetTexture()->GetWidth()/2),//|
							(float)(TempSprite->GetTexture()->GetHeight()/2)//|
							,0.0f);											//|
							}												//|
							else											//|
							{												//|
							m_SpriteManager->Begin(							//|
							D3DXSPRITE_ALPHABLEND|D3DXSPRITE_OBJECTSPACE);	//|
							CenterPosition=D3DXVECTOR3(						//|
							(float)(TempSprite->GetTexture()->GetWidth()/2),//|
							(float)(TempSprite->GetTexture()->GetHeight()/2)//|
							,0.0f);											//|
							}												//|
							D3DXMATRIXA16 TransforMat;						//|
							m_SpriteManager->GetTransform(&TransforMat);	//|
							D3DXMatrixRotationX( &TransforMat, 				//|
							D3DXToRadian(180) );							//|
							m_SpriteManager->SetTransform(&TransforMat);	//|
							}												//|
							else											//|
							{*/												//|
							
							CenterPosition=D3DXVECTOR3(0,0,0);				//|
							//}												//|
																			//|
							m_SpriteManager->Draw(							//|
								*(TempSprite->GetTexture()->GetTexture())	//|
								,&srcRect ,&CenterPosition,					//|
								&TempSprite->Position,						//|
								TempSprite->m_Color);						//|
							
						}													//|
					}														//|
				}															//|
				MoreInSpriteList = m_SpriteList->Next();					//|
			}																//|
			m_SpriteManager->End();
		}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Peculiar UI Problem Needs Tackling adriyel C# Programming 2 04-06-2008 08:46 AM
i have a problem please help me!!!???? stack Java Help 8 09-22-2007 04:17 PM
Simple C problem Minky C and C++ 1 09-11-2007 10:36 AM
Delphi Sockets : Simple client and server program tosh5457 Pascal/Delphi 0 05-26-2007 12:00 PM
null exception problem connor7777 C# Programming 2 03-28-2007 12:37 PM


All times are GMT -5. The time now is 02:24 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 100%


Complete - Celebrate!

Ads