Есть рамка https://ibb.co/jDpYGM2 при работе кода она отрисовывается становится синеватым https://ibb.co/3rff9n7 Вот код:
const GLchar* vertexShaderSource = "#version 330 core\n"
"layout(location = 0) in vec3 position;\n"
"layout(location = 1) in vec4 color;\n"
"layout(location = 2) in vec2 texCoord;\n"
"out vec4 ourColor;\n"
"out vec2 TexCoord;\n"
"uniform mat4 transform;\n"
"void main()\n"
"{\n"
"gl_Position = transform*vec4(position, 1.0f);\n"
"ourColor = color;\n"
"TexCoord = texCoord;\n"
"}\0";
const GLchar* fragmentShaderSource = "#version 330 core\n"
"in vec4 ourColor;\n"
"in vec2 TexCoord;\n"
"out vec4 color;\n"
"uniform sampler2D ourTexture;\n"
"void main()\n"
"{\n"
"color = texture(ourTexture, TexCoord);\n"
"}\0";
//...
void Scene1::LoadBorder(QOpenGLExtraFunctions* f)
{
float buf2[] =
{ // x, y, z, r, g, b, a, s, t
-1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
-1.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0,
1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0,
1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0,
-1.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0,
1.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 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);
indices_2 = new GLuint[6];
for (int i = 0; i < 6; i++)
indices_2[i] = (GLuint)i;
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, 9 * sizeof(GLfloat), (GLvoid*)0);
f->glEnableVertexAttribArray(0);
// Color attribute
f->glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 9 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));
f->glEnableVertexAttribArray(1);
// TexCoord attribute
f->glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 9 * sizeof(GLfloat), (GLvoid*)(7 * sizeof(GLfloat)));
f->glEnableVertexAttribArray(2);
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);
}
void Scene1::ShowBorder(QOpenGLExtraFunctions* f, GLuint shaderProgram)
{
f->glUseProgram(shaderProgram);
//f->glBindBuffer(GL_ARRAY_BUFFER, buffer2);
f->glBindVertexArray(vao2);
glBindTexture(GL_TEXTURE_2D, id3);
GLfloat trans2[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
};
unsigned int transformLoc = f->glGetUniformLocation(shaderProgram, "transform");
f->glUniformMatrix4fv(transformLoc, 1, GL_FALSE, trans2);
glEnable(GL_ALPHA_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glTexEnvf(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_BLEND);
f->glDrawArrays(GL_TRIANGLES, 0, 6);
glDisable(GL_BLEND);
glDisable(GL_ALPHA_TEST);
f->glBindVertexArray(0);
}