Jump to content
  • Advertisement
Sign in to follow this  
NecoSpes

D3DXSprite Help

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

I think I have everything... Unless I need a vertex buffer, FVF, etc. Or maybe something else. Naruto.bmp exists and is in the folder of my project. A good tutorial would help too. :D Thanks in advance! Oh yes. The problem is that it doesn't draw anything D:.
//Tetris 
#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <windowsx.h>
#include <iostream>
#include <d3d9.h>
#include <d3dx9.h>

#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")

#define WINDOWCLASS "winclass"

#define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)

struct CUSTOMVERTEX
{
    FLOAT x, y, z, rhw;    // from the D3DFVF_XYZRHW flag
    DWORD color;    // from the D3DFVF_DIFFUSE flag
};


HWND winhwnd;
LPDIRECT3D9 d3d;
LPDIRECT3DDEVICE9 d3ddev;
D3DPRESENT_PARAMETERS d3dpp;
ID3DXSprite *pSprite = NULL;
LPDIRECT3DTEXTURE9 naruto;

int game_init();
int game_main();
int game_end();

class square
{
public:
	square();
private:
	int x, y;
};

square::square()
{
}

HRESULT CALLBACK WinProc(HWND hwnd,
						 UINT msg,
						 WPARAM wparam,
						 LPARAM lparam)
{
	switch(msg)
	{
	case WM_DESTROY:
		{
			PostQuitMessage(0);
			return 0;
		}break;
	}

	return DefWindowProc(hwnd, msg, wparam, lparam);
}

int WINAPI WinMain(HINSTANCE hinstance,
				   HINSTANCE hprevinstance,
				   LPSTR lpcmdline,
				   int ncmdshow)
{
	MSG msg;
	WNDCLASSEX winclass;
	HWND hwnd;
	winclass.cbClsExtra = 0;
	winclass.cbSize = sizeof(WNDCLASSEX);
	winclass.cbWndExtra = 0;
	winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
	winclass.hCursor = LoadCursor(NULL, IDC_ARROW);
	winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
	winclass.hInstance = hinstance;
	winclass.lpfnWndProc = WinProc;
	winclass.lpszClassName = WINDOWCLASS;
	winclass.lpszMenuName = NULL;
	winclass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_OWNDC;
	if(!(RegisterClassEx(&winclass)))
		return 0;

	if(!(hwnd = CreateWindowEx(NULL, WINDOWCLASS, "X-Tris", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0,0, 800, 600, NULL, NULL, hinstance, NULL )))
		return 0;

	while(true)
	{
		if(PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE))
		{
			if(msg.message == WM_QUIT)
				break;
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

	return msg.wParam;
}

int game_init()
{
	d3d = Direct3DCreate9(D3D_SDK_VERSION);

	ZeroMemory(&d3dpp, sizeof(d3dpp));
	d3dpp.Windowed = true;
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dpp.hDeviceWindow = winhwnd;
	d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, winhwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev);
	
	

	if(FAILED(D3DXCreateSprite(d3ddev, &pSprite)))
		return 0;
	D3DXCreateTextureFromFile(d3ddev, "Naruto.bmp", &naruto);
	d3ddev->SetTexture(0, naruto); 
	return 0;
}
int game_main()
{
	d3ddev->Clear(0,NULL,D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f,0);
	
	d3ddev->BeginScene();
	pSprite->Begin(NULL);
	pSprite->Draw(naruto, NULL, NULL, &D3DXVECTOR3(1,1,1),0xFFFFFFFF); 
	
	pSprite->End();
	d3ddev->EndScene();
	d3ddev->Present(NULL,NULL,NULL,NULL);
	return 0;
}
int game_end()
{
	d3d->Release();
	d3ddev->Release();
	return 0;
}



[Edited by - NecoSpes on October 18, 2006 7:58:00 PM]

Share this post


Link to post
Share on other sites
Advertisement
I'm assuming that this is not all the codes in your program and that you've done all other things to get directx and a window going, I do not see any function calls in your game loop to use the functions you've defined.

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!