Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

How do you handle multiple textures in directX

Options
  • 25-10-2005 2:15pm
    #1
    Registered Users Posts: 2,320 ✭✭✭


    I think this belongs here more than on the graphics board.

    I have a box, defined by _lowerBound and _upperBound vectors which is essentially a room. I have to use two textures, one for the floor and ceiling and one for the 4 walls. The problem i have is that all the faces are being textured with the one texture because i am unsure where to put the second setTexture call. here's the setup method
    bool World::setup(IDirect3DDevice9 * device)
    {
    	bool success;
    	// Call the superclass setup
    	success = DrawableEntity::setup(device);
    
    	if (success) 
    	{			
    		TexelVertex * vertices;
    		
    		// Create a vertex buffer to hold the vertices we want to draw
    		device->CreateVertexBuffer(
    			36 * sizeof(TexelVertex), // size in bytes
    			D3DUSAGE_WRITEONLY,		  // flags
    			TexelVertex::FVF,         // vertex format
    			D3DPOOL_MANAGED,		  // managed memory pool
    			&_boxVertices,            // return create vertex buffer
    			0);     
    
    		_boxVertices->Lock(0, 0, (void**)&vertices, 0);
    
    			//ceiling
    			vertices[0] = TexelVertex(80, 15, -50, 1, 0);
    			vertices[1] = TexelVertex(80, 15, 50, 1, 1);
    			vertices[2] = TexelVertex(-80, 15, 50, 0, 1);
    
    			vertices[3] = TexelVertex(-80, 15, 50, 0, 1);
    			vertices[4] = TexelVertex(-80, 15, -50, 0, 0);
    			vertices[5] = TexelVertex(80, 15, -50, 1, 0);
    
    			//floor
    			vertices[6] = TexelVertex(-80, 0, 50, 1, 0);
    			vertices[7] = TexelVertex(80, 0, 50, 1, 1);
    			vertices[8] = TexelVertex(80, 0, -50, 0, 1);
    
    			vertices[9] = TexelVertex(80, 0, -50, 0, 1);
    			vertices[10] = TexelVertex(-80, 0, -50, 0, 0);
    			vertices[11] = TexelVertex(-80, 0, 50, 1, 0);			
    			
    			// Load the texture
    			D3DXCreateTextureFromFile(device, "ground.bmp", &_ceilingTexture);
    
    		_boxVertices->Unlock();
    
    		_boxVertices->Lock(12*sizeof(TexelVertex), 0, (void**)&vertices, 0);
    
    			//face
    			vertices[12] = TexelVertex(80, 15, 50, 0, 0);
    			vertices[13] = TexelVertex(80, 0, 50, 0, 1);
    			vertices[14] = TexelVertex(-80, 0, 50, 1, 1);
    
    			vertices[15] = TexelVertex(-80, 0, 50, 1, 1);
    			vertices[16] = TexelVertex(-80, 15, 50, 1, 0);
    			vertices[17] = TexelVertex(80, 15, 50, 0, 0);
    
    			//face
    			vertices[18] = TexelVertex(80, 15, -50, 0, 0);
    			vertices[19] = TexelVertex(80, 0, -50, 0, 1);
    			vertices[20] = TexelVertex(80, 0, 50, 1, 1);
    
    			vertices[21] = TexelVertex(80, 0, 50, 1, 1);
    			vertices[22] = TexelVertex(80, 15, 50, 1, 0);
                            vertices[23] = TexelVertex(80, 15, -50, 0, 0);
    			.
                            .
                            .
    			// Load the texture
    			D3DXCreateTextureFromFile(device, "rocks.bmp", &_wallTexture);
    
    		_boxVertices->Unlock();
    		
    	}
    
    	return success;
    }
    

    I initally thought that locking, then unlocking and locking again would change the texture but alas. Anyone any inspiration?


Comments

  • Moderators, Music Moderators Posts: 1,481 Mod ✭✭✭✭satchmo


    Well I've never programmed Direct3D, but one 3D API is the same as another. It would help if you showed us the rendering code too, that's probably where the problem is. It should be something like:
    //setup
    D3DXCreateTextureFromFile(floorTexture)
    D3DXCreateTextureFromFile(wallTexture)
    
    CreateVertexBuffer(floorVB)
    CreateVertexBuffer(wallVB)
    
    //rendering
    SetTexture(floorTexture)
    SetStreamSource(floorVB)
    DrawPrimitive()
    
    SetTexture(wallTexture)
    SetStreamSource(wallVB)
    DrawPrimitive()
    
    The main thing to note is that textures are completely independent of vertex buffers - the way you have your setup code written suggests you might think otherwise.


  • Registered Users Posts: 2,320 ✭✭✭Q_Ball


    It can be done using one vertex buffer apparently by using an offset to reference the ceiling and the walls. like in the code vertices[0] - [11] are the ceilings and [12] - [35] are the walls. I'll get the solution thursday i just hate feeling thick :mad:


  • Moderators, Music Moderators Posts: 1,481 Mod ✭✭✭✭satchmo


    Well sure stick it all in one VB so - the second parameter the DrawPrimitive specifies where in the VB to start. It still shouldn't affect the texturing.


Advertisement