Jump to content
  • Advertisement
Sign in to follow this  
Kr00pS

[solved] Black screen problem + question

This topic is 4013 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

SOLVED: Just some conflicts between game file and editor file. Hi ! I'm making a map editor for my game. Before this, I've made the engine of the game with a map module (tile sheet: one sprite (512*512)) and everything works. I can modify many settings (like map file) in configuration files, etc. So, I've taken back the game code and I've added menu, removed the fullscreen mode and stuffs... But, It's the same code than the game code and I've a black screen. I've debugged the map module, step by step, and everything works but nothing is draw. Drawing sprite works perfectly, drawing some text too. It's a big bug because if I add a sprite and I draw it before I draw the map, the map is drew EDIT: It works only in Release mode. In Debug mode, the map isn't draw at all. CODE (OUTDATED, PLEASE DOWNLOAD THE PROJECT) Map module Map.cpp
#include "Map.h"

Map::Map()
{
 	string filename = GlobalVars::GetInstance()->GetGVarValue<string>("mm_matmap");
 	//string filename = "Data/mat_map.bmp";

	int size_tile_x = GlobalVars::GetInstance()->GetGVarValue<int>("size_tile_x");
	int size_tile_y = GlobalVars::GetInstance()->GetGVarValue<int>("size_tile_y");

	m_TilesX = D3DManagement::GetInstance()->GetWidth()/size_tile_x;
	m_TilesY = D3DManagement::GetInstance()->GetHeight()/size_tile_y;
	
	m_Map = new Texture(filename);

	m_Tiles.resize(boost::extents[m_TilesX][m_TilesY]);

	FillMap();
}

void Map::FillMap()
{
	string filename = GlobalVars::GetInstance()->GetGVarValue<string>("map_filename");
	ifstream file(filename.c_str());

	if (file)
	{
		int temp = 0;

		for (int i = 0; i < m_TilesY; i++)
		{
			for (int j = 0; j < m_TilesX; j++)
			{
				temp = 0;

				file >> temp;

				if (file.fail())
				{
					MSG_ERROR("An exception has occured in the file");
				}

				m_Tiles[j] = new Tile(temp);
			}
		}
	}

	else
	{
		MSG_ERROR("Cannot open the map");
	}
}

Map::~Map()
{
	delete m_Map;

}

void Map::Draw()
{
	for (int i = 0; i < m_TilesY; i++)
	{
		for (int j = 0; j < m_TilesX; j++)
		{
			RECT rect = m_Tiles[j]->GetRect();

			D3DXVECTOR3 pos;

			pos.x = j*32;
			pos.y = i*32;

			m_Map->Draw(&rect, &pos);
		}
	}
}






Map.h
#pragma once

#include "inc.h"

#include "GlobalVars.h"
#include "D3DManagement.h"

#include "Texture.h"

#include "Tile.h"

#include "boost/multi_array.hpp"

class Map
{
private:
	int m_TilesX;
	int m_TilesY;

	Texture *m_Map;
	boost::multi_array<Tile *, 2> m_Tiles;


	void FillMap();

public:
	Map();
	~Map();

	void Draw();

	void Reset();
};






Texture.cpp
#include "Texture.h"

Texture::Texture(string filename)
{
	if (FAILED(D3DXCreateTextureFromFileEx(D3DManagement::GetInstance()->GetDevice(), filename.c_str(), 
		D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT,
		D3DX_DEFAULT, D3DCOLOR_XRGB(0, 255, 255), NULL, NULL, &m_Texture)))
	{
		MSG_ERROR("Can't load texture at : " + filename);
	}

	D3DXCreateSprite(D3DManagement::GetInstance()->GetDevice(), &m_Sprite);
}

Texture::~Texture()
{
	D3DSAFE_RELEASE(m_Sprite);
	D3DSAFE_RELEASE(m_Texture);
}

void Texture::Draw(RECT *src, D3DXVECTOR3 *pos)
{
	m_Sprite->Begin(D3DXSPRITE_ALPHABLEND);

	m_Sprite->Draw(m_Texture, src, NULL, pos, D3DCOLOR_ARGB(255,255,255,255));

	m_Sprite->End();
}

LPDIRECT3DTEXTURE9 Texture::GetTexture()
{
	return m_Texture;
}

void Texture::SetTexture(LPDIRECT3DTEXTURE9 texture)
{
	m_Texture = texture;
}

void Texture::SetTexture(string filename)
{
	D3DSAFE_RELEASE(m_Texture);

	if (FAILED(D3DXCreateTextureFromFileEx(D3DManagement::GetInstance()->GetDevice(), filename.c_str(), 
		D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT,
		D3DX_DEFAULT, D3DCOLOR_XRGB(0, 255, 255), NULL, NULL, &m_Texture)))
	{
		MSG_ERROR("Can't load texture at : " + filename);
	}
}







Texture.h
#pragma once

#include "inc.h"

#include "D3DManagement.h"
#include "Logger.h"

class Texture
{
private:
	LPDIRECT3DTEXTURE9 m_Texture;
	LPD3DXSPRITE m_Sprite;

public:
	Texture(string filename);
	~Texture();

	void Draw(RECT *src, D3DXVECTOR3 *pos);

	LPDIRECT3DTEXTURE9 GetTexture();

	void SetTexture(LPDIRECT3DTEXTURE9 texture);
	void SetTexture(string filename);
};






Tile.cpp
#include "Tile.h"

Tile::Tile(int sprite)
{
	m_Sprite = sprite;

	ostringstream oss;

	oss << "mm_t_" << m_Sprite << "_x";

	int x = GlobalVars::GetInstance()->GetGVarValue<int>(oss.str());

	oss.str("");
	oss << "mm_t_" << m_Sprite << "_y";

	int y = GlobalVars::GetInstance()->GetGVarValue<int>(oss.str());

	oss.str("");
	oss << "mm_t_" << m_Sprite << "_w";

	int w = GlobalVars::GetInstance()->GetGVarValue<int>(oss.str());

	oss.str("");
	oss << "mm_t_" << m_Sprite << "_h";

	int h = GlobalVars::GetInstance()->GetGVarValue<int>(oss.str());

	SetRect(&m_Rect, x, y, w, h);
}

Tile::~Tile()
{

}

int Tile::GetSprite()
{
	return m_Sprite;
}

RECT Tile::GetRect()
{
	return m_Rect;
}






Tile.h
#pragma once

#include "GlobalVars.h"

class Tile
{
private:
	int m_Sprite;
	RECT m_Rect;

public:
	Tile(int sprite);
	~Tile();

	int GetSprite();
	RECT GetRect();
};






Sprite.cpp
#include "Sprite.h"

Sprite::Sprite(string filename, int x, int y)
{
	if (FAILED(D3DXCreateTextureFromFileEx(D3DManagement::GetInstance()->GetDevice(), filename.c_str(), 
		D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT,
		D3DX_DEFAULT, D3DCOLOR_XRGB(0, 255, 255), NULL, NULL, &m_Texture)))
	{
		MSG_ERROR("Can't load texture at : " + filename);
	}

	m_Position.x = x;
	m_Position.y = y;
	m_Position.z = 0.0f;

	D3DXCreateSprite(D3DManagement::GetInstance()->GetDevice(), &m_Sprite);

	// opaque
	m_Alpha = 255;
}

Sprite::Sprite(LPDIRECT3DTEXTURE9 texture, int x, int y)
{
	m_Texture = texture;

	m_Position.x = x;
	m_Position.y = y;
	m_Position.z = 0.0f;

	D3DXCreateSprite(D3DManagement::GetInstance()->GetDevice(), &m_Sprite);

	// opaque
	m_Alpha = 255;
}

Sprite::~Sprite()
{
	D3DSAFE_RELEASE(m_Texture);
	D3DSAFE_RELEASE(m_Sprite);
}

LPD3DXSPRITE Sprite::GetSprite()
{
	return m_Sprite;
}

void Sprite::Draw()
{
	m_Sprite->Begin(D3DXSPRITE_ALPHABLEND);

	m_Sprite->Draw(m_Texture, NULL, NULL, &m_Position, D3DCOLOR_ARGB(m_Alpha,255,255,255));

	m_Sprite->End();
}

void Sprite::SetAlpha(int alpha)
{
	m_Alpha = alpha;
}

int Sprite::GetAlpha()
{
	return m_Alpha;
}

D3DXVECTOR3 Sprite::GetPosition()
{
	return m_Position;
}

