Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


hstubbs3

Member Since 14 Jun 2008
Offline Last Active Oct 17 2012 01:56 AM

Topics I've Started

why does DX3D 9 not like my code :-(

21 June 2008 - 01:51 PM

I'm just lost... I'm just messing around with some code (i'm more noob than I realised... ) that's supposed to render several squares (32x32 px) in just white using 2 triangles per...

and its just not working...

first I was getting a read access violation trying to lock my vertex buffer, which is stored in a global pointer (never mind how evil that is, give me a break) ...

in my message pump i had a call to a function called render_frame() that would copy the vertex list to the buffer for rendering. . . the buffer is created in winmain ...

debugging just stopped at buffer->lock(0,0,(void**)pVoid,0); (in render_frame() ) with the violation address being pVoid + 0x10 .. ??

....

I moved the contents of render_frame to just be in winmain's message loop, and now i just get first-chance exception - long at memory location. . i think its &pVoid..

I'm just confused by that all. . anyways, here my code. . .
note - I currently do get a window which is just black, 640x480 ... that much of my code works (its framework from me following a tut on d3d9 .. )

//we'll include windows and directX headers in luci.h!

#include "luci.h"

#define NUM_BOXES 15

#define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)
struct myvertex{ FLOAT x,y,z,rhw; DWORD color;};

struct MyMove { FLOAT x, y; };

struct MyBox{ FLOAT left, up, right, down; MyMove V; DWORD color; } ;
// color=D3DCOLOR_XRGB(0, 0, 255)

MyBox	TheBoxes[NUM_BOXES];
myvertex	BoxPolys[NUM_BOXES][6];

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int CmdShow)
{
	if(LuciCreateMainWindow(hInstance, CmdShow, false,640,480)) return 1;

	initD3D();
	LPDIRECT3DVERTEXBUFFER9 triangle_buf=NULL;

	d3ddev->CreateVertexBuffer(6*NUM_BOXES*sizeof(myvertex),0,CUSTOMFVF,
								D3DPOOL_MANAGED,&triangle_buf,NULL);


	int b=0;
	float screen_x=8; float screen_y=8;

	for(int y=0; y<(NUM_BOXES/15)+1; y++)
	{
		screen_y+=40;
		screen_x=8;

		for(int x=0; x<15; x++)
		{
			screen_x+=40;

			TheBoxes[b].left=screen_x-16.0f;	TheBoxes[b].up=y-16.0f; 
			TheBoxes[b].right=x+16.0f;			TheBoxes[b].down=y+16.0f;
			TheBoxes[b].color=D3DCOLOR_XRGB(255, 255, 255);
			
			b++;
		}
	}

	MSG msg;

	DWORD starting_point;

	bool DeviceLost=false;
	HRESULT DeviceErrCode;

	while( TRUE )
	{
		starting_point = GetTickCount();

		if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
		{
			if (msg.message == WM_QUIT) 
				break;

			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}

		if(DeviceLost)
		{
			DeviceErrCode = d3ddev->TestCooperativeLevel();
			if(DeviceErrCode == D3DERR_DEVICENOTRESET)
			{
				if(d3ddev->Reset(&d3dpp)==D3D_OK) DeviceLost=false;
			}
		}
		
		if(!DeviceLost)
		{
			for(int i=0; i<NUM_BOXES; i++)
			{
				BoxPolys[i][0].color=BoxPolys[i][1].color=TheBoxes[i].color;
				BoxPolys[i][2].color=BoxPolys[i][5].color=TheBoxes[i].color;

				BoxPolys[i][0].x=TheBoxes[i].left;	BoxPolys[i][0].y=TheBoxes[i].up;
				BoxPolys[i][1].x=TheBoxes[i].right;	BoxPolys[i][1].y=TheBoxes[i].up;
				BoxPolys[i][2].x=TheBoxes[i].left;	BoxPolys[i][2].y=TheBoxes[i].down;
				BoxPolys[i][3]=BoxPolys[i][2];	BoxPolys[i][4]=BoxPolys[i][1];
				BoxPolys[i][5].x=TheBoxes[i].right;	BoxPolys[i][5].y=TheBoxes[i].down;
			}
			//triangle creation code
			VOID *pVoid;
			triangle_buf->Lock(0,0,(void**)&pVoid,0);
			memcpy(pVoid,BoxPolys,sizeof(BoxPolys));
			triangle_buf->Unlock();

			d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0,0), 1.0f, 0);
			d3ddev->BeginScene();
			d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST,0,NUM_BOXES*2);
			d3ddev->EndScene();

			if(d3ddev->Present(NULL, NULL, NULL, NULL)!=D3D_OK) 
			{
				DeviceLost=true;
			}

		}

		while((GetTickCount() - starting_point) < 1000) ;
	}

	triangle_buf->Release();

	closeD3D();
	
//	LuciMB(L"Exiting Now");

	return msg.wParam;
}

LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch(message)
	{
	case WM_DESTROY:
		{
			PostQuitMessage(0);
			return 0;
		} break;
	
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}

	return 0;
}



[Edited by - hstubbs3 on June 21, 2008 8:50:01 PM]

PARTNERS