Sign in to follow this  
godkane

glArrayElement, glDrawElements C#

Recommended Posts

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);

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this