void Sprite::SetPosition(int x, int y)
{
	m_Position.x = x;
	m_Position.y = y;
}

void Sprite::SetPosition(D3DXVECTOR3 pos)
{
	m_Position = pos;
}


void Sprite::IncreasePosition(bool x, bool y, int delta)
{
	if (x)
	{
		m_Position.x += delta;
	}

	if (y)
	{
		m_Position.y += delta;
	}
}

void Sprite::DecreasePosition(bool x, bool y, int delta)
{
	if (x)
	{
		m_Position.x -= delta;
	}

	if (y)
	{
		m_Position.y -= delta;
	}
}







Sprite.h
#pragma once

#include "inc.h"

#include "D3DManagement.h"

class Sprite
{
private:
	LPDIRECT3DTEXTURE9 m_Texture;
	LPD3DXSPRITE m_Sprite;
	D3DXVECTOR3 m_Position;

	int m_Alpha;

public:
	Sprite(string filename, int x = 0, int y = 0);
	Sprite(LPDIRECT3DTEXTURE9 texture, int x = 0, int y = 0);
	virtual ~Sprite();

	LPD3DXSPRITE GetSprite();

	void Draw();

	void SetAlpha(int alpha);
	int GetAlpha();

	D3DXVECTOR3 GetPosition();
	void SetPosition(int x, int y);
	void SetPosition(D3DXVECTOR3 pos);

	void IncreasePosition(bool x, bool y, int delta);
	void DecreasePosition(bool x, bool y, int delta);
};






D3DManagement.cpp
#include "D3DManagement.h"

#include "resource.h"

const int FPS = 100;
const int FRAMERATE = FPS/1000;

HBITMAP bitmap = NULL;

BOOL CALLBACK AboutDLGProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg)
	{
	case WM_INITDIALOG:

		return TRUE;

	case WM_COMMAND:
		switch(LOWORD(wParam))
		{
		case IDOK:
			EndDialog(hwnd, IDOK);
			break;
		}

		break;

	default:
		return FALSE;
	}

	return TRUE;
}

BOOL CALLBACK ToolBoxDLGProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg)
	{
	case WM_INITDIALOG:

		return TRUE;

	case WM_CREATE:
		bitmap = LoadBitmap(GetModuleHandle(NULL), "Data/mat_map.bmp");

		break;

	case WM_PAINT:
		{
			BITMAP bm;
			PAINTSTRUCT ps;

			HDC hdc = BeginPaint(hwnd, &ps);

			HDC hdcMem = CreateCompatibleDC(hdc);
			HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem, bitmap);

			GetObject(bitmap, sizeof(bm), &bm);

			BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);

			SelectObject(hdcMem, hbmOld);
			DeleteDC(hdcMem);

			EndPaint(hwnd, &ps);
		}

		break;

	case WM_COMMAND:
		switch(LOWORD(wParam))
		{
		case IDCLOSE:
			EndDialog(hwnd, IDCLOSE);
			break;
		}
		break;

	default:
		return FALSE;
	}

	return TRUE;
}

