Archived

This topic is now archived and is closed to further replies.

Raloth

multiple index buffers for 1 tilemap array - headaches

Recommended Posts

Raloth    379
I am working on getting an index buffer for each of the different tiles in my tilemap so that I can blend in between them. I am sure that it's setting the array right so it knows which tiles go where, so it can only be the indices that are wrong. Can anyone spot a problem with this code?
	WORD *pGrassIndices,*pDirtIndices,*pSandIndices;
	
	if(grassIndices) if(FAILED(grassIndices->Lock(0,0,(BYTE**)&pGrassIndices,0))) return false;
	if(dirtIndices) if(FAILED(dirtIndices->Lock(0,0,(BYTE**)&pDirtIndices,0))) {
		grassIndices->Unlock();
		return false;
	}
	if(sandIndices) if(FAILED(sandIndices->Lock(0,0,(BYTE**)&pSandIndices,0))) {
		grassIndices->Unlock();
		dirtIndices->Unlock();
		return false;
	}
	
	int position = 0;
	for(int i=0;i<32;i++) {
		for(int j=0;j<32;j++) {
			if(tilelookup[i][j] & GrassID) {
				pGrassIndices[0] = position + 0;
				pGrassIndices[1] = position + 1;
				pGrassIndices[2] = position + 3;
				pGrassIndices[3] = position + 1;
				pGrassIndices[4] = position + 2;
				pGrassIndices[5] = position + 3;
				pGrassIndices += 6;
			}
			if(tilelookup[i][j] & DirtID) {
				pDirtIndices[0] = position + 0;
				pDirtIndices[1] = position + 1;
				pDirtIndices[2] = position + 3;
				pDirtIndices[3] = position + 1;
				pDirtIndices[4] = position + 2;
				pDirtIndices[5] = position + 3;
				pDirtIndices += 6;
			}
			if(tilelookup[i][j] & SandID) {
				pSandIndices[0] = position + 0;
				pSandIndices[1] = position + 1;
				pSandIndices[2] = position + 3;
				pSandIndices[3] = position + 1;
				pSandIndices[4] = position + 2;
				pSandIndices[5] = position + 3;
				pSandIndices += 6;
			}
			position += 4;
		}
	}
	
	if(sandIndices) sandIndices->Unlock();
	if(dirtIndices) dirtIndices->Unlock();
	if(grassIndices) grassIndices->Unlock();
GrassID is set to 1, DirtID is set to 2, and SandID is 4 so I can use | to set the tilelookup array to contain multiple types in one element. First I go through my base array and set the tiles to all grass. I then go and set the tilelookup array using the bits above for each adjacent tile. I ran some tests and everything works fine so far. However, if I try adding in a few random sand or dirt tiles, it won't render at all except for a few places at the beginning of the array. Any ideas? I'm so confused . [edited by - Raloth on August 13, 2003 9:54:07 PM]

Share this post


Link to post
Share on other sites
Osc    122
The second parameter to Lock should be the size in bytes that you want to lock, ie. 32*32*6*sizeof(WORD) instead of zero ;->

You may be able to lock a smaller region if you''ve already counted how many tiles use each type ( which you need to know anyway when you draw the data ).

Share this post


Link to post
Share on other sites
Raloth    379
quote:
Original post by Osc
The second parameter to Lock should be the size in bytes that you want to lock, ie. 32*32*6*sizeof(WORD) instead of zero ;->

You may be able to lock a smaller region if you''ve already counted how many tiles use each type ( which you need to know anyway when you draw the data ).


If you give both parameters 0 then it locks the entire buffer.
quote:
Original post by ACAC
Why use a different set of indicies for each sand/dirt/grss when they are exsactly the same? O_o


They aren''t the same...

Share this post


Link to post
Share on other sites
Chaucer    122
Raloth,
I think you may want to consider only using 1 index buffer instead of splitting it into one for each texture type. The reason I had been splitting it before was because I wasn''t doing any blending. If you''re blending, however, you''re going to be rendering several textures for each "tile" so there''s no real point to splitting the index buffer. I think...

Share this post


Link to post
Share on other sites
Raloth    379
Well, I could render the entire map several times. The problem is once you get to things like 6 different texture types you end up rendering 4 times the number of tiles you need to...

Share this post


Link to post
Share on other sites
Chaucer    122
A better way might be to create your index buffers in such a way that all geometry that will be rendered with 1 pass is in 1 buffer, 2 passes in another buffer, 3 passes in another, etc. That way, you''re only rendering a small portion of the geometry multiple times.

Share this post


Link to post
Share on other sites
Raloth    379
Ok, I will try it once I get my much more annoying alpha blending problem fixed. Thanks!

[edit] Are you sure about that? Because I gave each index buffer a separate pointer. Hmm...

[edited by - Raloth on August 14, 2003 11:52:46 PM]

Share this post


Link to post
Share on other sites