Single Draw call w/Triangle Strip...

Hi guys,
my teacher wants me to create a single draw call using a grid function I created using a triangle strip…

I figured out how to draw the the Grid and UV’s; however, I’m passing in an array of textures to my function, how do I draw each texture at each index. Here’s my code:

void DrawTriGridStrip(int width, int height, U32 textures[], bool bWireFrame)
Vertex vertex[3000];
int indexCount = 0;

for(int i = 0; i <= height; i++)
	for(int j = 0; j <= width; j++)
		vertex[indexCount++] = Vertex(j * 64, 
                                           i * 64, j, i);

unsigned short index[1000];
int scalar = width + 1;
int count = 0;

for(int i = 0; i <= height; i++)
	for(int j = 0; j <= width; j++)
		index[count++] = 0 + (scalar * i) + j;
		index[count++] = scalar + (scalar * 
                                     i) + j;
		index[count++] = 1 + (scalar * i) + j;
		index[count++] = (scalar + 1) + 
                                     (scalar * i) + j;

		if(j == width)
			index[count++] = (scalar + 1) 
                                       + (scalar * i) + j;
			index[count++] = (scalar) + 
                                             (scalar * i);
			index[count++] = (scalar) + 
                                             (scalar * i);

int size = count;


// Turn on wireframe mode
	glPolygonMode(GL_FRONT, GL_LINE);
	glPolygonMode(GL_BACK, GL_LINE);

glVertexPointer(2, GL_FLOAT, sizeof(Vertex), 
glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), 

int iCount = 0;	//ToDo: iterate in array to batch 
                    //draw calls...
glDrawElements( GL_TRIANGLE_STRIP, size - 1, 
                    GL_UNSIGNED_SHORT, index);
//glMultiDrawElements(GL_TRIANGLE_STRIP, size - 1, 
    //GL_UNSIGNED_SHORT, meshIndicesArrays, 512);


// Turn off wireframe mode
	glPolygonMode(GL_FRONT, GL_FILL);
	glPolygonMode(GL_BACK, GL_FILL);


I’m passing in an array of textures to my function, how do I draw each texture at each index.

you can’t draw the grid with a single draw call and use different textures.
You can’t use texture array extension with fixed function so that option is ruled out. You may have to use one texture and atlas each region.

Thanks, that’s one problem ruled out. Maybe I’m going about it all wrong… How could I batch my textures to one texture?

How big is your terrain/grid?
You can atlas textures by copy / paste into a large texture using tools like Paintshop pro/Photoshop, etc.
You may need to leave a 2 or 3 pixel gap between each one so that linear filtering does not fetch an adjacent tile.
Texture atlasing may be ruled out if your textures are many and or large (1024*1024 or greater). There is an implmentation texture size limit which may be a restriction for you.

You could try 3D textures if you are really stuck - each ‘slice’ would be the equivalent of your individual tile textures. Each slice would have to be the same dimension however. To render 3D textures you would need to supply a 3rd tex-coordinate.

Thanks a lot! That was great advice! My textures are relativity small small. I have already built an atlas for the textures and it works beautiful! Now, since I’m using a triangle strip, the only problem I’m having is setting the UV coordinates correctly. Any advice there? And thanks for all the help so far! :slight_smile:

if all the texture tiles in the atlas are the same size and positioned uniformly in a grid fashion, you should be able to mathematically calculate the UV coordinates easily.
On the other hand, if they are spread about unevenly and are different sizes then…trouble!