LRESULT CALLBACK MsgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg)
	{
	case WM_DESTROY:
		DestroyWindow(D3DManagement::GetInstance()->m_ToolBox);
		GameManager::GetInstance()->SetGameOver(true);
		PostQuitMessage(0);
		return 0;

	case WM_CLOSE:
		GameManager::GetInstance()->SetGameOver(true);
		PostQuitMessage(0);
		return 0;

	case WM_CREATE:
            HMENU hMenu, hSubMenu;

            hMenu = CreateMenu();

            hSubMenu = CreatePopupMenu();
            AppendMenu(hSubMenu, MF_STRING, ID_FILE_NEW, "N&ew Map");
            AppendMenu(hSubMenu, MF_STRING, ID_FILE_OPEN, "O&pen Map");
            AppendMenu(hSubMenu, MF_STRING, ID_FILE_SAVE, "S&ave Map");
            AppendMenu(hSubMenu, MF_STRING, ID_FILE_EXIT, "E&xit Editor");
            AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&File");

			hSubMenu = CreatePopupMenu();
			AppendMenu(hSubMenu, MF_STRING, ID_TOOLBOX_SHOW, "S&how");
			AppendMenu(hSubMenu, MF_STRING, ID_TOOLBOX_HIDE, "H&ide");
			AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&Toolbox");

			hSubMenu = CreatePopupMenu();
			AppendMenu(hSubMenu, MF_STRING, ID_HELP_HELP, "H&elp");
			AppendMenu(hSubMenu, MF_STRING, ID_HELP_ABOUT, "A&bout...");
            AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&?");

            SetMenu(hwnd, hMenu);

			D3DManagement::GetInstance()->m_ToolBox = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_TOOLBOX), hwnd,
				ToolBoxDLGProc);

			ShowWindow(D3DManagement::GetInstance()->m_ToolBox, SW_SHOW);

		return 0;

	case WM_COMMAND:
            switch(LOWORD(wParam))
            {
                case ID_FILE_EXIT:
					GameManager::GetInstance()->SetGameOver(true);
					PostMessage(hwnd, WM_CLOSE, 0, 0);
                return 0;

				case ID_TOOLBOX_SHOW:
					ShowWindow(D3DManagement::GetInstance()->m_ToolBox, SW_SHOW);
				return 0;

				case ID_TOOLBOX_HIDE:
					ShowWindow(D3DManagement::GetInstance()->m_ToolBox, SW_HIDE);
				return 0;

				case ID_HELP_ABOUT:
					DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_ABOUT), hwnd,
						AboutDLGProc);
				return 0;
            }
		return 0;

	case WM_KEYDOWN:
		if(wParam == VK_ESCAPE)
		{
			GameManager::GetInstance()->SetGameOver(true);
			PostQuitMessage(0);
			return 0;
		}

		D3DManagement::GetInstance()->SetKey((int)wParam, true);

		return 0;

	//case WM_CHAR:
	//	D3DManagement::GetInstance()->SetKey((int)wParam, true);

	//	return 0;


	case WM_KEYUP:
		D3DManagement::GetInstance()->SetKey((int)wParam, false);

		return 0;

	case WM_MOUSEMOVE:
		D3DManagement::GetInstance()->SetMousePosition(LOWORD(lParam), HIWORD(lParam));

		return 0;
	}

	return DefWindowProc(hwnd, msg, wParam, lParam);
}

D3DXVECTOR2 D3DManagement::GetMousePosition()
{
	return m_RelativeMousePos;
}


void D3DManagement::SetMousePosition(int x, int y)
{
	m_RelativeMousePos.x = x;
	m_RelativeMousePos.y = y;
}


bool D3DManagement::GetKey(int key)
{
	return m_Keys[key];
}

void D3DManagement::SetKey(int key, bool value)
{
	m_Keys[key] = value;
}

HRESULT D3DManagement::BuildWindow(string name, int width, int height)
{
	m_Width = width;
	m_Height = height;

	WNDCLASSEX wc = {sizeof(WNDCLASSEX), 0, MsgProc, 0L, 0L, GetModuleHandle(NULL), 
		NULL, LoadCursor(NULL, IDC_ARROW), NULL, MAKEINTRESOURCE(IDR_MENU), "D3DM", NULL};

	if(!RegisterClassEx(&wc))
	{
		MSG_ERROR("Window registration failed");
		return E_FAIL;
	}

	MSG_SUCCESS("Windows registration succeeded");

	m_MainWindowHandle = CreateWindow("D3DM", name.c_str(), WS_OVERLAPPEDWINDOW, 100, 100,
		m_Width, m_Height, GetDesktopWindow(), NULL, wc.hInstance, NULL);

	if (m_MainWindowHandle == NULL)
	{
		MSG_ERROR("Window creation failed");
		return E_FAIL;
	}

	MSG_SUCCESS("Windows creation succeeded");

	ShowWindow(m_MainWindowHandle, SW_SHOW);
	UpdateWindow(m_MainWindowHandle);


	for (int i = 0; i < 256; i++)
	{
		m_Keys = false;
	}


	return S_OK;
}

void D3DManagement::MessageLoop()
{
	float last_time = timeGetTime();

	MSG msg;

	PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);

	while (msg.message != WM_QUIT)
	{
		float current_time = timeGetTime();
		float delta_time = (current_time - last_time) * 0.001f;

		if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);

			GameManager::GetInstance()->ManageInput();
		}

		if ((current_time - last_time) >= FRAMERATE)
		{			
			GameManager::GetInstance()->ManageGame();

			Draw();

			last_time = current_time;
		}

		else
		{
			Sleep(FRAMERATE - (current_time - last_time));
		}
	}
}

