Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


theJ89

Member Since 04 Sep 2006
Offline Last Active Jul 29 2011 04:12 PM

Topics I've Started

Swapping between 2D and 3D drawing modes

19 May 2010 - 11:23 PM

Hello again, GameDev. Here's a bit of background behind what I'm trying to accomplish: After rendering my 3D game world I want to render a simple 2D HUD on top of that. To start, I want to draw a simple, untextured solid triangle to the screen. The problem is I'm not really sure how to approach this. In the past, I've used an XYZ vertex format for 3D drawing and an XYZRHW vertex format for 2D drawing. Does this mean I'll have to swap between vertex formats to swap between 3D and 2D drawing? Or is it better to just set up the view/projection matrices in such a way to accomplish the same effect? Second issue, render states and matrices. Anything I should reset before swapping to 2D drawing? Any other pitfalls I should look out for? Thanks for your time, theJ89

Window using up 50% of my processor?

21 January 2007 - 08:01 PM

Hey, recently I've taken to making an application that uses Direct 3D to draw a rotating cube. I've initilized Direct X, set up the matrices, and drawn my cube with the vertex buffer and index buffer. However, whenever I start the application, it uses up 50% of my processor! Why is this? Here is the source code:
#include <windows.h>
#include <d3d9.h>
#include <d3dx9.h>
#include <time.h>

#define WIN32_LEAN_AND_MEAN

//Vertex FVF and Vertex Structure
const DWORD VERTEX_FLAGS = (D3DFVF_XYZ | D3DFVF_DIFFUSE);

struct Vertex3D
{
	float x,y,z;
	D3DCOLOR color;
};

//Application Name
const LPCTSTR pszAppName="theJ89's Direct3D Test";

//Instance and Window
HINSTANCE hInst=NULL;
HWND hWnd=NULL;
bool bRun=true;
float i=0.0f;
//Direct3D interfaces.
IDirect3D9*				d3d=NULL;
IDirect3DDevice9*		d3dDevice=NULL;
IDirect3DVertexBuffer9*	d3dVertexBuffer=NULL;
IDirect3DIndexBuffer9*	d3dIndexBuffer=NULL;

//Vertices
Vertex3D cubeVerts[] =
{
	{-1.0f, 1.0f,-1.0f,  D3DCOLOR_COLORVALUE( 1.0, 0.0, 0.0, 1.0 ) }, // 0
	{ 1.0f, 1.0f,-1.0f,  D3DCOLOR_COLORVALUE( 0.0, 1.0, 0.0, 1.0 ) }, // 1
	{-1.0f,-1.0f,-1.0f,  D3DCOLOR_COLORVALUE( 0.0, 0.0, 1.0, 1.0 ) }, // 2
	{ 1.0f,-1.0f,-1.0f,  D3DCOLOR_COLORVALUE( 1.0, 1.0, 0.0, 1.0 ) }, // 3
	{-1.0f, 1.0f, 1.0f,  D3DCOLOR_COLORVALUE( 1.0, 0.0, 1.0, 1.0 ) }, // 4
	{-1.0f,-1.0f, 1.0f,  D3DCOLOR_COLORVALUE( 0.0, 1.0, 1.0, 1.0 ) }, // 5
	{ 1.0f, 1.0f, 1.0f,  D3DCOLOR_COLORVALUE( 1.0, 1.0, 1.0, 1.0 ) }, // 6
	{ 1.0f,-1.0f, 1.0f,  D3DCOLOR_COLORVALUE( 1.0, 0.0, 0.0, 1.0 ) }  // 7
};

//Indices
WORD cubeIndices[] =
{
	0, 1, 2, 3, // Quad 0
	4, 5, 6, 7, //      1
	4, 6, 0, 1, //      2
	5, 2, 7, 3, //      3
	1, 6, 3, 7, //      4
	0, 2, 4, 5  //      5
};

//Alert displays a message box with the name of the application, an "OK" button, an exclamation mark and the intended message.
void Alert(LPCTSTR pszMessage)
{
	if(hWnd!=NULL){
		MessageBox(hWnd,pszMessage,pszAppName,MB_OK | MB_ICONEXCLAMATION);
	} else {
		MessageBox(NULL,pszMessage,pszAppName,MB_OK | MB_ICONEXCLAMATION);
	}
}

//Confirm is like alert, but instead it has a question icon, yes/no buttons, and it returns the user's choice - true for yes and false for no.
bool Confirm(LPCTSTR pszMessage)
{
	int returnedValue=0;
	if(hWnd!=NULL){
		returnedValue=MessageBox(hWnd,pszMessage,pszAppName,MB_YESNO | MB_ICONQUESTION);
	} else {
		returnedValue=MessageBox(NULL,pszMessage,pszAppName,MB_YESNO | MB_ICONQUESTION);
	}
	if(returnedValue==IDYES){
		return true;
	} else {
		return false;
	}
}
//Message Handler for windows
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
{
	switch(uMessage)
	{
	case WM_DESTROY:
		bRun=false;
		break;
	case WM_LBUTTONDOWN:
		if(Confirm("Do you want to quit now?")){
			bRun=false;
		}
		break;
	default:
		break;
	}
	return DefWindowProc(hWnd,uMessage,wParam,lParam);
}
HRESULT MakeWindow(HINSTANCE hInstance)
{
	WNDCLASSEX wc;
	wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = NULL;
    wc.hCursor = NULL;
    wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = "DXTest3D";
    wc.hIconSm = NULL;
	
	if(!RegisterClassEx(&wc)){
        Alert("Could not register window class.");
		return E_FAIL;
	}

	if(!(hWnd=CreateWindowEx(NULL,"DXTest3D",pszAppName,WS_CAPTION | WS_VISIBLE,0,0,640,480,NULL,NULL,hInstance,NULL))){
		Alert("Could not create window.");
		return E_FAIL;
	}
	return true;
}
HRESULT InitD3D()
{
	//Create D3D interface
	if(NULL==(d3d=Direct3DCreate9(D3D_SDK_VERSION))){
		Alert("D3D failed to initilize!");
		return E_FAIL;
	}

	//Adapter information, need this for presentation params below to get backbuffer format
	D3DDISPLAYMODE d3ddm;
    d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&d3ddm);

	//Presentation Params
    D3DPRESENT_PARAMETERS d3dpp;
    ZeroMemory( &d3dpp, sizeof(d3dpp) );
    d3dpp.Windowed               = TRUE;
    d3dpp.SwapEffect             = D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat       = d3ddm.Format;
    d3dpp.EnableAutoDepthStencil = TRUE;
    d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
    d3dpp.PresentationInterval   = D3DPRESENT_INTERVAL_IMMEDIATE;

	//Create D3D Device Interface to let us do most Direct 3D related things. Presentation params above are passed to this.
	if(FAILED(d3d->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,D3DCREATE_HARDWARE_VERTEXPROCESSING,&d3dpp,&d3dDevice)))
	{
		Alert("D3D failed to create the device!");
		return E_FAIL;
	}

	d3dDevice->SetRenderState(D3DRS_LIGHTING,false);
	d3dDevice->SetRenderState(D3DRS_ZENABLE,true);

	D3DXMATRIX matProj;
	D3DXMatrixPerspectiveFovLH( &matProj, D3DXToRadian( 45.0f ), 640.0f / 480.0f, 0.1f, 100.0f );
	d3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );

	if(FAILED(d3dDevice->CreateVertexBuffer(8*sizeof(Vertex3D),D3DUSAGE_WRITEONLY,VERTEX_FLAGS,D3DPOOL_DEFAULT,&d3dVertexBuffer,NULL)))
	{
		Alert("D3D failed to create the vertex buffer!");
		return E_FAIL;
	}

	//This is (I think) the location of the vertex buffer on video memory. Lock sets this on the line below.
	void* pVerts=NULL;
	d3dVertexBuffer->Lock(0,sizeof(cubeVerts),(void**)&pVerts,0);
	memcpy(pVerts,cubeVerts,sizeof(cubeVerts));
	d3dVertexBuffer->Unlock();

	if(FAILED(d3dDevice->CreateIndexBuffer(24*sizeof(WORD),D3DUSAGE_WRITEONLY,D3DFMT_INDEX16,D3DPOOL_DEFAULT,&d3dIndexBuffer,NULL)))
	{
		Alert("D3D failed to create the index buffer!");
		return E_FAIL;
	}

	//This is (I think) the location of the index buffer on video memory. Lock sets this on the line below.
	WORD* pIndices = NULL;
	d3dIndexBuffer->Lock(0,sizeof(cubeIndices),(void**)&pIndices,0);
	memcpy(pIndices,cubeIndices,sizeof(cubeIndices));
	d3dIndexBuffer->Unlock();
	return S_OK;
}

