Thread: D3D Dx9 and rendering tiles (c++)

  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    2

    Question D3D Dx9 and rendering tiles (c++)

    I am looking for a tutorial that teaches the reader how to render tiles as they are arrange in a array looking like this.

    Code:
    int groundMap[5][5] = {
        {2  , 2  , 2  , 2  , 2},
        {2  , 1  , 1  , 1  , 2},
        {2  , 1  , 1  , 1  , 2},
        {2  , 1  , 1  , 1  , 2},
        {2  , 2  , 2  , 2  , 2},
    };
    Here does the numbers represent a tile (file).
    ex. 1 is grass and 2 is dirt.

    A friend helped me with this in openGL but he doesn't know directx so he cant help me.
    I have been looking for a few months after a tutorial that teaches the reader this.

    I wish to use D3D and DirectX9 with C++. But all I find when I google is articles about DirectDraw and tiles, and I wish to learn D3D not DirectDraw.

    This is a sample from the render we made in openGL (so people know what I am looking for). http://data.fuskbugg.se/skalman01/testRender.jpg hopefully someone that are good with DirectX9 and d3d can help me or show a tutorial about this or maybe has a example to show.

    To people that wish to reply to the thread:
    Keep to the topic please I am just trying to find this and so I can learn.

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Tiles are just 2D quads. How you store your tiles and maps in memory is more of an exercise in data structures and has nothing to do with Direct3D.

  3. #3
    Registered User
    Join Date
    Jul 2009
    Posts
    2
    I think I was a bit unclear, I want help find tutorials and/or books that uses D3D DX9 to render the correct files onto the screen by going threw the array.

    This is just a test to render sprites I can probably use the same piece when I draw tiles but it crashes when the app launches.

    I am new to DX but rendering 2D graphics shouldn't be to hard?
    Code:
    bool initSprites(void)
    {
    	// numOfSprites is defined like this 'const int numOfSprites = 2;'
    	std::string sprites[numOfSprites] = { "sprites.bmp", "sprintess.bmp" };
    	for(int i = 0; i < numOfSprites; i++)
    		spriteSurface = dxMgr->getSurfaceFromBitmap(sprites[numOfSprites]);
    
    	for (int i=0; i < MAX_SPRITES; i++)
    	{
    		spriteStruct[i].srcRect.top = 0;
    		spriteStruct[i].srcRect.left = i * SPRITE_WIDTH;
    		spriteStruct[i].srcRect.right = spriteStruct[i].srcRect.left + SPRITE_WIDTH;
    		spriteStruct[i].srcRect.bottom = SPRITE_HEIGHT;
    		spriteStruct[i].posX = rand()%600;
    		spriteStruct[i].posY = rand()%430;
    	}
    
    	return true;
    }

  4. #4
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    1. Don't use surfaces in Direct3D unless you absolutely have to.
    2. Sprite sheets can be used by altering the u,v coordinates of the quad.
    3. The logic used to draw/store your map has nothing to do with porting your game over to Direct3D.

    The only differences between what you have in OGL and what you need in D3D is you must port all the OGL specific calls and structures over to Direct3D.
    But I'm surprised b/c you are not asking about that you are asking how to write the game and since it sounds like you had one in OGL I'm a bit confused. I guess my main question is why are you porting to D3D if you have it working in OGL?
    My guess is you do not know OGL or D3D which means you need a book on one or the other or both. If the current code base is in OGL then stick with it. You will gain nothing by porting it.

    Short answer: Buy a book. We cannot teach OGL or D3D in one or even a hundred, possibly a thousand, posts.
    Last edited by VirtualAce; 07-25-2009 at 10:24 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DX9 visualization problem
    By darcome in forum Game Programming
    Replies: 4
    Last Post: 03-05-2003, 12:40 PM