Kunikita

09-06-2011, 12:37 PM

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;

height--;

width--;

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;

glColor3f(1,1,1);

// Turn on wireframe mode

if(bWireFrame)

{

glPolygonMode(GL_FRONT, GL_LINE);

glPolygonMode(GL_BACK, GL_LINE);

}

glEnableClientState(GL_VERTEX_ARRAY);

glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glDisable(GL_CULL_FACE);

glVertexPointer(2, GL_FLOAT, sizeof(Vertex),

&vertex[0].m_fX);

glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex),

&vertex[0].m_fU);

int iCount = 0; //ToDo: iterate in array to batch

//draw calls...

SetTexture(textures[iCount++]);

glDrawElements( GL_TRIANGLE_STRIP, size - 1,

GL_UNSIGNED_SHORT, index);

//glMultiDrawElements(GL_TRIANGLE_STRIP, size - 1,

//GL_UNSIGNED_SHORT, meshIndicesArrays, 512);

glDisableClientState(GL_TEXTURE_COORD_ARRAY);

// Turn off wireframe mode

if(bWireFrame)

{

glPolygonMode(GL_FRONT, GL_FILL);

glPolygonMode(GL_BACK, GL_FILL);

}

}

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;

height--;

width--;

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;

glColor3f(1,1,1);

// Turn on wireframe mode

if(bWireFrame)

{

glPolygonMode(GL_FRONT, GL_LINE);

glPolygonMode(GL_BACK, GL_LINE);

}

glEnableClientState(GL_VERTEX_ARRAY);

glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glDisable(GL_CULL_FACE);

glVertexPointer(2, GL_FLOAT, sizeof(Vertex),

&vertex[0].m_fX);

glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex),

&vertex[0].m_fU);

int iCount = 0; //ToDo: iterate in array to batch

//draw calls...

SetTexture(textures[iCount++]);

glDrawElements( GL_TRIANGLE_STRIP, size - 1,

GL_UNSIGNED_SHORT, index);

//glMultiDrawElements(GL_TRIANGLE_STRIP, size - 1,

//GL_UNSIGNED_SHORT, meshIndicesArrays, 512);

glDisableClientState(GL_TEXTURE_COORD_ARRAY);

// Turn off wireframe mode

if(bWireFrame)

{

glPolygonMode(GL_FRONT, GL_FILL);

glPolygonMode(GL_BACK, GL_FILL);

}

}