| QUOTE |
| The libs don't seem to be compatible with the the Borland Command-Line compiler. Voodoo might have gotten it to work though, maybe you could ask him. |
| CODE |
| #include <math.h> inline float sqrtf(float f) {return(sqrt((double)f));} |
| CODE |
| #include <VC6.h>//always include the VC6 header first! #include <windows.h> #include <string.h>//for memcpy #include <d3d9.h> //Window callback function and window handle LRESULT WINAPI MsgProc(HWND, UINT, WPARAM, LPARAM); HWND hwnd; //application internaly step function void step(void); //DX handle IDirect3D9*dx9; //Device (sort of DX child window) IDirect3DDevice9*dx_device; //Verticals struct vertex { float x, y, z, rhw; int color; }; vertex vertices[] = { { 150.0f, 50.0f, 0.5f, 1.0f, 0xffff0000 }, // x, y, z, rhw, color { 250.0f, 250.0f, 0.5f, 1.0f, 0xff00ff00 }, { 50.0f, 250.0f, 0.5f, 1.0f, 0xff00ffff }, }; //The vertex buffer IDirect3DVertexBuffer9*vertex_buffer; int WINAPI WinMain( HINSTANCE inst, HINSTANCE, LPSTR, INT style) { // Register the window class. WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L, inst, NULL, NULL, NULL, NULL, "App", NULL }; if(!RegisterClassEx( &wc )) return 0; // Create the application's window. hwnd = CreateWindow( "App", "Hello", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, GetDesktopWindow(), NULL, inst, NULL ); //Show the window ShowWindow(hwnd,style); //Set timer etc SetTimer(hwnd,1,50,0); //Setup DX dx9=Direct3DCreate9(D3D_SDK_VERSION); if(!dx9) return 0; D3DPRESENT_PARAMETERS parm; ZeroMemory( &parm, sizeof(parm) ); parm.Windowed = TRUE; parm.SwapEffect = D3DSWAPEFFECT_DISCARD; parm.BackBufferFormat = D3DFMT_UNKNOWN; if(D3D_OK!=dx9->CreateDevice( D3DADAPTER_DEFAULT,//default value D3DDEVTYPE_HAL, hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &parm, &dx_device)) return 0; //Setup vertex buffer if(D3D_OK!=dx_device->CreateVertexBuffer( 3*sizeof(vertex), 0 , D3DFVF_XYZRHW | D3DFVF_DIFFUSE, D3DPOOL_DEFAULT, &vertex_buffer, 0)) return 0; //now we write vertices into the buffer //First we lock the mem of the buffer (so that DX won't move it while we're writting) void* b_mem; if(D3D_OK!=vertex_buffer->Lock( 0, sizeof(vertices), &b_mem, 0 )) return 0; memcpy( b_mem, vertices, sizeof(vertices) ); vertex_buffer->Unlock(); MSG msg; while( GetMessage( &msg, NULL, 0, 0 ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } if(!dx_device) dx_device->Release(); if(!dx9) dx9->Release(); return 0; } void step(void) { // Clear the back buffer to a blue color dx_device->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 ); // Begin the scene. dx_device->BeginScene(); dx_device->SetStreamSource( 0, vertex_buffer, 0, sizeof(vertex) ); dx_device->SetFVF( D3DFVF_XYZRHW | D3DFVF_DIFFUSE ); dx_device->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 1 ); // End the scene. dx_device->EndScene(); dx_device->Present( NULL, NULL, NULL, NULL ); } LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) { switch( msg ) { case WM_DESTROY: PostQuitMessage( 0 ); return 0; case WM_TIMER: if(wParam==1) step(); return 0; } return DefWindowProc( hWnd, msg, wParam, lParam ); } |