void render()
{
	d3dDevice->Clear(0,NULL,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,D3DCOLOR_XRGB(0,0,0),1.0f,0);
	
	D3DXMATRIX matTrans;
	D3DXMATRIX matRot;
	D3DXMATRIX matWorld;

	D3DXMatrixTranslation( &matTrans, 0.0f, 0.0f, 5.0f+(i/25) );

	//D3DXToRadian()
	i=i+0.02f;
	if(i>=360.0f){
		i=i-360.0f;
	}
	D3DXMatrixRotationYawPitchRoll( &matRot,
		                            D3DXToRadian(i),
		                            D3DXToRadian(i),
		                            0);
	matWorld = matRot * matTrans;
	d3dDevice->SetTransform( D3DTS_WORLD, &matWorld );

    d3dDevice->BeginScene();
	
	d3dDevice->SetStreamSource( 0, d3dVertexBuffer, 0, sizeof(Vertex3D) );
	d3dDevice->SetIndices(d3dIndexBuffer);
	d3dDevice->SetFVF(VERTEX_FLAGS);

	d3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLESTRIP, 0, 0, 8,  0, 2 );
	d3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLESTRIP, 0, 0, 8,  4, 2 );
	d3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLESTRIP, 0, 0, 8,  8, 2 );
	d3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLESTRIP, 0, 0, 8, 12, 2 );
	d3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLESTRIP, 0, 0, 8, 16, 2 );
	d3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLESTRIP, 0, 0, 8, 20, 2 );

	d3dDevice->EndScene();
	d3dDevice->Present(NULL,NULL,NULL,NULL);
}

void shutDown( void )
{
	if( d3dIndexBuffer!=NULL)
		d3dIndexBuffer->Release();

    if(d3dVertexBuffer!=NULL)
		d3dVertexBuffer->Release(); 
    if(d3dDevice!=NULL)
		d3dDevice->Release();
    if( d3d!=NULL )
        d3d->Release();
}
//Main windows function. Message loop, initilizes Direct X and renders the scene.
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCommandLine, int nCommandShow)
{
	MSG msg;
	hInst=hInstance;
	ZeroMemory(&msg,sizeof(msg));

	if(FAILED(MakeWindow(hInst))){
		shutDown();
		return 0;
	}

	if(FAILED(InitD3D())){
		shutDown();
		return 0;
	}
	
	while(bRun)
    {
        //Exactly what is the difference between PeekMessage and GetMessage?
        if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
		render();
	}

	shutDown();
	return 1;
}

The example I was following: http://www.codesampler.com/dx9src/dx9src_2.htm#dx9_indexed_geometry If you need any additional information, just ask.

Help me with my application?

26 September 2006 - 06:12 AM

Hello. I'm finally completed with my first application in Direct X. However I get the feeling that it's really messy and inefficent. Would anybody like to help me out?

I've got the actual application and source code posted at this location.
http://www.guilddnr.net/dunescape/d3d_app.rar (this code was compiled with Visual C++ .NET 2003 edition, with the Direct X 9.0c SDK)

Additionally, here is the code plainly:
//theJ89's Direct X Test and window creation program
#include <windows.h>	//Includes windows,
#include <d3d9.h>		//D3D,
#include <time.h>		//D3D,
#include <d3dx9.h>		//D3D,
#include <dxerr9.h>		//and the D3D error handler?

//Removes rarely used things in windows.
#define WIN32_LEAN_AND_MEAN
//Describes the format of the vertex...
//Even though I make my own custom vertex structure I think it has to conform to these specifications.
#define POINT_FLAGS (D3DFVF_XYZRHW | D3DFVF_TEX1)

//Width and height of the menu along with the name of my program.
#define APP_NAME "theJ89's DirectX Test Program"
#define SCREEN_WIDTH 1024
#define SCREEN_HEIGHT 768
#define MAX_TEXTURES 16
#define MAX_QUADS 256

//Window and instance pointers
HWND window;
HINSTANCE hInst;

//Program stops running when bRun is set to false
bool bRun=true;

//Alert displays a message box with the name of the application, an "OK" button, an exclamation mark and the intended message.
void Alert(LPCTSTR lpMessage)
{
	ShowCursor(true);
	if(window!=NULL){
		MessageBox(window,lpMessage,APP_NAME,MB_OK | MB_ICONEXCLAMATION);
	} else {
		MessageBox(NULL,lpMessage,APP_NAME,MB_OK | MB_ICONEXCLAMATION);
	}
	ShowCursor(false);
}

//Confirm is like alert, but instead it has a question icon, yes/no buttons, and it returns the user's choice - true for yes and false for no.
bool Confirm(LPCTSTR lpMessage)
{
	ShowCursor(true);
	int returnedValue=0;
	if(window!=NULL){
		returnedValue=MessageBox(window,lpMessage,APP_NAME,MB_YESNO | MB_ICONQUESTION);
	} else {
		returnedValue=MessageBox(NULL,lpMessage,APP_NAME,MB_YESNO | MB_ICONQUESTION);
	}
	ShowCursor(false);
	if(returnedValue==IDYES){
		return true;
	} else {
		return false;
	}
	
}

