glArrayElement, glDrawElements C#
I'm trying to get glArrayElements and glDrawElements to work in C# and am having problems. I do not have lighting. Example 1 works like it should, well Example 2 shows a blank screen and Example 3 crashs.
float[,] vertices = {{ -1.0f, -1.0f, 1.0f},
{ 1.0f, -1.0f, 1.0f},
{ 1.0f, 1.0f, 1.0f},
{ -1.0f, 1.0f, 1.0f}};
private float[,] colors = {{1.0f, 0.0f, 1.0f },
{1.0f, 0.0f, 1.0f },
{1.0f, 0.0f, 1.0f },
{1.0f, 0.0f, 1.0f}};
byte[,] frontIndices = {{0, 1, 2, 3}};
GL.glEnableClientState(GL.GL_COLOR_ARRAY);
GL.glEnableClientState(GL.GL_VERTEX_ARRAY);
GL.glColorPointer(3, GL.GL_FLOAT, 0, colors);
GL.glVertexPointer(3, GL.GL_FLOAT, 0, vertices);
Example 1
GL.glColor3f(1.0f,0.0f,1.0f);
GL.glBegin(GL.GL_QUADS);
GL.glVertex3f(vertices[0,0], vertices[0,1], vertices[0,2]);
GL.glVertex3f(vertices[1,0], vertices[1,1], vertices[1,2]);
GL.glVertex3f(vertices[2,0], vertices[2,1], vertices[2,2]);
GL.glVertex3f(vertices[3,0], vertices[3,1], vertices[3,2]);
GL.glEnd();
Example 2
GL.glArrayElement(0);
GL.glArrayElement(1);
GL.glArrayElement(2);
GL.glArrayElement(3);
Example 3
GL.glDrawElements(GL.GL_QUADS, 4, GL.GL_BYTE, frontIndices);
I don't know anything about C# but:
Example 2
With glArrayElements, you still need glBegin and glEnd
GL.glBegin(GL.GL_QUADS);
GL.glArrayElement(0);
GL.glArrayElement(1);
GL.glArrayElement(2);
GL.glArrayElement(3);
GL.glEnd();
Example 3
You're only draw ONE primitive, not 4 (even though there 4 vertices)
GL.glDrawElements(GL.GL_QUADS, 1, GL.GL_BYTE, frontIndices);
8-bit indices aren't usually used. That shouldn't be a problem though
Example 2
With glArrayElements, you still need glBegin and glEnd
GL.glBegin(GL.GL_QUADS);
GL.glArrayElement(0);
GL.glArrayElement(1);
GL.glArrayElement(2);
GL.glArrayElement(3);
GL.glEnd();
Example 3
You're only draw ONE primitive, not 4 (even though there 4 vertices)
GL.glDrawElements(GL.GL_QUADS, 1, GL.GL_BYTE, frontIndices);
8-bit indices aren't usually used. That shouldn't be a problem though
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement