A few questions

This is a discussion on A few questions within the Game Programming forums, part of the General Programming Boards category; Hi there. i'm relatively new to directx. I have a message loop from a book called Introduction to 3d Game ...

  1. #1
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321

    A few questions

    Hi there.
    i'm relatively new to directx.

    I have a message loop from a book called Introduction to 3d Game Programming with Directx 9.0

    here it is:

    Code:
    int d3d::EnterMsgLoop( bool (*ptr_display)(float timeDelta) )
    {
    	MSG msg;
    	::ZeroMemory(&msg, sizeof(MSG));
    
    	static float lastTime = (float)timeGetTime(); 
    
    	while(msg.message != WM_QUIT)
    	{
    		if(::PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
    		{
    			::TranslateMessage(&msg);
    			::DispatchMessage(&msg);
    		}
    		else
            {	
    			float currTime  = (float)timeGetTime();
    			float timeDelta = (currTime - lastTime)*0.001f;
    
    			ptr_display(timeDelta);
    
    			lastTime = currTime;
            }
        }
        return msg.wParam;
    }
    could someone clear this up for me please.
    i understand a little, but not all of it.

    thanks if anyone replies.

    EDIT:
    Oh yes, and what is HRESULT?
    Last edited by beene; 04-14-2007 at 05:26 AM.

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    This loop is the message pump. And it also takes care of some timer housekeeping so you can pass the frame delta to the render function. I completely changed the one in the book to my own version b/c I did not agree with some of the architecture and framework. I removed the pointer to the render function as well but I won't get into my architecture here as it will certainly differ from yours.

    Interesting to note that in the second edition of the book the author made many of the same changes. In order to fit this into an object oriented design you will have to make some significant alterations to what you see in the book.

    But it is a very good book and I highly recommend it as well as the second edition. If you have questions you can go to www.moon-labs.com. There are forums and FAQs about the book as well as more code, more information, and the author frequents the site as well and is more than happy to help new programmers with DirectX.
    Last edited by VirtualAce; 04-14-2007 at 07:07 AM.

  3. #3
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321
    Thanks Bubba, i appreciate your response.

    I'm now wondering what
    Code:
    ::ZeroMemory(&msg, sizeof(MSG));
    is for...

    And i'm still wondering what HRESULT is.

  4. #4
    Captain - Lover of the C
    Join Date
    May 2005
    Posts
    341
    ZeroMemory sets everything in the MSG structure to 0. HRESULT is the return type that the guys at DirectX came up with. It's designed to tell whether the function completed properly. There are several different things that HRESULT could be to give specific errors. There are 2 macros that are designed to simplify those into either success or failure.
    Code:
    HRESULT MyResult;
    MyResult = SomeFunction();
    if (SUCCEED(MyResult))
    {
         // function ran fine
    }
    
    if (FAILED(MyResult))
    {
         // handle some errors
         // possibly exit program
    }
    
    // or directly:
    if (FAILED(SomeFunction()))
    {
         // SomeFunction failed
    }
    Don't quote me on that... ...seriously

  5. #5
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321
    Thanks, that pretty much covers it.

  6. #6
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321
    Hi again, i'm back with more questions.
    I want to clear a few things up before i move on with my DirecX programming.

    Code:
    struct Vertex
    {
    	Vertex(){}
    	Vertex(float x, float y, float z)
    	{
    		_x = x;  _y = y;  _z = z;
    	}
    	float _x, _y, _z;
    	static const DWORD FVF;
    };
    const DWORD Vertex::FVF = D3DFVF_XYZ;
    I have read the part of the book that this is in but i don't understand it.
    I want to before i move on.
    Like before, can anyone tell me about this struct?
    Thanks in advance.

  7. #7
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    A vertex is a point in 3d space that is used to draw objects, I assume that's how DX implements their vertex internally.

  8. #8
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321
    I know what a Vertex is, just why do i need that struct, and what does it do?

  9. #9
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    You need the struct to represent the abstract notion of a "vertex". If you don't understand that, you should probably spend some more time learning the basics of programming before you torture yourself with DX.

  10. #10
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321
    Thanks, i do understand that.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. questions....so many questions about random numbers....
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 07-30-2009, 08:47 AM
  2. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  3. Several Questions, main one is about protected memory
    By Tron 9000 in forum C Programming
    Replies: 3
    Last Post: 06-02-2005, 07:42 AM
  4. Trivial questions - what to do?
    By Aerie in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 12-26-2004, 08:44 AM
  5. questions questions questions.....
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 08-14-2001, 07:22 AM

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