//This is my vertex format, according to the second DX3D tutorial. It's got X, Y, and Z along with a reciprocol homogeneous w component and the color.
struct Vertex2D
{
	float x,y,z,rhw,u,v;
	D3DCOLOR color;
};
//This is my array of vertices, arranged like so:
/*
1----2
|  / |
| /  |
0----3
*/
Vertex2D vertices[MAX_QUADS*4];


class Image
{
public:
	Image();
	Image(float x, float y, float width, float height, IDirect3DTexture9* cTex);
	~Image();
	void Move(float x, float y);
	void UpdateVerts();

	bool show;
	float x,y,width,height,rotation;
	short unsigned int index;
	D3DCOLOR color;
	IDirect3DTexture9* cSource;
};

Image* cImages[MAX_QUADS];

Image::Image()
{
	//Init index to -1; find open slot.
	int oIndex=-1;
	for(int i=0; i<MAX_QUADS&&oIndex<0; i++)
	{
		if(cImages[i]==NULL)
		{
			oIndex=i;
		}
	}
	if(oIndex<0)
	{
		Alert("Attempted to create image but no open slots.");
		return;
	}
	else
	{
		index=oIndex;
	}
	cImages[index]=this;

	this->show=false;
	this->cSource=NULL;
	this->x=0;
	this->y=0;
	this->width=0;
	this->height=0;
	this->rotation=0.0f;
	
	//Set U, V coordinates and RHW, Z, and Color to defaults
	vertices[(index*4)].u=0.0f;
	vertices[(index*4)].v=1.0f;
	vertices[(index*4)+1].u=0.0f;
	vertices[(index*4)+1].v=0.0f;
	vertices[(index*4)+2].u=1.0f;
	vertices[(index*4)+2].v=0.0f;
	vertices[(index*4)+3].u=1.0f;
	vertices[(index*4)+3].v=1.0f;
	for(int i=0; i<4; i++)
	{
		vertices[(index*4)+i].rhw=1.0f;
		vertices[(index*4)+i].z=1.0f;
		vertices[(index*4)+i].color=0xFFFFFFFF;
	}
	//Set X/Y positions
	UpdateVerts();
}

Image::Image(float x, float y, float width, float height, IDirect3DTexture9* cTex)
{
	//Init index to -1; find open slot.
	int oIndex=-1;
	for(int i=0; i<MAX_QUADS&&oIndex<0; i++)
	{
		if(cImages[i]==NULL)
		{
			oIndex=i;
		}
	}
	if(oIndex<0)
	{
		Alert("Attempted to create image but no open slots.");
		return;
	}
	else
	{
		index=oIndex;
	}
	cImages[index]=this;

	this->show=true;
	this->cSource=cTex;
	this->x=x;
	this->y=y;
	this->width=width;
	this->height=height;
	this->rotation=0.0f;
	
	//Set U, V coordinates and RHW, Z, and Color to defaults
	vertices[(index*4)].u=0.0f;
	vertices[(index*4)].v=1.0f;
	vertices[(index*4)+1].u=0.0f;
	vertices[(index*4)+1].v=0.0f;
	vertices[(index*4)+2].u=1.0f;
	vertices[(index*4)+2].v=0.0f;
	vertices[(index*4)+3].u=1.0f;
	vertices[(index*4)+3].v=1.0f;
	for(int i=0; i<4; i++)
	{
		vertices[(index*4)+i].rhw=1.0f;
		vertices[(index*4)+i].z=1.0f;
		vertices[(index*4)+i].color=0xFFFFFFFF;
	}
	//Set X/Y positions
	UpdateVerts();
}

Image::~Image()
{
	cImages[index]=NULL;
}

void Image::Move(float x, float y)
{
	this->x=x;
	this->y=y;
	UpdateVerts();
}
void Image::UpdateVerts()
{
	vertices[(index*4)].x=x;
	vertices[(index*4)].y=y+height;
	vertices[(index*4)+1].x=x;
	vertices[(index*4)+1].y=y;
	vertices[(index*4)+2].x=x+width;
	vertices[(index*4)+2].y=y;
	vertices[(index*4)+3].x=x+width;
	vertices[(index*4)+3].y=y+height;
}

//DXGraphics is my singleton class to handle the Direct 3D interface, the device, the vertex buffer, rendering, and manage creation and cleanup.
//Currently I have the Render function set to draw a triangle fan that forms a rect as you can tell by the vertices.
class DXGraphics
{
public:
	IDirect3DTexture9* d3dTextures[MAX_TEXTURES];

