• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
NZT

DrawText not working?

1 post in this topic

Okay, so I can't seem to get the [url="http://msdn.microsoft.com/en-us/library/ms901121.aspx"]DrawText[/url] function to work (I'm a beginner in Directx). I'm following [url="http://www.toymaker.info/Games/html/text.html"]ToyMaker's DX9 Tutorial[/url]. I have sufficient error checking, none of them are indicating any failures anywhere. I'm also not receiving any compile-time nor run-time errors/warnings. I have properly configured my project to include the necessary Directx9 headers & libraries, as well. This is a default Win32 Windows application.

I'm using Microsoft Visual C++ Express edition on a 64 bit version of Windows 7.

Source Code: ([url="http://codeviewer.org/view/code:248d"]Highlighted Version[/url])
[CODE]
// DirectxText.cpp: Application entry point
#include "stdafx.h"
#include "DirectxText.h"
#include <d3d9.h>
#include <d3dx9.h>
#include <Windows.h>
#pragma comment (lib, "d3d9.lib")
#pragma comment (lib, "d3dx9.lib")
#define MAX_LOADSTRING 100
// Window size (width & height)
#define WINDOW_WIDTH 600
#define WINDOW_HEIGHT 400
// Window positions (x & y)
#define WINDOW_POSX 500
#define WINDOW_POSY 400
// Use code segments only available for debugging purposes
#ifndef DEBUG
#define DEBUG
#endif
// ---------------------------------------------------------------------------
// Global Variables:
HWND g_hWnd; // Handle (identifier) for main window
HINSTANCE g_hInst; // Current instance
TCHAR g_szTitle[MAX_LOADSTRING]; // Title bar text
TCHAR g_szWindowClass[MAX_LOADSTRING]; // Main window's class name
// ---------------------------------------------------------------------------

// ---------------------------------------------------------------------------
// Forward declarations for Win32 functions
USHORT MyRegisterClass(HINSTANCE hInstance); // USHORT is explicitly defined in WinDef.h
int InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
// ---------------------------------------------------------------------------

// ---------------------------------------------------------------------------
// Directx
HRESULT D3D_Init(HWND hWnd); // Initialize Directx globals
HRESULT D3D_Display(); // Render a frame
bool D3D_Cleanup(); // Gracefully release COM objects
IDirect3D9 *g_pD3D = NULL; // D3D interface
IDirect3DDevice9 *g_pD3Ddev = NULL; // D3D device interface
ID3DXFont *g_pD3DFont = NULL;
// ---------------------------------------------------------------------------

int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
MSG msg;
ZeroMemory(&msg, sizeof(MSG));
HACCEL hAccelTable;
// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, g_szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_DIRECTXTEXT, g_szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
return false;
hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_DIRECTXTEXT));
// Main message loop:
while (msg.message != WM_QUIT)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
#ifdef DEBUG
// Only perform if DEBUG mode is specified:
if(FAILED(D3D_Display()))
MessageBox(g_hWnd, "D3D_Display failed!", "Main Message Loop", MB_ICONEXCLAMATION | MB_OK);
#else
D3D_Display();
#endif
}
}
#ifdef DEBUG
// Only perform if DEBUG mode is specified:
if(!D3D_Cleanup)
MessageBox(g_hWnd, "D3D_Cleanup failed, live COM objects may still reside in memory!", "Error", MB_ICONEXCLAMATION | MB_OK);
#else
D3D_Cleanup();
#endif
return (int) msg.wParam;
}
USHORT MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
ZeroMemory(&wcex, sizeof(WNDCLASSEX));
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_DIRECTXTEXT));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = MAKEINTRESOURCE(IDC_DIRECTXTEXT);
wcex.lpszClassName = g_szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
return RegisterClassEx(&wcex);
}
int InitInstance(HINSTANCE hInstance, int nCmdShow)
{
g_hInst = hInstance; // Store instance handle in our global variable
g_hWnd = CreateWindow(g_szWindowClass, g_szTitle, WS_OVERLAPPEDWINDOW,
WINDOW_POSX, WINDOW_POSY, WINDOW_WIDTH, WINDOW_HEIGHT, NULL, NULL, hInstance, NULL);
if (!g_hWnd)
return false;
if(SUCCEEDED(D3D_Init(g_hWnd)))
{
ShowWindow(g_hWnd, nCmdShow);
UpdateWindow(g_hWnd);
return true;
}
else
return false;
}
LRESULT CALLBACK WndProc(HWND g_hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
switch (wmId)
{
case IDM_EXIT:
DestroyWindow(g_hWnd);
break;
default:
return DefWindowProc(g_hWnd, message, wParam, lParam);
}
break;
case WM_KEYDOWN: // Escape key was pressed, time to bounce!
if(wParam == VK_ESCAPE)
PostQuitMessage(0);
break;
case WM_PAINT:
hdc = BeginPaint(g_hWnd, &ps);
#ifdef DEBUG
if(FAILED(D3D_Display()))
MessageBox(g_hWnd, "D3D_Display failed!", "Main Message Loop", MB_ICONEXCLAMATION | MB_OK);
#else
D3D_Display();
#endif
EndPaint(g_hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(g_hWnd, message, wParam, lParam);
}
return 0;
}
HRESULT D3D_Init(HWND hWnd)
{
if(FAILED(g_pD3D = Direct3DCreate9(D3D_SDK_VERSION)))
return false;
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS));
d3dpp.Windowed = true;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = g_hWnd;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
d3dpp.BackBufferWidth = WINDOW_WIDTH;
d3dpp.BackBufferHeight = WINDOW_HEIGHT;
HRESULT hr = g_pD3D->CreateDevice(D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
NULL,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,
&g_pD3Ddev);
if(FAILED(hr))
return hr;
hr = 0;
// Create font object:
hr = D3DXCreateFont(g_pD3Ddev, 20, 5, FW_BOLD, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, TEXT("Arial"), &g_pD3DFont);

if(FAILED(hr))
return hr;
// Purple background:
hr = g_pD3Ddev->Clear(0,
NULL,
D3DCLEAR_TARGET,
D3DCOLOR_XRGB(100, 0, 255),
1.0f,
0);
if(FAILED(hr))
return hr;
return D3D_OK;
}
HRESULT D3D_Display()
{
char Text[] = "Hello World!"; // Text to output
HRESULT hr = 0; // Function return code(s)
D3DCOLOR fontColor = D3DCOLOR_ARGB(255,0,255,0); // Red text (A, R, G, B)
// Create a rectangle to indicate where on the screen the text shall be drawn:
RECT rct;
ZeroMemory(&rct, sizeof(RECT));
rct.left = 2;
rct.right = 50;
rct.top = 10;
rct.bottom = rct.top + 20;
if(g_pD3DFont->DrawText(NULL, Text, sizeof(Text), &rct, 0, fontColor) == 0)
#ifdef DEBUG
// Only perform if DEBUG mode is specified:
MessageBox(g_hWnd, "DrawText function failed!", "D3D_Display", MB_ICONEXCLAMATION | MB_OK);
#else
return false;
#endif
hr = g_pD3Ddev->Present(NULL, NULL, NULL, NULL);
if(FAILED(hr))
return hr;
}
bool D3D_Cleanup()
{
if(g_pD3DFont)
g_pD3DFont->Release();
if(g_pD3Ddev)
g_pD3Ddev->Release();
if(g_pD3D)
g_pD3D->Release();
if(!g_pD3DFont && !g_pD3Ddev && !g_pD3D)
return true;
else
return false;
}
[/CODE]
0

Share this post


Link to post
Share on other sites
ok, you need to fill the first parameter to DrawText method which is a pointer to an existing ID3DXSprite interface. Use D3DXCreateSprite to do so. And after that:

[code] // Prepare the device for drawing sprites
if(SUCCEEDED(m_pD3DXSprite->Begin(D3DXSPRITE_SORT_TEXTURE | D3DXSPRITE_ALPHABLEND)))
{
// Render data on the screen
m_pD3DXFont->DrawText(m_pD3DXSprite, m_szFPSData, -1, &oClientRect[0], 0, 0xFFFFFFFF); // FPS data
m_pD3DXFont->DrawText(m_pD3DXSprite, m_oString.data(), -1, &oClientRect[1], 0, 0XFFFF0000); // Specified string

// End target sprite drawing
m_pD3DXSprite->End();
}[/code]
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0