HRESULT D3DManagement::InitD3D()
{
	if (((m_D3DObject = Direct3DCreate9(D3D_SDK_VERSION)) == NULL))
	{
		MSG_ERROR("Can't create Direct3D object");
		return E_FAIL;
	}

	MSG_SUCCESS("Direct3D object creation succeeded");

	D3DPRESENT_PARAMETERS d3dpp;
	ZeroMemory(&d3dpp, sizeof(d3dpp));

	d3dpp.Windowed               = TRUE;
	d3dpp.EnableAutoDepthStencil = TRUE;
	d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
	d3dpp.SwapEffect             = D3DSWAPEFFECT_DISCARD;
	d3dpp.BackBufferWidth        = m_Width;
	d3dpp.BackBufferHeight       = m_Height;
	d3dpp.BackBufferFormat       = D3DFMT_X8R8G8B8;
	d3dpp.PresentationInterval   = D3DPRESENT_INTERVAL_IMMEDIATE;

	if (FAILED(m_D3DObject->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_MainWindowHandle,
		D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &m_D3DDevice)))
	{
		MSG_ERROR("Can't create Direct3D device");
		return E_FAIL;
	}

	MSG_SUCCESS("Direct3D device creation succeeded");

	m_D3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
	m_D3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE);

	// Desactivation du Z buffer
	m_D3DDevice->SetRenderState(D3DRS_ZWRITEENABLE, false);

	SetMatrices();

	return S_OK;
}

void D3DManagement::Draw()
{
	m_D3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);

	m_D3DDevice->BeginScene();

	GameManager::GetInstance()->Draw();

	m_D3DDevice->EndScene();

	m_D3DDevice->Present(NULL, NULL, NULL, NULL);
}

void D3DManagement::Cleanup()
{
	D3DSAFE_RELEASE(m_D3DObject);
	D3DSAFE_RELEASE(m_D3DDevice);
}

void D3DManagement::SetMatrices()
{
	D3DXMATRIX matWorld;
	D3DXMatrixTranslation(&matWorld, 2, 2, 0);
	m_D3DDevice->SetTransform(D3DTS_WORLD, &matWorld);

	// ------------------------------------------------------------------------------------------------
	D3DXVECTOR3 vecEyePt (0.0f, 3.0f, 0.0f);
	D3DXVECTOR3 vecLookatPt (0.0f, 0.0f, 0.0f);
	D3DXVECTOR3 vecUpVec (0.0f, 1.0f, 0.0f);

	D3DXMATRIXA16 matView;

	D3DXMatrixLookAtLH(&matView, &vecEyePt, &vecLookatPt, &vecUpVec);
	m_D3DDevice->SetTransform(D3DTS_VIEW, &matView);

	// ------------------------------------------------------------------------------------------------

	D3DXMATRIX matOrtho;
	D3DXMatrixOrthoLH(&matOrtho, D3DX_PI/4, 1.0f, 1.0f, 1000.0f);
	m_D3DDevice->SetTransform(D3DTS_PROJECTION, &matOrtho);
}

LPDIRECT3DDEVICE9 D3DManagement::GetDevice()
{
	return m_D3DDevice;
}

HWND D3DManagement::GetHandle()
{
	return m_MainWindowHandle;
}

int D3DManagement::GetWidth()
{
	return m_Width;
}

int D3DManagement::GetHeight()
{
	return m_Height;
}






D3DManagement.h
#pragma once

#include "inc.h"

#include "Logger.h"
#include "GameManager.h"

using namespace std;

class GameManager;

#define D3DSAFE_RELEASE(p) if (p != NULL) { p->Release(); }

class D3DManagement
{
private:
	LPDIRECT3D9 m_D3DObject;
	LPDIRECT3DDEVICE9 m_D3DDevice;

	HWND m_MainWindowHandle;

	int m_Width;
	int m_Height;

	bool m_Keys[256];

	D3DXVECTOR2 m_RelativeMousePos;

// ------------------------------------------------------------------------------------------------
	D3DManagement() {}
	~D3DManagement() {}
// ------------------------------------------------------------------------------------------------

public:
// ------------------------------------------------------------------------------------------------
	static D3DManagement *GetInstance()
	{
		static D3DManagement instance;
		return &instance;
	}
// ------------------------------------------------------------------------------------------------