	//Constructor, makes sure all pointers are initilized to NULL
	DXGraphics()
	{
		d3d=NULL;
		d3dDevice=NULL;
		d3dVertexBuffer=NULL;
		for(int i=0; i<MAX_TEXTURES; i++)
		{
			d3dTextures[i]=NULL;
		}
	}
	//Destructor, releases the vertex buffers, device, and d3d interface
	~DXGraphics()
	{
		for(int i=0; i<MAX_TEXTURES; i++)
		{
			if(d3dTextures[i]!=NULL)
				d3dTextures[i]->Release();
		}
		if(d3dVertexBuffer!=NULL)
			d3dVertexBuffer->Release();
		if(d3dDevice!=NULL)
			d3dDevice->Release();
		if(d3d!=NULL)
			d3d->Release();
	}
	//Initilizes the interface and allows me to create the device...
	HRESULT createD3D()
	{
		if(NULL==(d3d=Direct3DCreate9(D3D_SDK_VERSION)))
		{
			Alert("Could not create Direct3D object.");
			return E_FAIL;
		}
		Alert("Successfully created Direct3D object!");
		return S_OK;
	}
	//Creates the device used to handle... um, pretty much everything.
	HRESULT createDevice()
	{
		D3DPRESENT_PARAMETERS d3dPresent;
		ZeroMemory(&d3dPresent,sizeof(d3dPresent));
		d3dPresent.Windowed=TRUE;
		d3dPresent.SwapEffect=D3DSWAPEFFECT_DISCARD;
		d3dPresent.BackBufferFormat=D3DFMT_UNKNOWN;
		
		if( FAILED( d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dPresent, &d3dDevice)))
		{
			Alert("Could not create device!");
			return E_FAIL;
		}
		Alert("Created device successfully!");
		d3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
		d3dDevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
		d3dDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);
		d3dDevice->SetFVF(POINT_FLAGS);
		return S_OK;
	}
	HRESULT loadTexture(const char* pszImgPath)
	{
		int iEmpty=-1;
		char message[255];
		char cBuffer[33];
		ZeroMemory(&message,sizeof(message));
		for(int i=0; i<MAX_TEXTURES&&iEmpty<0; i++)
		{
			if(d3dTextures[i]==NULL)
				iEmpty=i;
		}
		if(iEmpty<0)
		{
			strcat(message, "Cannot load texture ");
			strcat(message, pszImgPath);
			strcat(message, " - No available slots.");
			Alert(message);
			return E_FAIL;
		}

			
		if(FAILED(D3DXCreateTextureFromFile(d3dDevice, pszImgPath, &d3dTextures[iEmpty]))){
			strcat(message, "Attempting to load texture ");
			strcat(message, pszImgPath);
			strcat(message, " has failed.");
			Alert(message);
			return E_FAIL;
		}
		strcat(message, "Loading texture ");
		strcat(message, pszImgPath);
		itoa(iEmpty,cBuffer,10);
		strcat(message, "(slot ");
		strcat(message, cBuffer);
		strcat(message, ")");
		strcat(message, " has succeeded!");
		Alert(message);
		return S_OK;
	}
	//Creates a vertex buffer for my polygons.
	HRESULT createVertexBuffer()
	{
		if( FAILED( d3dDevice->CreateVertexBuffer(MAX_QUADS*4*sizeof(Vertex2D),0, POINT_FLAGS, D3DPOOL_DEFAULT, &d3dVertexBuffer, NULL ) ) )
		{
			Alert("Could not create vertex buffer!");
			return E_FAIL;
		}
		Alert("Created vertex buffer!");
		return S_OK;
	}
	//Copies the vertexes from the array in physical memory to the buffer on video memory, if I understood that correctly.
	HRESULT fillVertexBuffer()
	{
		VOID* pVertices;
		if(FAILED(d3dVertexBuffer->Lock(0,sizeof(vertices),(void**)&pVertices,0)))
		{
			Alert("Attempting to fill the vertex buffer has failed!");
			return E_FAIL;
		}
		memcpy(pVertices,vertices,sizeof(vertices));
		d3dVertexBuffer->Unlock();
		//Alert("The vertex buffer has been filled!");
		return S_OK;
	}
	//Clears the back buffer to black, starts drawing the scene,
	//sets the stream to the buffer, sets the vertex format (I don't think
	//it should be here but whatever works), and lastly draws the
	//primative - a triangle fan comprised of the four vertices.
	//From there it just ends the scene and displays it.
	void Render()
	{
		if(d3dDevice!=NULL)
		{
			d3dDevice->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,0,0),1.0f,0);
			if(SUCCEEDED(d3dDevice->BeginScene()))
			{
				d3dDevice->SetStreamSource(0,d3dVertexBuffer,0,sizeof(Vertex2D));
				for(int i=0;i<MAX_QUADS;i++)
				{
					if(cImages[i]!=NULL&&cImages[i]->show)
					{
						d3dDevice->SetTexture(0,cImages[i]->cSource);
						d3dDevice->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_SELECTARG1);
						d3dDevice->SetTextureStageState(0,D3DTSS_COLORARG1,D3DTA_TEXTURE);
						d3dDevice->SetTextureStageState(0,D3DTSS_COLORARG2,D3DTA_DIFFUSE);
						d3dDevice->SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_SELECTARG1);
						d3dDevice->SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_TEXTURE);
						d3dDevice->SetTextureStageState(0,D3DTSS_ALPHAARG2,D3DTA_DIFFUSE);
						d3dDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,i*4,2);
					}
				}
				d3dDevice->EndScene();
			}
			d3dDevice->Present(NULL,NULL,NULL,NULL);
		}
	}
private:
	IDirect3D9* d3d;
	IDirect3DDevice9* d3dDevice;
	IDirect3DVertexBuffer9* d3dVertexBuffer;
};

//Creates the singleton object that handles Direct3D
DXGraphics dx3d;

