Я пытаюсь следовать [это] [1] простой учебник, но я получаю следующее сообщение об ошибке при достижении «glDrawArrays»:glDrawArrays Нарушение прав доступа
Необработанное исключение в 0x03D7598E (nvoglv32.dll) в openGLTest.exe : 0xC0000005: Доступ к считыванию с нарушениями доступа 0x00000000.
void createMesh(void) {
float* vertices = new float[18];// Amount of vertices
vertices[0] = -0.5; vertices[1] = -0.5; vertices[2] = 0.0; // Bottom left corner
vertices[3] = -0.5; vertices[4] = 0.5; vertices[5] = 0.0; // Top left corner
vertices[6] = 0.5; vertices[7] = 0.5; vertices[8] = 0.0; // Top Right corner
vertices[9] = 0.5; vertices[10] = -0.5; vertices[11] = 0.0; // Bottom right corner
vertices[12] = -0.5; vertices[13] = -0.5; vertices[14] = 0.0; // Bottom left corner
vertices[15] = 0.5; vertices[16] = 0.5; vertices[17] = 0.0; // Top Right corner
glGenVertexArrays(1, &vaoID[0]); // Create our Vertex Array Object
glBindVertexArray(vaoID[0]); // Bind our Vertex Array Object so we can use it
glGenBuffers(1, vboID); // Generate our Vertex Buffer Object
glBindBuffer(GL_ARRAY_BUFFER, vboID[0]); // Bind our Vertex Buffer Object
glBufferData(GL_ARRAY_BUFFER, 18 * sizeof(GLfloat), vertices, GL_STATIC_DRAW); // Set the size and data of our VBO and set it to STATIC_DRAW
glVertexAttribPointer((GLuint)0, 3, GL_FLOAT, GL_FALSE, 0, 0); // Set up our vertex attributes pointer
glEnableVertexAttribArray(0); // Disable our Vertex Array Object
glBindVertexArray(0); // Disable our Vertex Buffer Object
delete[] vertices; // Delete our vertices from memory
glBindVertexArray(vaoID[0]); // Bind our Vertex Array Object
glDrawArrays(GL_TRIANGLES, 0, 6); // Draw our square
glBindVertexArray(0); // Unbind our Vertex Array Object
}
Я в затруднении относительно того, что вызывает его, поскольку учебник является тем же самым!
Я все еще глядя на код, но по наитию, что происходит если вы удалите 'delete [] vertices;'? – Xirema
Я удалил его, но все же происходит такое же нарушение доступа. – Calco
Хорошо. OpenGL делает забавные вещи за кулисами, поэтому хорошо исключать такие вещи. – Xirema