//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.left=screen_x-16.0f; TheBoxes.up=y-16.0f;
TheBoxes.right=x+16.0f; TheBoxes.down=y+16.0f;
TheBoxes.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[0].color=BoxPolys[1].color=TheBoxes.color;
BoxPolys[2].color=BoxPolys[5].color=TheBoxes.color;
BoxPolys[0].x=TheBoxes.left; BoxPolys[0].y=TheBoxes.up;
BoxPolys[1].x=TheBoxes.right; BoxPolys[1].y=TheBoxes.up;
BoxPolys[2].x=TheBoxes.left; BoxPolys[2].y=TheBoxes.down;
BoxPolys[3]=BoxPolys[2]; BoxPolys[4]=BoxPolys[1];
BoxPolys[5].x=TheBoxes.right; BoxPolys[5].y=TheBoxes.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;
}
why does DX3D 9 not like my code :-(
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 .. )
[Edited by - hstubbs3 on June 21, 2008 8:50:01 PM]
Your code will be easier to read if you enclose it in [source] tags (you can edit your post using the 'edit' button in the upper-right).
thx for the
tag thingy.. . still lost on the error though :-/ might just try and simplify until it works... meh. .
I havent played with this for a few years, but you are checking messages then rendering then doing a prorated wait
while((GetTickCount() - starting_point) < 1000) ;
[you might want to loop with a sleep function insetad of simply spinning]
The problem may be that you get alot more messages in than you think but every one of them has to wait one full cycle before it gets processed.
Usually you process inputs in the message loop decoding and caching the actions for when the render/game turn gets executed (triggered by a timer messge or whatever). The message loop should be free running to process all the windows messages quickly.
Wouldn't it be helpful to fix the actual error first?
The problem is your outer for loop which loops to NUMBOXES/15+1. That ends up in two loop runs, with i being 0 and 1.
Then there's the inner loop with 15. This increases b up to 30. And that's twice the size of your array.
The problem is your outer for loop which loops to NUMBOXES/15+1. That ends up in two loop runs, with i being 0 and 1.
Then there's the inner loop with 15. This increases b up to 30. And that's twice the size of your array.
as for the For loop... ok, so i'm an idiot... but even fixing that i still have an issue...
first-chance exception - Microsoft C++ exception: long at memory location 0x0012fd08 ... somewhere in DrawPrimitive ...
the prorated loop was originally intended to limit to about 50fps . . . i was gonna eventually animate these things. . then it was crashing out on an unhandled exception so i put a messagebox in there and it was crazy.. lol. . so yeah.. . 1000 is way too long to wait usually... but still kinda lost..
Oops.. . left out setstreamsource .. . heh... ok. . so now i don't have exceptions,.... still just black.. got to check the winding of the polys or something i guess...
thanks for the help tho ....
first-chance exception - Microsoft C++ exception: long at memory location 0x0012fd08 ... somewhere in DrawPrimitive ...
the prorated loop was originally intended to limit to about 50fps . . . i was gonna eventually animate these things. . then it was crashing out on an unhandled exception so i put a messagebox in there and it was crazy.. lol. . so yeah.. . 1000 is way too long to wait usually... but still kinda lost..
Oops.. . left out setstreamsource .. . heh... ok. . so now i don't have exceptions,.... still just black.. got to check the winding of the polys or something i guess...
thanks for the help tho ....
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement