Jump to content
  • Advertisement
Sign in to follow this  

glDrawElements

This topic is 4592 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to draw a simple cube. Currently this errors out because of the frontIndices looking wierd. private 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}, {-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.2f, 0.2f }, {0.2f, 0.2f, 1.0f }, {0.8f, 1.0f, 0.2f }, {0.75f, 0.75f, 0.75f}, {0.35f, 0.35f, 0.35f}, {0.5f, 0.5f, 0.5f }}; private 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); GL.glDrawElements(GL.GL_QUADS, 1, GL.GL_BYTE, frontIndices);

Share this post


Link to post
Share on other sites
Advertisement
That is a minor issue when there is no lighting. Here is the same code but I know this works. I want to use the one that is much less code, plus should be faster too.(less commands) This is in C# if you couldn't tell. Currently when I run my code it is a black screen, so I'm not understanding how the equation is run with the data that I gave it. I'm reading this from a book that does this in C and everything looks right.
GL.glBegin(GL.GL_QUADS); // Draw A Quad

GL.glColor3f(0.0f,1.0f,0.0f); // Set The Color To Green
GL.glVertex3f( 1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Top)
GL.glVertex3f(-1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Top)
GL.glVertex3f(-1.0f, 1.0f, 1.0f); // Bottom Left Of The Quad (Top)
GL.glVertex3f( 1.0f, 1.0f, 1.0f); // Bottom Right Of The Quad (Top)

GL.glColor3f(1.0f,0.5f,0.0f); // Set The Color To Orange
GL.glVertex3f( 1.0f,-1.0f, 1.0f); // Top Right Of The Quad (Bottom)
GL.glVertex3f(-1.0f,-1.0f, 1.0f); // Top Left Of The Quad (Bottom)
GL.glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Bottom)
GL.glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Bottom)

GL.glColor3f(1.0f,0.0f,0.0f); // Set The Color To Red
GL.glVertex3f( 1.0f, 1.0f, 1.0f); // Top Right Of The Quad (Front)
GL.glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Quad (Front)
GL.glVertex3f(-1.0f,-1.0f, 1.0f); // Bottom Left Of The Quad (Front)
GL.glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom Right Of The Quad (Front)

GL.glColor3f(1.0f,1.0f,0.0f); // Set The Color To Yellow
GL.glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Back)
GL.glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Back)
GL.glVertex3f(-1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Back)
GL.glVertex3f( 1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Back)

GL.glColor3f(0.0f,0.0f,1.0f); // Set The Color To Blue
GL.glVertex3f(-1.0f, 1.0f, 1.0f); // Top Right Of The Quad (Left)
GL.glVertex3f(-1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Left)
GL.glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Left)
GL.glVertex3f(-1.0f,-1.0f, 1.0f); // Bottom Right Of The Quad (Left)

GL.glColor3f(1.0f,0.0f,1.0f); // Set The Color To Violet
GL.glVertex3f( 1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Right)
GL.glVertex3f( 1.0f, 1.0f, 1.0f); // Top Left Of The Quad (Right)
GL.glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom Left Of The Quad (Right)
GL.glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Right)

GL.glEnd();

Share this post


Link to post
Share on other sites
Let me try to explain this again:
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!