0

I'm using OpenGL with g++. This simple code works fine in my system. It draws a rectangle as expected.

GLfloat vertices[] = 
{
    0,0,0,  //0
    0,6,0,  //1
    6,6,0,  //2
    6,0,0,  //3
};
GLint indices[] = {0,1,2,3};
glColor3f(1,0,0);
glVertexPointer (3, GL_FLOAT, 0, vertices);
glDrawElements(GL_QUADS, 4, GL_UNSIGNED_INT, indices);

But in my friend's system, it gives segmentation fault.

I changed GL_UNSIGNED_INT to GL_INT. Then at least it does not give segmentation fault but its not rendering anything.

What can be the reason for this?

Shashwat
  • 2,538
  • 7
  • 37
  • 56
  • There si lots of GL state which might be relevant here. For example, do you have other arrays enabled? – derhass Apr 16 '14 at 13:18
  • I have `glEnableClientState (GL_COLOR_ARRAY);` and `glEnableClientState (GL_VERTEX_ARRAY);`. Do I need to have anything else? – Shashwat Apr 16 '14 at 14:14
  • In the code above, there is no color array. So if you have this still enabled from some previous draw call, you must explicitely disable it. – derhass Apr 16 '14 at 16:54
  • It would make more sense if you post more of the relevant code. Since OpenGL acts as a state machine there's a lot we can miss looking at a snippet of the code. – Harsh Jul 07 '16 at 11:09

1 Answers1

0

Read your documentation carefully

Don't forget to glEnableClientState(GL_VERTEX_ARRAY);

mrVoid
  • 995
  • 7
  • 17