Using D3DFVF_XYZRHW flag for a Vertex Buffer

This is a discussion on Using D3DFVF_XYZRHW flag for a Vertex Buffer within the Windows Programming forums, part of the Platform Specific Boards category; I'm hoping i can pick someones brain for this without having to post a whole whack of code. I've got ...

  1. #1
    Peace
    Join Date
    Aug 2001
    Posts
    1,510

    Using D3DFVF_XYZRHW flag for a Vertex Buffer

    I'm hoping i can pick someones brain for this without having to post a whole whack of code.

    I've got a 3D enviroment set up and i can display billboards and Meshs to it just fine. The textures come out exactly right. But i have need to display certain things on screen-relative coords (like my mouse cursor) so i used these flags D3DFVF_XYZRHW | D3DFVF_TEX1 when creating my vertex buffer, which looks like this:

    Code:
    struct vertex
    {
       float x, y, z, rhw;
       float u, v;
    };
    
    vertex target[4];
    
    IDirect3DVertexBuffer8 * g_VBuffer;
    
    //displayed like this:
    
    //lock up VBuffer and memcopy it on in
    unsigned char *vb_vertices;
    
    if (FAILED( g_VBuffer->Lock(0, 0, &vb_vertices, 0) ))
    {
       MessageBox(hWnd, "Lock() failed!", "Function Error", MB_OK);
       return E_FAIL;
    }
    
    memcpy(vb_vertices, target, sizeof(target));
    g_VBuffer->Unlock();
    
    g_pDevice->SetVertexShader(D3D_CUSTOMVERTEX);
    g_pDevice->SetStreamSource(0, g_VBuffer, sizeof(vertex));
    g_pDevice->SetTexture(0, pTexture);
    
    g_pDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);

    The Buffer appears exactly wher it should and the texture is also displayed... but! Its all grey (which is the colour of my text incidentally). I know the texture is there because i alpha blended out the background colours on it and they disapeared leaving only a grey mouse-cursor shape without any of the textures colours on it.

    Oh, in case its relevant i've got the following RenderStates set:

    Code:
     //*** DISPLAY TYPE STUFF ***
    
    	//Z-Level? Yes. Of course.
        g_pDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
    
    	//Noramlize Normals?
        g_pDevice->SetRenderState( D3DRS_NORMALIZENORMALS, TRUE );
    
    	//Cull Counter-Clockwise
        g_pDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW );
    
    
    	//*** LIGHTING ***
    
    	//Set lighting OFF
    	g_pDevice->SetRenderState( D3DRS_LIGHTING, FALSE );
    
    
    	//*** TEXTURE HANDLING ***
    	
    	//Texture stretching filter types (Option for D3DTEXF_LINEAR???)
        g_pDevice->SetTextureStageState( 0, D3DTSS_MAGFILTER, D3DTEXF_POINT );
        g_pDevice->SetTextureStageState( 0, D3DTSS_MINFILTER, D3DTEXF_POINT );
    
    	//Dither textures?
        g_pDevice->SetRenderState( D3DRS_DITHERENABLE, TRUE );
    
    	//Turned off because we dont use Coloured Vertexs
        g_pDevice->SetRenderState( D3DRS_COLORVERTEX, FALSE );
    
    	//Alpha Blending used in some textures for CVertexBuffer calls
    	g_pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
    
    
    	//*** PIXEL HANDLING ***
    
    	//Defines the method of determining pixel color
    	g_pDevice->SetTextureStageState( 0, D3DTSS_COLOROP,	  D3DTOP_SELECTARG1 );
    	//Take color only from texture instead of vertex colors (or which we have none)
    	g_pDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
    
    	//Defines the method of determining pixel alpha
    	g_pDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP,	  D3DTOP_SELECTARG1 );
    	//Alpha value for each pixel comes from the textures alpha value
    	g_pDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
    
    	//Source/Destination blending
    	g_pDevice->SetRenderState( D3DRS_SRCBLEND,	D3DBLEND_SRCALPHA );
    	g_pDevice->SetRenderState( D3DRS_DESTBLEND,	D3DBLEND_INVSRCALPHA );
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  2. #2
    Registered User Coder's Avatar
    Join Date
    Aug 2001
    Location
    Cairo, Egypt
    Posts
    128

    Just a note

    Just a sidenote (I don't think it has anything to do with the problem) : Why don't you disable the Z buffer test when you're rendering 2D stuff? Since you want it to be on top of everything

    By the way, if everybody fails to help you. Consider posting the code/url/attachment so that people'd try it on their PC's
    Last edited by Coder; 09-06-2001 at 02:38 PM.
    Muhammad Haggag

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    48
    check your e-mail.
    astride a storied past, thats everywhere you are

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multithreading (flag stopping a thread, ring buffer) volatile
    By ShwangShwing in forum C Programming
    Replies: 3
    Last Post: 05-19-2009, 07:27 AM
  2. can some one please tell me the cause of the error ?
    By broli86 in forum C Programming
    Replies: 8
    Last Post: 06-26-2008, 08:36 PM
  3. Simple (?) problem rendering a vertex buffer
    By Dark_Phoenix in forum Game Programming
    Replies: 4
    Last Post: 08-11-2007, 07:32 PM
  4. error help making no sense
    By tunerfreak in forum C++ Programming
    Replies: 5
    Last Post: 04-17-2007, 07:55 PM
  5. Resource ICONs
    By gbaker in forum Windows Programming
    Replies: 4
    Last Post: 12-15-2003, 06:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21