Image* pMyImage=NULL;
//Message Handler for windows
LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
{
	POINTS coords;
	switch(uMessage)
	{
	case WM_DESTROY:
		bRun=false;
		break;
	case WM_MOUSEMOVE:
        coords = MAKEPOINTS (lParam);
		if(pMyImage!=NULL) {
			pMyImage->Move(coords.x-16,coords.y-16);
		}
		break;
	case WM_LBUTTONDOWN:
		Alert("Left mouse button pressed. Goodbye!");
		bRun=false;
		break;
	/*
	case WM_PAINT:
		dx3d.Render();
		ValidateRect( hWnd, NULL );
		break;
	*/
	default:
		break;
	}
	return DefWindowProc(hWnd,uMessage,wParam,lParam);
}
//I made a function to create a window because I like having everything for this in one function.
int MakeWindow(HINSTANCE hInstance)
{
	WNDCLASSEX wc;
	wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = WindowProcedure;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = NULL;
    wc.hCursor = NULL;
    wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = "DXTest";
    wc.hIconSm = NULL;
	
	if(!RegisterClassEx(&wc))
        return false;
	window=CreateWindowEx(NULL,"DXTest",APP_NAME,WS_CAPTION | WS_VISIBLE,0,0,SCREEN_WIDTH,SCREEN_HEIGHT,NULL,NULL,hInstance,NULL);

	if(!window)
		return false;

	return true;
}
//Main windows function. Message loop, initilizes Direct X and renders the scene.
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCommandLine, int nCommandShow)
{
	MSG msg;
	hInst=hInstance;

	int iTime=time(NULL);
	int framecount=0;
	float fps=1;

	ZeroMemory(&vertices,sizeof(vertices));
	for(int i=0; i<MAX_QUADS; i++)
	{
		cImages[i]=NULL;
	}

	MakeWindow(hInst);
	ShowCursor(false);
	if(FAILED(dx3d.createD3D()))
		return 0;
	if(FAILED(dx3d.createDevice()))
		return 0;
	if(FAILED(dx3d.createVertexBuffer()))
		return 0;
	if(FAILED(dx3d.loadTexture("tex.tga")))
		return 0;
	if(FAILED(dx3d.loadTexture("cursor.tga")))
		return 0;
	
	Image MyImages[100]={
		Image(0,0,32,32,dx3d.d3dTextures[0]),
		Image(32,0,32,32,dx3d.d3dTextures[0]),
		Image(64,0,32,32,dx3d.d3dTextures[0]),
		Image(96,0,32,32,dx3d.d3dTextures[0]),
		Image(128,0,32,32,dx3d.d3dTextures[0]),
		Image(160,0,32,32,dx3d.d3dTextures[0]),
		Image(192,0,32,32,dx3d.d3dTextures[0]),
		Image(224,0,32,32,dx3d.d3dTextures[0]),
		Image(256,0,32,32,dx3d.d3dTextures[0]),
		Image(288,0,32,32,dx3d.d3dTextures[0]),

		Image(0,32,32,32,dx3d.d3dTextures[0]),
		Image(32,32,32,32,dx3d.d3dTextures[0]),
		Image(64,32,32,32,dx3d.d3dTextures[0]),
		Image(96,32,32,32,dx3d.d3dTextures[0]),
		Image(128,32,32,32,dx3d.d3dTextures[0]),
		Image(160,32,32,32,dx3d.d3dTextures[0]),
		Image(192,32,32,32,dx3d.d3dTextures[0]),
		Image(224,32,32,32,dx3d.d3dTextures[0]),
		Image(256,32,32,32,dx3d.d3dTextures[0]),
		Image(288,32,32,32,dx3d.d3dTextures[0]),

		Image(0,64,32,32,dx3d.d3dTextures[0]),
		Image(32,64,32,32,dx3d.d3dTextures[0]),
		Image(64,64,32,32,dx3d.d3dTextures[0]),
		Image(96,64,32,32,dx3d.d3dTextures[0]),
		Image(128,64,32,32,dx3d.d3dTextures[0]),
		Image(160,64,32,32,dx3d.d3dTextures[0]),
		Image(192,64,32,32,dx3d.d3dTextures[0]),
		Image(224,64,32,32,dx3d.d3dTextures[0]),
		Image(256,64,32,32,dx3d.d3dTextures[0]),
		Image(288,64,32,32,dx3d.d3dTextures[0]),

		Image(0,96,32,32,dx3d.d3dTextures[0]),
		Image(32,96,32,32,dx3d.d3dTextures[0]),
		Image(64,96,32,32,dx3d.d3dTextures[0]),
		Image(96,96,32,32,dx3d.d3dTextures[0]),
		Image(128,96,32,32,dx3d.d3dTextures[0]),
		Image(160,96,32,32,dx3d.d3dTextures[0]),
		Image(192,96,32,32,dx3d.d3dTextures[0]),
		Image(224,96,32,32,dx3d.d3dTextures[0]),
		Image(256,96,32,32,dx3d.d3dTextures[0]),
		Image(288,96,32,32,dx3d.d3dTextures[0]),

		Image(0,128,32,32,dx3d.d3dTextures[0]),
		Image(32,128,32,32,dx3d.d3dTextures[0]),
		Image(64,128,32,32,dx3d.d3dTextures[0]),
		Image(96,128,32,32,dx3d.d3dTextures[0]),
		Image(128,128,32,32,dx3d.d3dTextures[0]),
		Image(160,128,32,32,dx3d.d3dTextures[0]),
		Image(192,128,32,32,dx3d.d3dTextures[0]),
		Image(224,128,32,32,dx3d.d3dTextures[0]),
		Image(256,128,32,32,dx3d.d3dTextures[0]),
		Image(288,128,32,32,dx3d.d3dTextures[0]),

		Image(0,160,32,32,dx3d.d3dTextures[0]),
		Image(32,160,32,32,dx3d.d3dTextures[0]),
		Image(64,160,32,32,dx3d.d3dTextures[0]),
		Image(96,160,32,32,dx3d.d3dTextures[0]),
		Image(128,160,32,32,dx3d.d3dTextures[0]),
		Image(160,160,32,32,dx3d.d3dTextures[0]),
		Image(192,160,32,32,dx3d.d3dTextures[0]),
		Image(224,160,32,32,dx3d.d3dTextures[0]),
		Image(256,160,32,32,dx3d.d3dTextures[0]),
		Image(288,160,32,32,dx3d.d3dTextures[0]),

		Image(0,192,32,32,dx3d.d3dTextures[0]),
		Image(32,192,32,32,dx3d.d3dTextures[0]),
		Image(64,192,32,32,dx3d.d3dTextures[0]),
		Image(96,192,32,32,dx3d.d3dTextures[0]),
		Image(128,192,32,32,dx3d.d3dTextures[0]),
		Image(160,192,32,32,dx3d.d3dTextures[0]),
		Image(192,192,32,32,dx3d.d3dTextures[0]),
		Image(224,192,32,32,dx3d.d3dTextures[0]),
		Image(256,192,32,32,dx3d.d3dTextures[0]),
		Image(288,192,32,32,dx3d.d3dTextures[0]),

		Image(0,224,32,32,dx3d.d3dTextures[0]),
		Image(32,224,32,32,dx3d.d3dTextures[0]),
		Image(64,224,32,32,dx3d.d3dTextures[0]),
		Image(96,224,32,32,dx3d.d3dTextures[0]),
		Image(128,224,32,32,dx3d.d3dTextures[0]),
		Image(160,224,32,32,dx3d.d3dTextures[0]),
		Image(192,224,32,32,dx3d.d3dTextures[0]),
		Image(224,224,32,32,dx3d.d3dTextures[0]),
		Image(256,224,32,32,dx3d.d3dTextures[0]),
		Image(288,224,32,32,dx3d.d3dTextures[0]),

		Image(0,256,32,32,dx3d.d3dTextures[0]),
		Image(32,256,32,32,dx3d.d3dTextures[0]),
		Image(64,256,32,32,dx3d.d3dTextures[0]),
		Image(96,256,32,32,dx3d.d3dTextures[0]),
		Image(128,256,32,32,dx3d.d3dTextures[0]),
		Image(160,256,32,32,dx3d.d3dTextures[0]),
		Image(192,256,32,32,dx3d.d3dTextures[0]),
		Image(224,256,32,32,dx3d.d3dTextures[0]),
		Image(256,256,32,32,dx3d.d3dTextures[0]),
		Image(288,256,32,32,dx3d.d3dTextures[0]),

		Image(0,288,32,32,dx3d.d3dTextures[0]),
		Image(32,288,32,32,dx3d.d3dTextures[0]),
		Image(64,288,32,32,dx3d.d3dTextures[0]),
		Image(96,288,32,32,dx3d.d3dTextures[0]),
		Image(128,288,32,32,dx3d.d3dTextures[0]),
		Image(160,288,32,32,dx3d.d3dTextures[0]),
		Image(192,288,32,32,dx3d.d3dTextures[0]),
		Image(224,288,32,32,dx3d.d3dTextures[0]),
		Image(256,288,32,32,dx3d.d3dTextures[0]),
		Image(288,288,32,32,dx3d.d3dTextures[0])
	};

	Image Cursor=Image(288,288,32,32,dx3d.d3dTextures[1]);
	pMyImage=&Cursor;
	for(int i=0; i<100; i++)
	{
		MyImages[i];
	}
	

	while (bRun)
    {
		framecount++;
		if(time(NULL)>iTime) {
			fps=framecount;
			framecount=0;
		}
        //Exactly what is the difference between PeekMessage and GetMessage?
        if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
		//The vertex buffer is filled each frame because I used to have something that moved the vertexes one pixel each frame, and needed to refresh the buffer.
		dx3d.fillVertexBuffer();
		//Last step, render the scene with the singleton's functions.
		dx3d.Render();
	}

	return 0;
}





I've created two classes to handle Direct 3D, for the most part - DXGraphics and Image - and of course a custom struct for my vertex which contains x,y,z,rhw,u,v, and a D3DCOLOR. As you can tell by the RHW parameter, I am making a 2D application with Direct 3D.

I have defined the max number of quads (256 last I checked) and the max number of textures (16). These limits are set when the application is compiled.

The size of the vertex buffer, and the size of my global vertex array is equal to MAX_QUADS*4.

My class, DXGraphics, contains the array of textures (however it is not a static variable, instead it is simply an array of IDirect3DTexture9 the size of MAX_TEXTURES (16)).

Only one object is of the DXGraphics class, and I call it dx3d.

Whenever my DXGraphics object constructs, it sets all of it's interface pointers to NULL. Likewise it releases all of the interfaces not equal to NULL whenever it's destructed. It contains a D3D interface pointer, Device interface pointer, Vertex Buffer pointer, and of course 16 texture interface pointers for loaded textures (however at the time only two are used).

I have functions created for initilizing each of these interfaces. Additionally in DXGraphics there are also functions for filling the vertex buffer and rendering.

My image class, Image, is used to handle and display quads. Image contains the float variables X, Y, Width, Height, and Rotation. Additionally there is the integer value index, a boolean value show which determines if the Image is drawn, and a D3DCOLOR (also integer I believe but whatever) variable Color. The image class contains functions for constructing and destructing the Image class, Moving the image onscreen, and updating the vertices.

Every Image when constructed is automatically placed in the first available slot in a global array of Image pointers. Likewise when the Image is destructed the pointer is set to NULL. The vertices associated with the Image are determined by the Image's index in this array - so, if it's index was 5, then the vertices associated with it would be 20,21,22, and 23, because 5*4=20. This keeps track of the Images so that the renderer can know what vertices in the array to draw.

So far this setup has worked wonderfully for me, but I am very unexperienced and this is only a simple setup. Could you possibly give me some pointers?

[Edited by - theJ89 on September 26, 2006 4:32:07 PM]

Need help with texturing quads

16 September 2006 - 03:12 PM

I'm using Visual C++ 2003 and the DirectX 9 SDK to create a simple windows program that renders a quad in 2D. So far I've completed Tutorials 1 and 2 on MSDN for DirectX 9. Here is the code I have come up with so far: Edit: Sorry, new to the forums, didn't know about the "source" tag.
//theJ89's Direct X Test and window creation program
#include &lt;windows.h&gt;	//Includes windows,
#include &lt;d3d9.h&gt;		//D3D,
#include &lt;dxerr9.h&gt;		//and the D3D error handler?

//Removes rarely used things in windows.
#define WIN32_LEAN_AND_MEAN
//Describes the format of the vertex...
//Even though I make my own custom vertex structure I think it has to conform to these specifications.
#define POINT_FLAGS (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)

//Width and height of the menu along with the name of my program.
#define APP_NAME "theJ89's DirectX Test Program"
#define SCREEN_WIDTH 1024
#define SCREEN_HEIGHT 768

//Window and instance pointers
HWND window;
HINSTANCE hInst;

//Program stops running when bRun is set to false
bool bRun=true;

//Alert displays a message box with the name of the application, an "OK" button, an exclamation mark and the intended message.
void Alert(LPCTSTR lpMessage)
{
	if(window!=NULL){
		MessageBox(window,lpMessage,APP_NAME,MB_OK | MB_ICONEXCLAMATION);
	} else {
		MessageBox(NULL,lpMessage,APP_NAME,MB_OK | MB_ICONEXCLAMATION);
	}
}

//Confirm is like alert, but instead it has a question icon, yes/no buttons, and it returns the user's choice - true for yes and false for no.
bool Confirm(LPCTSTR lpMessage)
{
	int returnedValue=0;
	if(window!=NULL){
		returnedValue=MessageBox(window,lpMessage,APP_NAME,MB_YESNO | MB_ICONQUESTION);
	} else {
		returnedValue=MessageBox(NULL,lpMessage,APP_NAME,MB_YESNO | MB_ICONQUESTION);
	}
	if(returnedValue==IDYES){
		return true;
	} else {
		return false;
	}
}

//This is my vertex format, according to the second DX3D tutorial. It's got X, Y, and Z along with a reciprocol homogeneous w component and the color.
struct Vertex2D
{
	float x,y,z,rhw;
	D3DCOLOR color;
};

//This is my array of vertices, arranged like so:
/*
1----2
|  / |
| /  |
0----3
*/
Vertex2D vertices[] =
{
	{0.0f,		100.0f,	1.0f,	1.0f,	0xffffffff},
	{0.0f,		0.0f,	1.0f,	1.0f,	0xffffffff},
	{100.0f,	0.0f,	1.0f,	1.0f,	0xffffffff},
	{100.0f,	100.0f,	1.0f,	1.0f,	0xffffffff}
};

