Hi there,
I tried to render two 2D textures into a GL_QUADS and do alpha blending in Fragment shader, texture0 is the background texture, and texture1 is the one on top. Since we want to create the texture’s width and height based on 2^n, so for example, for the video size at 1280x720, we will create the texture0 size at 2048x1024 using glTexImage2D, and then we update texture using glTexSubImage2D at size 1280x720, that’s mean we will use partially of the texture, and for the texture1, assume the size of frame is 1920x1080, we will create the texture1 at 2048x2048, and then update the texture using glTexSubImage2D at size 1920x1080.
So right now, the problem is how can I adapter those sub-texture’s coordinates, and make sure texture0 fit with texture1. I am using following pseudo code in render function and it is not display texture properly, do have one know how to scale one of texture to fit another, thank you so much.
Kevin.
static const GLfloat v3[ 3 ] = { -1.00, -1.00, 0.0 };
static const GLfloat v2[ 3 ] = { 1.00, -1.00, 0.0 };
static const GLfloat v1[ 3 ] = { 1.00, 1.00, 0.0 };
static const GLfloat v0[ 3 ] = {-1.00, 1.00, 0.0 };
...
glPushMatrix();
glBegin(GL_QUADS);
GLfloat tmp[ 2 ];
tmp[ 0 ] = 0.0; tmp[ 1 ] = 0.0;
glMultiTexCoord2fv( GL_TEXTURE0, tmp );
glMultiTexCoord2fv( GL_TEXTURE1, tmp );
glVertex3fv(v0);
tmp[ 0 ] = (GLfloat)1280/(GLfloat)2048; tmp[ 1 ] = 0.0;
glMultiTexCoord2fv( GL_TEXTURE0, tmp );
tmp[ 0 ] = (GLfloat)1920/(GLfloat)2048; tmp[ 1 ] = 0.0;
glMultiTexCoord2fv( GL_TEXTURE1, tmp );
glVertex3fv(v1);
tmp[ 0 ] = (GLfloat)1280/(GLfloat)2048; tmp[ 1 ] = (GLfloat)720/(GLfloat)1024;
glMultiTexCoord2fv( GL_TEXTURE0, tmp );
tmp[ 0 ] = (GLfloat)1920/(GLfloat)2048; tmp[ 1 ] = (GLfloat)1080/(GLfloat)2048;
glMultiTexCoord2fv( GL_TEXTURE1, tmp );
glVertex3fv(v2);
tmp[ 0 ] = 0.0; tmp[ 1 ] = (GLfloat)720/(GLfloat)1024;
glMultiTexCoord2fv( GL_TEXTURE0, tmp );
tmp[ 0 ] = 0.0; tmp[ 1 ] = (GLfloat)1080/(GLfloat)2048;
glMultiTexCoord2fv( GL_TEXTURE1, tmp );
glVertex3fv(v2);
glEnd();
glPopMatrix();