direct x farb-angabe in dword? (kein macro geht :|)
-
hi,
ich hab mir mal die ms-tutorials zu directx angeguckt und hab jetzt in direct 3d reingeguckt.
da wird ja ein vertex definiert:
struct CUSTOMVERTEX { FLOAT x, y, z, rhw; // The transformed position for the vertex. DWORD color; // The vertex color. };
und dann ist so ein beispiel dreieck:
CUSTOMVERTEX 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, }, };
wie ist die farbangabe in DWORD color ?
ich hab alle macros probiert, die ich gefunden hab: D3DCOLOR_ARGB, D3DCOLOR_COLORVALUE, D3DCOLOR_RGBA, D3DCOLOR_XRGB - aber keins funktioniert, d.h. bei keinem kommt die farbe raus, die ich angebe0xffff0000 ist hellgrün
0xff00ff00 ist lila
0xff00ffff ist dunkelrot0x00000000 is schwarz...
wenn ich nu aber 0x00000001 angebe, kommt auch dunkelrot!wie geht das?!
lw
-
Statt der Hexziffer die aufgebaut ist nach dem Schema 0xAARRGGBB kannst du auch das Makro D3DCOLOR_ARGB() verwenden, siehe hier:
CUSTOMVERTEX vertices[] = { { 150.0f, 50.0f, 0.5f, 1.0f, D3DCOLOR_ARGB(255,255,0,0) }, // x, y, z, rhw, color { 250.0f, 250.0f, 0.5f, 1.0f, D3DCOLOR_ARGB(255,0,255,0) }, { 50.0f, 250.0f, 0.5f, 1.0f, D3DCOLOR_ARGB(255,0,0,255) }, };
MfG SideWinder
-
Vermutlich liegt es an etwas ganz anderem.
Bye, TGGC (Denken, und gut ist.)
-
Das kann natürlich gut sein, dafürmüsste er aber seine Code mal ganz posten.
PS: TGGC, ich leibe dein hilfreichen aussagen
-
dann müsste D3DCOLOR_ARGB(255,0,0,255) ja blau sein, ne?
das würd bei mir aber dunkelrot
(das gleiche dunkelrot wie bei 0x00000001 !!)screenshot: http://www.lawilog.de/foto.gif
kann das so ne art bug sein?
lw
ihr wollt code?!
also es is das bsp. "Step 2: Setting Up the Vertex Buffer" aus dem directX sdk... hier nochma, wenn ihr das wollt:#ifndef _MSC_VER #define sqrtf (float)sqrt #endif //bcc32 -tW -DWIN32 matrices.cpp d3d9.lib d3dx9.lib #include <windows> #include <mmsystem> #include <d3d9> #include <d3dx9> using namespace std; LPDIRECT3D9 g_pD3D = NULL; // Used to create the D3DDevice LPDIRECT3DDEVICE9 g_pd3dDevice = NULL;// Our rendering device LPDIRECT3DVERTEXBUFFER9 g_pVB = NULL; // Buffer to hold vertices struct CUSTOMVERTEX // A structure for our custom vertex type { FLOAT x, y, z, rhw; // The transformed position for the vertex DWORD color; // The vertex color }; // Our custom FVF, which describes our custom vertex structure #define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE) //#define myRGB(r,g,b) ((COLORREF)((0xff000000|(BYTE)(r)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(b))<<16))) //#define xRGB(b,g,r) (RGB(r,g,b)) HRESULT InitD3D(HWND hWnd) { // Create the D3D object, which is needed to create the D3DDevice. if(NULL == (g_pD3D = Direct3DCreate9(D3D_SDK_VERSION))) return E_FAIL; D3DPRESENT_PARAMETERS d3dpp;// Set up the structure used to create the D3DDevice ZeroMemory(&d3dpp, sizeof(d3dpp)); d3dpp.Windowed = true; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; // Create the D3DDevice if(FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice))) { return E_FAIL; } // Turn off culling, so we see the front and back of the triangle g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); // Turn off D3D lighting, since we are providing our own vertex colors g_pd3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE); return S_OK; } DWORD farbe = D3DCOLOR_ARGB(255,0,0,255);// D3DCOLOR_XRGB(230,173,18);//0xff000000; HRESULT InitGeometry() { // Initialize three vertices for rendering a triangle CUSTOMVERTEX g_Vertices[] = { { -1.0f,-1.0f, 0.0f, D3DCOLOR_ARGB(255,0,0,255)}, { 1.0f,-1.0f, 0.0f, D3DCOLOR_ARGB(255,0,0,255)}, { 0.0f, 1.0f, 0.0f, D3DCOLOR_ARGB(255,0,0,255)}, }; // Create the vertex buffer. if( FAILED( g_pd3dDevice->CreateVertexBuffer(3*sizeof(CUSTOMVERTEX), 0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL))) { return E_FAIL; } // Fill the vertex buffer. VOID* pVertices; if(FAILED(g_pVB->Lock( 0, sizeof(g_Vertices), (void**)&pVertices, 0))) return E_FAIL; memcpy(pVertices, g_Vertices, sizeof(g_Vertices)); g_pVB->Unlock(); return S_OK; } void Cleanup() { if(g_pVB != NULL) g_pVB->Release(); if(g_pd3dDevice != NULL) g_pd3dDevice->Release(); if(g_pD3D != NULL) g_pD3D->Release(); } void SetupMatrices()//Sets up the world, view, and projection transform matrices { // For our world matrix, we will just rotate the object about the y-axis. D3DXMATRIXA16 matWorld; // Set up the rotation matrix to generate 1 full rotation (2*PI radians) // every 1000 ms. To avoid the loss of precision inherent in very high // floating point numbers, the system time is modulated by the rotation // period before conversion to a radian angle. UINT iTime = timeGetTime() % 3600; FLOAT fAngle = iTime * (2.0f * D3DX_PI) / 3600.0f; D3DXMatrixRotationY( &matWorld, fAngle ); g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld ); // Set up our view matrix. A view matrix can be defined given an eye point, // a point to lookat, and a direction for which way is up. Here, we set the // eye five units back along the z-axis and up three units, look at the // origin, and define "up" to be in the y-direction. D3DXVECTOR3 vEyePt( 0.0f, 3.0f,-5.0f ); D3DXVECTOR3 vLookatPt( 0.0f, 0.0f, 0.0f ); D3DXVECTOR3 vUpVec( 0.0f, 1.0f, 0.0f ); D3DXMATRIXA16 matView; D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec ); g_pd3dDevice->SetTransform( D3DTS_VIEW, &matView ); // For the projection matrix, we set up a perspective transform (which // transforms geometry from 3D view space to 2D viewport space, with // a perspective divide making objects smaller in the distance). To build // a perpsective transform, we need the field of view (1/4 pi is common), // the aspect ratio, and the near and far clipping planes (which define at // what distances geometry should be no longer be rendered). D3DXMATRIXA16 matProj; D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f ); g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj ); } void Render()//Draws the scene { //if(NULL == g_pd3dDevice) return; // Clear the backbuffer to a blue color g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(255,255,255), 1.0f, 0); // Begin the scene if(SUCCEEDED(g_pd3dDevice->BeginScene())) { SetupMatrices(); // Rendering of scene objects can happen here g_pd3dDevice->SetStreamSource(0, g_pVB, 0, sizeof(CUSTOMVERTEX)); g_pd3dDevice->SetFVF(D3DFVF_CUSTOMVERTEX); g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1); // End the scene g_pd3dDevice->EndScene(); } // Present the backbuffer contents to the display g_pd3dDevice->Present(NULL, NULL, NULL, NULL); } LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_DESTROY: { Cleanup(); PostQuitMessage(0); return 0; } /*case WM_PAINT: { Render(); ValidateRect(hWnd, NULL); return 0; }*/ default: return DefWindowProc(hWnd, msg, wParam, lParam); } } int WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, int) { // Register the window class WNDCLASSEX wc = {sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L, hInst/*GetModuleHandle(NULL)*/, NULL, NULL, NULL, NULL, "D3D Tutorial", NULL}; RegisterClassEx(&wc); // Create the application's window HWND hWnd = CreateWindow("D3D Tutorial", "DirectX Test", WS_OVERLAPPEDWINDOW, 100, 100, 500, 500, GetDesktopWindow(), NULL, wc.hInstance, NULL); // Initialize Direct3D if(SUCCEEDED(InitD3D(hWnd))) { if(SUCCEEDED(InitGeometry()))// Create the vertex buffer { // Show the window ShowWindow(hWnd, SW_SHOWDEFAULT); UpdateWindow(hWnd); // Enter the message loop MSG msg; ZeroMemory(&msg, sizeof(msg)); while(msg.message != WM_QUIT) { if(PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } else Render(); } } } UnregisterClass("D3D Tutorial", wc.hInstance); return 0; }
-
Lawilog schrieb:
kann das so ne art bug sein?
Nein, es ist ein getarnter Feature.
Benutz mal die DX Debug Runtimes.
Bye, TGGC (Denken, und gut ist.)
-
Was ist das denn für nen IDe?
Zeig mal den ganzen Code.
-
Das ist sicher nicht das Sample.
struct und FVF passt nicht zusammen. Sollte aber Compiler und oder DebugRuntimes merken. Nutz den Kram!
Bye, TGGC (Denken, und gut ist.)
-
huuuups...sorry
da wär ich aber nie drauf gekommen...
danke
lw
-
Immer gern.
Bye, TGGC (Denken, und gut ist.)