Sign in to follow this  
Knight52

[D3D9] Vertex Translation problem

Recommended Posts

I'm not sure if I should post this in beginner's forum, but I'm doing it here.

I'm trying to move this square to the right, but it just doesn't move and I have no idea where I went wrong.

Here's the code I think it's relevant:
[code]#include <Windows.h>
#include <WindowsX.h>
#include <d3d9.h>
#include <d3dx9.h>

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

#define SCREEN_HEIGHT 768
#define SCREEN_WIDTH 1024
#define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)

LPDIRECT3D9 d3d;
LPDIRECT3DDEVICE9 d3dDevice;
LPDIRECT3DVERTEXBUFFER9 vBuffer;

DWORD Color_A = 0xff00ff00,
Color_B = D3DCOLOR_ARGB(136, 255, 0, 204);

void loadContent();
void initializeD3D(HWND hwnd);
void initializeGraphic(void);
void initializeLight();
void draw(void);
void update();
void flushD3D(void);
LRESULT CALLBACK WindowProc(HWND hwnd, unsigned int message, WPARAM wParam, LPARAM lParam);

struct CustomVertex
{
float x, y, z, rhw;
DWORD alpha;
} theVertex[] = {
{ 100.0f, 100.0f, 0.5, 1, D3DCOLOR_ARGB(255, 0, 0, 255) },
{ 500.0f, 100.0f, 0.5, 1, D3DCOLOR_ARGB(255, 0, 255, 0) },
{ 500.0f, 500.0f, 0.5, 1, D3DCOLOR_ARGB(255, 255, 0, 0), },
{ 100.0f, 500.0f, 0.5, 1, D3DCOLOR_ARGB(255, 0, 255, 255)},
};
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{.....
}
LRESULT CALLBACK WindowProc(HWND hwnd, unsigned int message, WPARAM wParam, LPARAM lParam)
{.....
}
void loadContent()
{ }
void initializeD3D(HWND hwnd)
{
d3d = Direct3DCreate9(D3D_SDK_VERSION);
D3DPRESENT_PARAMETERS param;
ZeroMemory(&param, sizeof(D3DPRESENT_PARAMETERS));
param.Windowed = true;
param.SwapEffect = D3DSWAPEFFECT_DISCARD;
param.hDeviceWindow = hwnd;
param.BackBufferFormat = D3DFMT_X8R8G8B8;
param.BackBufferWidth = SCREEN_WIDTH;
param.BackBufferHeight = SCREEN_HEIGHT;
d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &param, &d3dDevice);
initializeGraphic();
d3dDevice->SetRenderState(D3DRS_LIGHTING, false);
}
void initializeGraphic(void)
{
d3dDevice->CreateVertexBuffer(4*sizeof(CustomVertex), 0, CUSTOMFVF, D3DPOOL_MANAGED, &vBuffer, NULL);
void* pVoid;
vBuffer->Lock(0, 0, (void**)&pVoid, 0);
memcpy(pVoid, theVertex, sizeof(theVertex));
vBuffer->Unlock();
}
void draw(void)
{
d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, 0xffffffff, 1, 0);
d3dDevice->BeginScene();

d3dDevice->SetFVF(CUSTOMFVF);
static float index = 0; index += 1;// ------------ where I started
d3dDevice->SetStreamSource(0, vBuffer, 0, sizeof(CustomVertex));
D3DXMATRIX matTran;
D3DXMatrixTranslation(&matTran, index, 0, 0);/// ------------------ where I finished
d3dDevice->SetTransform(D3DTS_WORLD, &matTran);
d3dDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 2);

d3dDevice->EndScene();
d3dDevice->Present(NULL, NULL, NULL, NULL);
}
void flushD3D(void)
{
vBuffer->Release();
d3dDevice->Release();
d3d->Release();
}[/code]

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