PDA

View Full Version : Texture from image region of interest



Debian
11-29-2015, 11:03 PM
Hello!
I output several images as panorama, for this I use one texture and glTexSubImage2D function.
Initiliaze code:

GLuint _texture;
GLfloat _vertecies[4 * 2];
GLfloat _txcoord[4 * 2];

_vertecies[0] = 0; // x0
_vertecies[1] = 0; // y0
_vertecies[2] = 1; // x1
_vertecies[3] = 0; // y1
_vertecies[4] = 1; // x2
_vertecies[5] = 1; // y2
_vertecies[6] = 0; // x3
_vertecies[7] = 1; //y3
_txcoord[0] = 0; // s0
_txcoord[1] = 0; // t0
_txcoord[2] = 1; // s1
_txcoord[3] = 0; // t1
_txcoord[4] = 1; // s2
_txcoord[5] = 1; // t2
_txcoord[6] = 0; // s3
_txcoord[7] = 1; // t3

glClearColor(0, 0, 0, 1);
glEnable(GL_TEXTURE_2D);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glGenTextures(1, &_texture);
glBindTexture(GL_TEXTURE_2D, _texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glOrtho(0, 1, 1, 0, -1, 1);
glVertexPointer(2, GL_FLOAT, 0, _vertecies);
glTexCoordPointer(2, GL_FLOAT, 0, _txcoord);
Paint code

glBindTexture(GL_TEXTURE_2D, _texture);
glDrawArrays(GL_QUADS, 0, 4);
But on some images I should output only region of interest, e.g. 100x100 with left top corner on 10x15 from image 1920x1080, now I use follow code for this:

if (is_have_roi)
image = image.copy(roi);

glBindTexture(GL_TEXTURE_2D, _texture);
glTexSubImage2D(GL_TEXTURE_2D, 0, _offset_x[pos], _offset_y[pos], width, height, type, GL_UNSIGNED_BYTE, data);
This is work, but isn't quick.
Can I solve this with OpenGL function?
Thank you and excuse my bad english.