Directx issues

This is a discussion on Directx issues within the Game Programming forums, part of the General Programming Boards category; I haven't really seen any issues posted about this... however there is always a possibility of me misreading something. In ...

  1. #1
    I am me, who else?
    Join Date
    Oct 2002
    Posts
    250

    Directx issues

    I haven't really seen any issues posted about this... however there is always a possibility of me misreading something.

    In any event, I started working with vertex buffers and am now having a problem. When I click and drag on the screen I am creating rectangles (this is intended) then I record the position, relative to the client window and make sure these coordinates are passed to the vertex buffers. Then I finally render the rectangle on the screen, however with the transformed verticies (passing these to a customvertex struct I picked up from someone's code)...

    Code:
    struct CUSTOMVERTEX
    	{
    		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_XYZRHW|D3DFVF_DIFFUSE)
    I have found that the rectangle being drawn is usually offset as I go further in the y direction. I have added 2x2 rectangles to represent the position in the window according to windows GDI, but I notice they are off. At the top of the window they are almost dead on, but as I got further +y it gets worse.


    Kinda looks like this at the bottom of the window.

    instead its here -> ----------------
    | |
    topleft should be->x
    ...
    |_________|

    bottom right should be here -->x


    Any ideas? Lemme know if you need a better explanation, thanks.

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,597
    You need to adjust for GDI and the way it is representing the graphics. GDI can use many many different types of mapping modes. MM_TEXT is what I think you want.

  3. #3
    I am me, who else?
    Join Date
    Oct 2002
    Posts
    250
    wow that totally did not format right at all hopefully that will help me, it was supposed to represent a square which was shifted up on the yu-axis buyt apparently I couldn't format that

  4. #4
    I am me, who else?
    Join Date
    Oct 2002
    Posts
    250
    Quote Originally Posted by Bubba
    You need to adjust for GDI and the way it is representing the graphics. GDI can use many many different types of mapping modes. MM_TEXT is what I think you want.

    Hmm I set the mapping mode to MM_TEXT, and tried a couple others, but its not working how I would have hoped.

    When I set out my vertexbuffers, they are given (for right now anyway) fixed coordinates. For example I create a CRect..

    Code:
    CRect myRect(200, 100, 500, 400);
    Then I get the buffers setup...


    Code:
    verticies[0].x  =  (float)myRect.left;
    	verticies[0].y  =  (float)myRect.top;
    	verticies[0].z  =  0.0f;
    	verticies[0].rhw = 1.0f;
    	verticies[0].tu =  0.0f;
    	verticies[0].tv =  0.0f;
    
    	verticies[1].x  =  (float)myRect.right;
    	verticies[1].y  =  (float)myRect.top;
    	verticies[1].z  =  0.0f;
    	verticies[1].rhw = 1.0f;
    	verticies[1].tu =  1.0f;
    	verticies[1].tv =  0.0f;
    
    	verticies[3].x  =  (float)myRect.right;
    	verticies[3].y  =  (float)myRect.bottom;
    	verticies[3].z  =  0.0f;
    	verticies[3].rhw = 1.0f;
    	verticies[3].tu =  1.0f;
    	verticies[3].tv =  1.0f;
    
    	verticies[2].x  =  (float)myRect.left;
    	verticies[2].y  =  (float)myRect.bottom;
    	verticies[2].z  =  0.0f;
    	verticies[2].rhw = 1.0f;
    	verticies[2].tu =  0.0f;
    	verticies[2].tv =  1.0f;
    and then try to render it...

    I draw a rectangle in the ondraw function (yes I am using MFC for this), and whats rendered by direct3d and the GDI are a bit off. Most notably in the y-axis. Usually its almost bang-on with the x-axis. Getting a book on this as well, but its always nice to have help from outside sources as well . Thanks again, and hopefully this explanation makes more sense than my previous one...

  5. #5
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,597
    Sounds like you are still using the wrong units for mapping. Make sure it is pixels and remember that the y aspect ratio will change as the size of the window changes. There are always less pixels in Y than X. This is probably what you are seeing.

    The correct pixel aspect ratio for any given window barring field of view and all of that is:

    AspectY=HorizPixels/VertPixels;

    Now when you move vertically you must account for AspectY. Multiply all your y movements by AspectY and it should come out right.

  6. #6
    I am me, who else?
    Join Date
    Oct 2002
    Posts
    250
    Hmmm interesting, I set it to MM_TEXT, and it reports to me that I did set MM_TEXT.

    I tried to use the aspecty, but either I am just totally missing your meaning, or I am doing it wrong. Basically I took the client width/height to get the aspect ratio, but its stretching the image instead of fitting it accordingly. I will attach two images which should help a lot more than words. I appreciate the help a lot

    The red-blue box is the GDI indicating the rectangle I am trying to draw.

    This is defined again as

    Code:
    CRect myRect(200, 100, 500, 400);
    My directx setup is as follows...

    Code:
    g_pD3D = Direct3DCreate9( D3D_SDK_VERSION );
    
        D3DDISPLAYMODE d3ddm;
    
        g_pD3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm );
    
        D3DPRESENT_PARAMETERS d3dpp;
        ZeroMemory( &d3dpp, sizeof(d3dpp) );
    	
        d3dpp.Windowed               = TRUE;
        d3dpp.SwapEffect             = D3DSWAPEFFECT_DISCARD;
        d3dpp.BackBufferFormat       = d3ddm.Format;
        d3dpp.EnableAutoDepthStencil = TRUE;
        d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
        d3dpp.PresentationInterval   = D3DPRESENT_INTERVAL_IMMEDIATE;
    
        g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, GetSafeHwnd(),
                              D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                              &d3dpp, &g_pd3dDevice );
    
    	loadTexture();
    	
    	g_pd3dDevice->CreateVertexBuffer( 4*sizeof(Vertex), D3DUSAGE_WRITEONLY, 
                                          D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, 
                                          &g_pVertexBuffer, NULL );
        void *pVertices = NULL;
    	setupVerts();
    
        g_pVertexBuffer->Lock( 0, 0, (void**)&pVertices, 0 );
        memcpy( pVertices, verticies, sizeof(verticies) );
        g_pVertexBuffer->Unlock();
    
        D3DXMATRIX matProj;
        D3DXMatrixPerspectiveFovLH( &matProj, D3DXToRadian( 45.0f ), 
                                    640.0f / 480.0f, 0.1f, 100.0f );
        g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
    
    	g_pd3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
    Dunno if that will help, but I would appeciate input. It shouldn't be this hard, or I am just thinking about it in the wrong way. Either way, pointers to tutorials or a good explanation is the best. Thanks again
    Attached Images Attached Images   

  7. #7
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,597
    Then maybe the division I posted is backwards. Try PixelY*(height/width).

  8. #8
    I am me, who else?
    Join Date
    Oct 2002
    Posts
    250
    Tried that actually, it shrunk instead I am not sure if I am just totally off, or if anyone has had this before at all... I'm using vertex buffers, but transformed coords, so it should not be a problem I wouldn't think...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ DirectX 9 3D z-buffer issues?
    By jrbarr in forum Game Programming
    Replies: 3
    Last Post: 02-14-2008, 01:23 AM
  2. Isometric Tile Engine using DirectX
    By Wraithan in forum Game Programming
    Replies: 3
    Last Post: 07-17-2006, 01:16 PM
  3. DirectX version issues
    By VirtualAce in forum Game Programming
    Replies: 1
    Last Post: 06-26-2006, 07:52 PM
  4. DirectSound header issues
    By dxfoo in forum C++ Programming
    Replies: 0
    Last Post: 03-19-2006, 07:16 PM
  5. DirectX - Starting Guide?
    By Zeusbwr in forum Game Programming
    Replies: 13
    Last Post: 11-25-2004, 12:49 AM

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