	HWND m_ToolBox;

	HRESULT BuildWindow(string name, int width, int height);

	HRESULT InitD3D();
	void MessageLoop();
	void Draw();
	void Cleanup();

	void SetMatrices();

	LPDIRECT3DDEVICE9 GetDevice();
	HWND GetHandle();

	bool GetKey(int key);
	void SetKey(int key, bool value);

	int GetWidth();
	int GetHeight();

	D3DXVECTOR2 GetMousePosition();
	void SetMousePosition(int x, int y);
};

LRESULT CALLBACK MsgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);






GameManager.cpp
#include "GameManager.h"

#include "Sprite.h"
#include "D3DManagement.h"

#include "Font.h"
#include "TextManager.h"


#include "Map.h"


void GameManager::Init()
{
	D3DManagement::GetInstance()->BuildWindow("Editor", GlobalVars::GetInstance()->GetGVarValue<int>("screen_width"),
		GlobalVars::GetInstance()->GetGVarValue<int>("screen_height"));

	D3DManagement::GetInstance()->InitD3D();

	//D3DManagement::GetInstance()->Init();

	TextManager::GetInstance()->Init();

	m_GameOver = false;

	m_Map = new Map();
}

void GameManager::Destroy()
{
	TextManager::GetInstance()->Destroy();

	D3DManagement::GetInstance()->Cleanup();

}

void GameManager::GameLoop()
{
	while (m_GameOver != true)
	{
		D3DManagement::GetInstance()->MessageLoop();
	}
}

void GameManager::Draw()
{
	m_Map->Draw();

	DrawMessages();
}

void GameManager::DrawMessages()
{
	IGMSG_INFO("LOOOOOOOOOOOOOOOL", 10, 10, D3DCOLOR_XRGB(255,255,255));
}

void GameManager::ManageGame()
{
	static float last_time = 0.0f;
	static float current_time = 0.0f;

	current_time = timeGetTime();

	if ((current_time - last_time) >= 10)
	{
		last_time = current_time;
	}
}

void GameManager::ManageInput()
{
	if (D3DManagement::GetInstance()->GetKey('S'))
	{

	}
}

void GameManager::SetGameOver(bool value)
{
	m_GameOver = value;
}

bool GameManager::IsGameOver()
{
	return m_GameOver;
}






GameManager.h
#pragma once

class Map;

#include "inc.h"

#include "GlobalVars.h"

class GameManager
{
private:
	bool m_GameOver;

	Map *m_Map;

// ------------------------------------------------------------------------------------------------
	GameManager() {}
	~GameManager() {}
// ------------------------------------------------------------------------------------------------

public:
// ------------------------------------------------------------------------------------------------
	static GameManager *GetInstance()
	{
		static GameManager instance;
		return &instance;
	}
// ------------------------------------------------------------------------------------------------

	void Init();
	void Destroy();

	void Draw();

	void DrawMessages();

	void GameLoop();

	void ManageGame();
	void ManageInput();

	void SetGameOver(bool value);
	bool IsGameOver();
};







----------------------- Now the question, I've made a toolbox dialog who must contain the terrain tiles of the game. The user select what tile he wants to draw. I'm trying to use GDI, I load a bitmap in the WM_CREATE message, and I draw it in the WM_PAINT message. All of these things in my Toolbox Message Proc but it doesn't work. Screen: Free Image Hosting at www.ImageShack.us Why (see the file D3DManagement.cpp of the Editor source code) ? Using DirectX or GDI ? Thanks in advance. [Edited by - Kr00pS on October 29, 2007 1:30:23 PM]

Share this post


Link to post
Share on other sites
Advertisement
It's difficult to look through a lot of code when it's all posted in a topic. I suggest that you post a link to the zip file with your project's code, and the specific resources you are using in your screenshot. That way we can load up your project and hit F5.

From what I could gather so far by looking at your code, your Sprite class and your Texture class create their own instances of ID3DXSprite. This implies you are creating as many instances of ID3DXSprite as you have sprite and tileset textures.
The best way to go about this is to only use one global sprite instance, and have textures, texture coordinates, and on-screen position specific to each object.

Further more, you are calling ID3DXSprite::Begin and ::End each time you draw a tile, and each time you draw a sprite. The intended way is to call ::Begin before you start drawing anything, and ::End after you finish drawing everything.

One last thing I would suggest, is that you go to DirectX Control Panel (available as a shortcut on your start menu, under Programs->Microsoft DirectX SDK), and set your DirectX libraries from retail to debug. That way, if you are doing any sort of blatant mistakes, DirectX debug runtime will crash your program and output handful of warm error messages on your Output window. Also, #define D3D_DEBUG_INFO just before your #include <d3dx9.h>.

Share this post


Link to post
Share on other sites
Thanks for your reply

Archive with full code (last code)

I'm using config files to specify the sprite coordinates in 512*512 textures.

One texture for the terrain tiles, many textures for the sprites.

------

I'm already using the DX debug librairies, useful for the memory leaks at the moment. :)

------

I got 3000 fps without the map and 25 fps with the map (Pentium D 820, 1GB DDR2, X1900GT). It's a cause of the calls of ID3DXSprite::Begin() and ID3DXSprite::End() ?

Share this post


Link to post
Share on other sites
I forgot that I don't have boost :( so I couldn't debug your project. Everything looks OK, besides those other things I mentioned.

One possible reason for it working in Release but not in Debug is because in Debug mode, all variables get initialized to some compiler-dependent value, which for Microsoft's compilers is 0xCC. So if for instance you forgot to initialize your alpha, and then draw tiles with that alpha (which you don't, but just for example), then they would be visible in debug mode with alpha of 0xCC, but in release mode the alpha could be 0, depending on what what is that memory region.

But anyway, first make sure you are using only one sprite object. That will speed up your code and make it easier to debug. Then, also make sure you are checking return values. I noticed that you ignore return values of Sprite::Begin, Sprite::End and Sprite::Draw, so you don't even know if they are succeeding.

Regarding your dialog stuff, it also looks like you are not checking the return values of LoadBitmap, CreateDC, etc. Also, you are returning TRUE on your WM_PAINT handler, when you should be returning 0 (I believe).

Share this post


Link to post
Share on other sites
(CODE UPDATED)


Quote:
I forgot that I don't have boost :( so I couldn't debug your project. Everything looks OK, besides those other things I mentioned.


Too bad :(

Quote:
One possible reason for it working in Release but not in Debug is because in Debug mode, all variables get initialized to some compiler-dependent value, which for Microsoft's compilers is 0xCC. So if for instance you forgot to initialize your alpha, and then draw tiles with that alpha (which you don't, but just for example), then they would be visible in debug mode with alpha of 0xCC, but in release mode the alpha could be 0, depending on what what is that memory region.


Okay, I'm trying to find who I didn't initialize an important thing. In release mode, it works perfectly now.

Quote:
But anyway, first make sure you are using only one sprite object. That will speed up your code and make it easier to debug. Then, also make sure you are checking return values. I noticed that you ignore return values of Sprite::Begin, Sprite::End and Sprite::Draw, so you don't even know if they are succeeding.


OK.

EDIT: Done. :)

Awesome with retail runtimes, I've 1300 FPS with the map and 3000 without. Thank you :)

Quote:
Regarding your dialog stuff, it also looks like you are not checking the return values of LoadBitmap, CreateDC, etc. Also, you are returning TRUE on your WM_PAINT handler, when you should be returning 0 (I believe).

My debug.html is like this:

*** Logging Started ***


<D3DManagement::BuildWindow> Windows registration succeeded

<D3DManagement::BuildWindow> Windows creation succeeded

<D3DManagement::InitD3D> Direct3D object creation succeeded

<D3DManagement::InitD3D> Direct3D device creation succeeded

<ToolBoxDLGProc> Can't begin paint

<ToolBoxDLGProc> Can't create Compatible DC

<ToolBoxDLGProc> Can't begin paint

<ToolBoxDLGProc> Can't begin paint

<ToolBoxDLGProc> Can't create Compatible DC

<ToolBoxDLGProc> Can't begin paint

<ToolBoxDLGProc> Can't create Compatible DC


*** Logging Finished ***

The bitmap is successfully loaded.

[Edited by - Kr00pS on October 29, 2007 12:06:31 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!