2

my problem is not properly drawing simple plane; I dont know why i get once error at begining : Invalid Operation 1282. Can someone check that?

My variables : GLfloat *tab for verticies plane int *tab2 for indecies

this is my init funcion:

// kolor tła - zawartość bufora koloru
glClearColor( 1.0f, 1.0f, 1.0f, 1.0f );

// wczytanie shaderów i przygotowanie obsługi programu
program=LoadShaders("shader.vert","shader.frag" );

//Vertexy
//VertexArrayID;
glGenVertexArrays(1, &VertexArrayID);
glBindVertexArray(VertexArrayID);

//Verticies;
glGenBuffers(1, &Verticies);
glBindBuffer(GL_ARRAY_BUFFER, Verticies);
glBufferData( GL_ARRAY_BUFFER,foo*sizeof(GLfloat), tab, GL_STATIC_DRAW );

unsigned int m_ciezarkow[]={0,1,0};


//Indicies
glGenBuffers(1,&Indeksy);
glBindBuffer(GL_ARRAY_BUFFER,Indeksy);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int)*size, tab2, GL_STATIC_DRAW); 



glUseProgram( program );

pos_cam=glGetUniformLocation( program, "camera" );
pos_color=glGetUniformLocation( program, "_color" );

glUseProgram(0);

This is my draw function:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(program);
//my camera
glUniformMatrix4fv(pos_cam,1,GL_FALSE,&cam.matrix()[0][0]);

//Verticies
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, Verticies);
glVertexAttribPointer( 0, 3 , GL_FLOAT, GL_FALSE, 0, (void*)0 );

//Masa
//glEnableVertexAttribArray(1);
//glBindBuffer(GL_ARRAY_BUFFER, Masa);
//glVertexAttribPointer( 0, 3 , GL_FLOAT, GL_FALSE, 0, (void*)0 );

//Indicies
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,Indeksy);

glDrawElements(GL_TRIANGLES,size,GL_UNSIGNED_INT,(void*)0); 
glUseProgram( 0 );
glDisableVertexAttribArray(0);`
2
  • 1
    I would start by figuring out which line is giving you the error. If you move the call to glGetError() to different places in your code, can you figure out the exact line? Commented Aug 24, 2013 at 21:12
  • I get this error after first loop draw function. Commented Aug 24, 2013 at 21:18

1 Answer 1

4

There is a mistake here:

//Indicies
glGenBuffers(1,&Indeksy);
glBindBuffer(GL_ARRAY_BUFFER,Indeksy);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int)*size, tab2, GL_STATIC_DRAW); 

You bind Indeksy as GL_ARRAY_BUFFER, but it should be GL_ELEMENT_ARRAY_BUFFER. With your code, there is probably 0 bound as index buffer, and the glBufferData for that target will fail with GL_INVALID_OPERATION.

Sign up to request clarification or add additional context in comments.

1 Comment

I Love You MAN ! I Lost 2 hours of life, probably cuz i'am codding since morning;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.