I have such a OpenGL-4 code (see below). I have created a buffer for vertices and wanted to initialize it with the help of for-loop in init().
It should be a circle of 30 lines (surrounded by circle later) but I can see only the first line on the screen. And I have done such things before with glVertex. But with VOA I don't really know what to do; I tried a lot but I'm really puzzled; May be It's some stupid mistake or my misunderstanding, I failed to find it. is it possible to do so with VOAs at all?
GLuint lineArrayID;
GLuint lineVertexBuffer;
GLuint numLines = 30;
static GLfloat lineVertexBufferData[30][2] = {};
void init() {
draw_circle();
glClearColor(1.0, 1.0, 1.0, 1.0);//background of the window
GLfloat x, y;
double angle;
GLfloat radius = 5.0;
angle = 2 * PI / 30;
int j = 0;
float i = 0;
for (i = -PI; i < -PI; i += 0.15){
std::cout << " +"<<std:: endl;
x = sin(i);
y = cos(i);
lineVertexBufferData[j][0] = 0.0; lineVertexBufferData[j][1] = 0.0;
lineVertexBufferData[j][0] = x; lineVertexBufferData[j][1] = y;
j++;
}
// compile and activate the desired shader program
shaderProgramID = loadShaders("D.vs", "D.fs");
glUseProgram(shaderProgramID);
// generate Buffers for our objects
prepareLines();
}
void prepareLines(){
glGenVertexArrays(1, &lineArrayID); //gen one array object
glBindVertexArray(lineArrayID); //binds it
glGenBuffers(1, &lineVertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, lineVertexBuffer);
glBufferData(GL_ARRAY_BUFFER, numLines * 60 * sizeof(GLfloat), lineVertexBufferData, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
glEnableVertexAttribArray(0);
glBindVertexArray(0);
}
static void display(void) {
glClear(GL_COLOR_BUFFER_BIT);
// drawing the lines
glBindVertexArray(lineArrayID);
glCallList(1);
glDrawArrays(GL_LINES, 0, numLines * 2);
glBindVertexArray(0);
transform();
//glRotatef(grad, 0, 0, 1);
//glutSwapBuffers();
glFlush();
}