//DXGraphics is my singleton class to handle the Direct 3D interface, the device, the vertex buffer, rendering, and manage creation and cleanup.
//Currently I have the Render function set to draw a triangle fan that forms a rect as you can tell by the vertices.
class DXGraphics
{
public:
	//Constructor, makes sure all pointers are initilized to NULL
	DXGraphics()
	{
		d3d=NULL;
		d3dDevice=NULL;
		d3dVertexBuffer=NULL;
	}
	//Destructor, releases the vertex buffers, device, and d3d interface
	~DXGraphics()
	{
		if(d3dVertexBuffer!=NULL)
			d3dVertexBuffer-&gt;Release();
		if(d3dDevice!=NULL)
			d3dDevice-&gt;Release();
		if(d3d!=NULL)
			d3d-&gt;Release();
	}
	//Initilizes the interface and allows me to create the device...
	HRESULT createD3D()
	{
		if(NULL==(d3d=Direct3DCreate9(D3D_SDK_VERSION)))
		{
			Alert("Could not create Direct3D object.");
			return E_FAIL;
		}
		Alert("Successfully created Direct3D object!");
		return S_OK;
	}
	//Creates the device used to handle... um, pretty much everything.
	HRESULT createDevice()
	{
		D3DPRESENT_PARAMETERS d3dPresent;
		ZeroMemory(&d3dPresent,sizeof(d3dPresent));
		d3dPresent.Windowed=TRUE;
		d3dPresent.SwapEffect=D3DSWAPEFFECT_DISCARD;
		d3dPresent.BackBufferFormat=D3DFMT_UNKNOWN;
		
		if( FAILED( d3d-&gt;CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dPresent, &d3dDevice)))
		{
			Alert("Could not create device!");
			return S_OK;
		}
		Alert("Created device successfully!");
		return E_FAIL;
	}
	//Creates a vertex buffer for my polygons.
	HRESULT createVertexBuffer()
	{
		if( FAILED( d3dDevice-&gt;CreateVertexBuffer(4*sizeof(Vertex2D),0, POINT_FLAGS, D3DPOOL_DEFAULT, &d3dVertexBuffer, NULL ) ) )
		{
			Alert("Could not create vertex buffer!");
			return E_FAIL;
		}
		Alert("Created vertex buffer!");
		return S_OK;
	}
	//Copies the vertexes from the array in physical memory to the buffer on video memory, if I understood that correctly.
	HRESULT fillVertexBuffer()
	{
		VOID* pVertices;
		if(FAILED(d3dVertexBuffer-&gt;Lock(0,sizeof(vertices),(void**)&pVertices,0)))
		{
			Alert("Attempting to fill the vertex buffer has failed!");
			return E_FAIL;
		}
		memcpy(pVertices,vertices,sizeof(vertices));
		d3dVertexBuffer-&gt;Unlock();
		//Alert("The vertex buffer has been filled!");
		return S_OK;
	}
	//Clears the back buffer to black, starts drawing the scene, sets the stream to the buffer, sets the vertex format (I don't think it should be here but whatever works), and lastly draws the primative - a triangle fan comprised of the four vertices. From there it just ends the scene and displays it.
	void Render()
	{
		if(d3dDevice!=NULL)
		{
			d3dDevice-&gt;Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,0,0),1.0f,0);
			if(SUCCEEDED(d3dDevice-&gt;BeginScene()))
			{
				d3dDevice-&gt;SetStreamSource(0,d3dVertexBuffer,0,sizeof(Vertex2D));
				d3dDevice-&gt;SetFVF(POINT_FLAGS);
				d3dDevice-&gt;DrawPrimitive(D3DPT_TRIANGLEFAN,0,2);
				d3dDevice-&gt;EndScene();
			}
			d3dDevice-&gt;Present(NULL,NULL,NULL,NULL);
		}
	}
private:
	IDirect3D9* d3d;
	IDirect3DDevice9* d3dDevice;
	IDirect3DVertexBuffer9* d3dVertexBuffer;
};

//Creates the singleton object that handles Direct3D
DXGraphics dx3d;

//Message Handler for windows
LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
{
	switch(uMessage)
	{
	case WM_DESTROY:
		bRun=false;
		break;
	case WM_LBUTTONDOWN:
		Alert("Left mouse button pressed. Goodbye!");
		bRun=false;
		break;
	/*
	case WM_PAINT:
		dx3d.Render();
		ValidateRect( hWnd, NULL );
		break;
	*/
	default:
		break;
	}
	return DefWindowProc(hWnd,uMessage,wParam,lParam);
}
//I made a function to create a window because I like having everything for this in one function.
int MakeWindow(HINSTANCE hInstance)
{
	WNDCLASSEX wc;
	wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = WindowProcedure;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = NULL;
    wc.hCursor = NULL;
    wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = "DXTest";
    wc.hIconSm = NULL;

	if(!RegisterClassEx(&wc))
        return false;
	window=CreateWindowEx(NULL,"DXTest",APP_NAME,WS_CAPTION | WS_VISIBLE,0,0,SCREEN_WIDTH,SCREEN_HEIGHT,NULL,NULL,hInstance,NULL);

	if(!window)
		return false;

	return true;
}
//Main windows function. Message loop, initilizes Direct X and renders the scene.
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCommandLine, int nCommandShow)
{
	MSG msg;
	hInst=hInstance;
	MakeWindow(hInst);

	dx3d.createD3D();
	dx3d.createDevice();
	dx3d.createVertexBuffer();

	while (bRun)
    {
        //Exactly what is the difference between PeekMessage and GetMessage?
        if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
		//The vertex buffer is filled each frame because I used to have something that moved the vertexes one pixel each frame, and needed to refresh the buffer.
		dx3d.fillVertexBuffer();
		//Last step, render the scene with the singleton's functions.
		dx3d.Render();
	}
	return 0;
}

Now what I want to do is texture these quads. I have a 32x32 .tga that I want to use as a texture for the quad. However so far I can't find a tutorial for texturing quads using the XYZRHW vertex format... so, can somebody help me out here? [Edited by - theJ89 on September 16, 2006 9:32:24 PM]

Wanting to get into professional game coding

04 September 2006 - 03:23 PM

