Ошибка: Вызвано исключение по адресу 0x000000006CA7CC00 (nvoglv64.dll): 0xC0000005: нарушение прав доступа при чтении по адресу 0x0000000000000000. Вот код часть его работает, но когда добавляю вторую часть сыпется ошибка
std::set<float> sleft, sright;
sleft.insert(-0.78);
sleft.insert(-0.48);
sleft.insert(-0.16);
sleft.insert(0.16);
sleft.insert(0.48);
sright.insert(-0.48);
sright.insert(-0.16);
sright.insert(0.16);
sright.insert(0.48);
sright.insert(0.78);
std::set<float>::iterator itr, itrright;
int jIter = 0, nn = 288;
int n = 10;
float* buf = new float[nn * n * 5];
indices = new GLuint[36 * n * 5];
for (itr = sleft.begin(), itrright = sright.begin();
itr != sleft.end(); itr++, itrright++)
{
float xleft = *itr;
float xright = *itrright;
for (int i = 0; i < n; i++)
{
//front up
float yTex = 1 - (float)i / n;
float yTex2 = 1 - (float)(i + 1) / n;
buf[(0 + i * nn) + jIter * n * nn] = xleft;
buf[(1 + i * nn) + jIter * n * nn] = 0.68f * sin((90.0 - 60.0 / n * i) * 0.0175);
buf[(2 + i * nn) + jIter * n * nn] = 0.68f * cos((90.0 - 60.0 / n * i) * 0.0175);
buf[(3 + i * nn) + jIter * n * nn] = 0.0;
buf[(4 + i * nn) + jIter * n * nn] = 0.0;
buf[(5 + i * nn) + jIter * n * nn] = 0.0;
buf[(6 + i * nn) + jIter * n * nn] = 0.0;//1.0
buf[(7 + i * nn) + jIter * n * nn] = yTex;
//...etc
}
}
GLuint buffer;
f->glGenVertexArrays(1, &vao);
f->glGenBuffers(1, &buffer);
f->glBindVertexArray(vao);
f->glBindBuffer(GL_ARRAY_BUFFER, buffer);
f->glBufferData(GL_ARRAY_BUFFER, sizeof(float) * nn * n * 5, buf, GL_STATIC_DRAW);
for (int i = 0; i < 36 * n; i++)
indices[i] = (GLuint)i;
GLuint EBO;
f->glGenBuffers(1, &EBO);
f->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
f->glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint) * 60, indices, GL_STATIC_DRAW);
f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*)0);
f->glEnableVertexAttribArray(0);
f->glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));
f->glEnableVertexAttribArray(1);
f->glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*)(6 * sizeof(GLfloat)));
f->glEnableVertexAttribArray(2);
f->glEnableVertexAttribArray(0);
f->glBindBuffer(GL_ARRAY_BUFFER, 0);
f->glBindVertexArray(0);
glClearColor(0, 0, 0, 0);
image1.load("content//drum//auto1.png");
texture = new QOpenGLTexture(image1.mirrored());
texture->setMinificationFilter(QOpenGLTexture::LinearMipMapLinear);
texture->setMagnificationFilter(QOpenGLTexture::Linear);
glGenTextures(1, &id);
glBindTexture(GL_TEXTURE_2D, id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image1.width(), image1.height(),
0, GL_RGBA, GL_UNSIGNED_BYTE, image1.bits());
image1.load("content//drum//auto2.png");
texture2 = new QOpenGLTexture(image1.mirrored());
texture2->setMinificationFilter(QOpenGLTexture::LinearMipMapLinear);
texture2->setMagnificationFilter(QOpenGLTexture::Linear);
glGenTextures(1, &id2);
glBindTexture(GL_TEXTURE_2D, id2);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image1.width(), image1.height(),
0, GL_RGBA, GL_UNSIGNED_BYTE, image1.bits());
glBindTexture(GL_TEXTURE_2D, 0);
/* проблема начинается после этого добавления этого кода*/
float buf2[] =
{// x, y, z, r, g, b, s, t
-1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0,
-1.0, -1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0,
1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0,
1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0,
-1.0, -1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0,
1.0, -1.0, 0.0, 0.5, 0.5, 0.5, 1.0, 1.0
};
GLuint buffer2;
f->glGenVertexArrays(1, &vao2);
f->glGenBuffers(1, &buffer2);
f->glBindVertexArray(vao2);
f->glBindBuffer(GL_ARRAY_BUFFER, buffer2);
f->glBufferData(GL_ARRAY_BUFFER, sizeof(buf2), buf2, GL_STATIC_DRAW);
GLuint indices_2[] = {
0,1,2,
3,4,5
};// Note that we start from 0!
GLuint EBO2;
f->glGenBuffers(1, &EBO2);
f->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO2);
f->glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices_2), indices_2, GL_STATIC_DRAW);
// Position attribute
f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*)0);
f->glEnableVertexAttribArray(0);
// Color attribute
f->glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));
f->glEnableVertexAttribArray(2);
// TexCoord attribute
f->glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*)(6 * sizeof(GLfloat)));
f->glEnableVertexAttribArray(3);
f->glEnableVertexAttribArray(0);
f->glBindBuffer(GL_ARRAY_BUFFER, 0); // Note that this is allowed, the call to glVertexAttribPointer registered VBO as the currently bound vertex buffer object so afterwards we can safely unbind
f->glBindVertexArray(0); // Unbind VAO (it's always a good thing to unbind any buffer/array to prevent strange bugs
image2.load("content//border.png"); // загружаем изображение в переменную image1
// конвертируем изображение в формат для работы с OpenGL:
texture3 = new QOpenGLTexture(image2.mirrored());
texture3->setMinificationFilter(QOpenGLTexture::LinearMipMapLinear);
texture3->setMagnificationFilter(QOpenGLTexture::Linear);
glGenTextures(1, &id3);
glBindTexture(GL_TEXTURE_2D, id3);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image2.width(), image2.height(),
0, GL_RGBA, GL_UNSIGNED_BYTE, image2.bits());
glBindTexture(GL_TEXTURE_2D, 0);
glEnable(GL_DEPTH_TEST);
f->glUseProgram(shaderProgram);
f->glBindVertexArray(vao);
GLfloat trans[16] =
{
1.0,0.0,0.0,0.0,
0.0,1.0 * cos(rotate__ * 0.0175),0.0 - sin(rotate__ * 0.0175),0.0,
0.0,0.0 + sin(rotate__ * 0.0175),1.0 * cos(rotate__ * 0.0175),0.0,
0.0,0.0,0.0,1.0
};
rotate__ += 1;
if (rotate__ >= 360)
rotate__ = 0;
unsigned int transformLoc = f->glGetUniformLocation(shaderProgram, "transform");
f->glUniformMatrix4fv(transformLoc, 1, GL_FALSE, trans);
for (int j = 0; j < 5; j++)
{
glBindTexture(GL_TEXTURE_2D, id);
for (int i = 0 + j * 10; i < 10 + j * 10; i++)
f->glDrawArrays(GL_TRIANGLES, 36 * i, 6/* 36 * 10 * 5*/);
glBindTexture(GL_TEXTURE_2D, id2);
for (int i = 0 + j * 10; i < 10 + j * 10; i++)
f->glDrawArrays(GL_TRIANGLES, 36 * i + 6, 6/* 36 * 10 * 5*/);
glBindTexture(GL_TEXTURE_2D, id);
for (int i = 0 + j * 10; i < 10 + j * 10; i++)
f->glDrawArrays(GL_TRIANGLES, 36 * i + 12, 6/* 36 * 10 * 5*/);
glBindTexture(GL_TEXTURE_2D, id2);
for (int i = 0 + j * 10; i < 10 + j * 10; i++)
f->glDrawArrays(GL_TRIANGLES, 36 * i + 18, 6/* 36 * 10 * 5*/);
glBindTexture(GL_TEXTURE_2D, id);
for (int i = 0 + j * 10; i < 10 + j * 10; i++)
f->glDrawArrays(GL_TRIANGLES, 36 * i + 24, 6/* 36 * 10 * 5*/);
glBindTexture(GL_TEXTURE_2D, id2);
for (int i = 0 + j * 10; i < 10 + j * 10; i++)
f->glDrawArrays(GL_TRIANGLES, 36 * i + 30, 6/* 36 * 10 * 5*/);
}
/*вот добавленный код код выше для отрисовки работает*/
f->glBindVertexArray(vao2);
glBindTexture(GL_TEXTURE_2D, id3);
f->glDrawArrays(GL_TRIANGLES, 0, 6);
f->glBindVertexArray(0);