四角形

quadrilateral.png

初期化

GLuint vbo;
    glGenBuffers(1, &vbo);
    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    int imageresoloc = glGetUniformLocation(id, "uImageResolution");
    glUniform2f(imageresoloc,(float)image.cols, (float)image.rows);
    static const GLfloat quad_data[] = {
        0.0f,0.0f,
        1.0, 0.0,
        1.0, 1.0,
        0.0f,1.0,
    };
    glBufferData(GL_ARRAY_BUFFER, sizeof(quad_data), quad_data, GL_STATIC_DRAW);

描画

void BackGround::draw()
{
    glUseProgram(id);
    glBindVertexArray(vao);
    glActiveTexture(GL_TEXTURE0);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, textureId);
    glUniform1i(sampler, 0);
    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
    glDisable(GL_TEXTURE_2D);
    glUseProgram(0);
}

rectangle

サポートサイト Wikidot.com rectangle