Hello, before I begin I'd like to give you a little bit of background on myself. I am not new to the game scene. Ever since I was 6 I've been playing games for the consoles - mostly RPGs such as Chrono Trigger, Secret of Mana, and Final Fantasy 2/3 (the US versions) for the SNES. I also played Legend of Zelda: A Link to the Past which personally I couldn't get enough of. This started my interest in videogames and to this day has not changed. When I was 8 we bought our first computer (an old gateway with a 4gb harddrive and 64mb of memory). It was around this time that I began to get into PC games. The first professional game I played for the PC was Command and Conquer, one of the best strategy games of all time. After Command and Conquer, an offshoot series was released called Command and Conquer: Red Alert. It was in this game that I got a chance to play online and things were never the same - an entire world of possibilities had been laid out before me! At the time the idea of being able to play games online, which before I had only played by myself was an awesome thought. Real people to play with or against. I made friends with people I played with online and as I played online I started learning the game terminology that I would come to swear by. Eventually, I got my hands on a third party map editor for Red Alert called C&C-RAED. I learned to create maps for Red Alert, host them on online games or play them singleplayer. I learned to mod the game through configuration files, tutorials on the net, other users and examples of modified maps. I created an entire Before that I explored Microsoft Word and found the Visual Basic editor that was included with it, and got a feel for designing UI, placing forms, buttons, tabs and the like and scripting in VBScript(although I have not scripted with VBScript for years, and my knowledge of how to do this has faded from disuse). I thought that it was really cool that I could figure out how to use Word to do this. At the time I didn't even know I was scripting but I knew that it was something that I liked to do and I was good at. Around this same time my sister gave me a Trial version of software called Hyperstudio, which I came to learn is a type of presentation software for schools. But as I looked around the sample projects in Hyperstudio, I noticed that there were some things that certain projects could do that I couldn't figure out. Then by going into edit and looking around, I found that they were using a scripting language called HyperScript. I started to write down some of the commands I could understand and then imitated what they had done in their projects in my own scripts - and I did. I learned how to move objects dynamically, make the script wait, take advantage of the system 'beep' sound, animate, display dialogs and more. I created one of my first games ever, a simple puzzle game that involved you having to drag and drop objects in the right places (this functionality was built into the software, I didn't script it). I used what I had learned from scripting to move, hide, or show things through scripting. There were other alternatives but I liked scripting because I had more control than what the UI of the program offered. Then, one of my friends introduced me to a game that I thought I would not like but ended up being a huge thing for me: Starcraft, Blizzard's futuristic RTS. This game was a huge deal for me. I started playing online before I even beat any of the single-player campaigns and what I found on Battle.net blew my mind! Hundreds upon thousands of user created maps! Huge masses of players, clans, several different gamemodes that differed from the campaigns that Blizzard had created for Starcraft. I played the game daily for hours on end, and it introduced me to one of my best friends. I was really stunned by the quality of some of these maps. Intricate RPGs on a realm-sized map, intense defense maps, competetive zone control, and free-form RP maps. I found the Starcraft Map editor and started to create simple maps, place units, and design terrain and forts. I found I could modify the names, attack and damage of the units in the unit editor. Even better, for the first time ever, I could edit scripts without scripting knowledge! Enter the trigger editor. I could issue commands without knowing a scripting language. There was a list where I could add commands, specify what events triggered the trigger, and add conditions to specify when this should happen. I got a feel for the nature of programming by working with triggers in mapping. I created over 50 maps (mostly based on spur-of-the-moment ideas) for starcraft that I can remember. I became an avid roleplayer when playing starcraft online and we composed epic adventures. I created three good maps for starcraft. One of them was an action map called Ghost Mansion 7 which was a team based escape map. The other was an epic roleplaying map called Realm of Dunescape, which at one time was one of the most popular maps on Battle.net, and a heavily modified version of that map called Realm of Mystica. While I was playing starcraft I was also getting into javascript, which I think all of you around here probably know is a popular scripting language used in the design of web pages. It was a steep learning curve but it was lessened by the fact that almost all scripts written for it are readable (some of them are encoded). I quickly learned from scripts I found around the internet, along with many available code samples from around the net and the many tutorials that existed on the net. I learned the basic routines from javascript - Arithmatic, for loops, setting and declaring variables, and so on. javascript also introduced me to Object Orientated Programming, which confused me at first but then I came to love. With the advent of DHTML, I could now fully manipulate all of the effects I could find in CSS with javascript. I found a code sample on the net that showed me how to change the position of an object on the screen. So, I used my HTML editor (Frontpage Express - it was a free version of Frontpage that Microsoft no longer supports) a blank page with a black background, created a .jpg in paint and created a script object that moved it to the very utmost top of the screen. I can still remember it:
imageObject.style.position="absolute";
imageObject.style.pixelLeft=0;
imageObject.style.pixelTop=0;
Using this knowledge along with my mapping and scripting experience and understanding of HTML I created a simple puzzle game I call "Twisted" (It's still hosted on my free site at http://www.angelfire.com/tv/jeffhut/ but the host has placed ads all over the place. Keep in mind I was only 10 when I made it, and my skills have improved). I was very much into playing Runescape (and I know how much people hate it but I thought it was a good game before they added the paid members accounts) so I created a game based off of what I saw in Runescape - Dunescape. Dunescape's name is a clear ripoff of Runescape obviously, but that's besides the point. Dunescape was my first ever major game project - I scripted it entirely, planned for it, drew maps, tables of items, their damages, defense ratings, planned math ahead, thought of how I would design the various systems and spent hours of my own time working in Frontpage Express and it's script editor designing the various systems. In addition to that I had to make my own art because I was no good at myself. I didn't have a gif animatior so I also did the animation myself. It was very poorly scripted because even then I was only a moderately experienced scripter and had never looked at any real reference, except for the W3C DOM. However I designed collision, tile triggers, map transitions, basic combat, a character settings manager, and even fooled with cookies to have it remember the player's stats. I made basic AI that made agressive enemies try to follow and then attack you. I bought Warcraft 3 and stopped playing Starcraft. I was involved in mapping for a while with it but ultimately it just was not what I had seen in Starcraft. However during the time that I did play starcraft, I created a nearly complete trigger guide which can be found here: http://www.wc3campaigns.net/showthread.php?t=17723 Tired with Warcraft 3 and nostalgic for the times where I worked on Dunescape, I started up on the Second version of it. I learned how to use 3DS Max to create models and then render them, and I acquired a better editor for graphics called Paint Shop Pro. My skills involving computer graphics as a whole improved and I learned a lot during this period. I also learned to use a little bit of PHP, enough to create a server-side player manager and, through an inefficent refresh-and-check for changes method I suddenly found a way to make Dunescape multiplayer. One page refreshed the content from the server, which fed it into the script that managed incoming data. It compared it with existing data and made changes accordingly. It sent data out by simply changing the request portion of the refresh page. It was a pretty hacky solution but it worked. Ultimately, however, I gave up on the project. It was too laggy, too unstable, and I lacked the effort to continue it. It was around this time that I started hearing about people who had modded a game called Half-Life - I had seldom heard about the game before, so I picked it up. It was really a thrilling game, even though it was created in 1996 and it was now 2001. Despite that, I scrutinized the game while I was playing it - observing the way the textures were mapped onto the surfaces of the polygons, observing back-face culling (although at the time I didn't know that was what it was) in action, Watching how the distinct lines of the polygons shifted while I moved, the acceleration and deceleration of the player as he moved, the actions of the alpha channels, the custom lighting, the NPCs, everything. It was a work of art that I was looking at. And then 2003 rolled around and Half-Life 2 was released - and I got a new computer - absolutely STUNNING! It blew away my former perceptions of what was possible in a computer game and motivated me to work on a third version of Dunescape. Still in HTML and javascript however the game suffered from the ineffecient structure of internet explorer. I finally realized, as I went along, that Internet Explorer was not the proper environment to be developing games in and it never was. Distraught over this appalling failure I wandered into the Garry's Mod community (http://forums.facepunchstudios.com/) and started to map for it, around version 7. I released one good map and several prefabs but I was not heavily involved in the community until Garry's Mod 9, the current release. Garry's Mod 9 added an instance of Lua to the source engine code, and Garry bound commands in the source engine to Lua. I quickly caught onto this and created the first Roleplay Mod for Garry's Mod. It was a hit until Underseeg released his. But, by creating this I was introduced to Lua. I found it to be a very simple language, and based on what I had seen in other languages. But, now that I've told you about what I've done and where I am now, I'll get to the real subject of my post... I am fairly new to the C++ language, although I feel I have a good grasp of it and have been able to make several successful console applications in the past. I do not have any experience with the Windows SDK or Direct X SDK. What I'm trying to accomplish is something pretty simple. I want to create a Windows Application by using C++ that initilizes Direct X fullscreen, loads a texture, and draws a quad to the screen. I've been following these two tutorials: http://www.flipcode.com/articles/article_guidedx82d.shtml http://www.gamedev.net/reference/articles/article1972.asp However I noticed that when I looked at the source files they accomplished a 2D perspective in different ways. Could somebody help me out here?

PARTNERS