我有一个将 RGB 视频帧呈现到窗口的功能。如果窗口尺寸相同,这对于捕获的尺寸(640 x 480)来说很好,但是当我调整窗口大小时,渲染不正确:
img http://img855.imageshack.us/img855/1694/screenshot20120404at536.png
编辑:现在工作的功能。
static inline void draw_rgb(
unsigned char * buf, unsigned x, unsigned y, unsigned window_width,
unsigned window_height, unsigned frame_width, unsigned frame_height
)
{
glEnable(GL_TEXTURE_RECTANGLE_EXT);
glBindTexture(GL_TEXTURE_RECTANGLE_EXT, 1);
glTextureRangeAPPLE(GL_TEXTURE_RECTANGLE_EXT, window_width * window_height * 2, buf);
glTexImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, GL_RGBA, frame_width, frame_height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, buf);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_TEXTURE_2D);
glViewport(x, y, window_width, window_height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho((GLfloat)0, (GLfloat)window_width, (GLfloat)0, (GLfloat)window_height, -1.0, 1.0);
glBindTexture(GL_TEXTURE_RECTANGLE_EXT, 1);
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glBegin(GL_QUADS);
{
glTexCoord2f(0.0f, 0.0f);
glVertex2f(0.0f, window_height);
glTexCoord2f(0.0f, frame_height);
glVertex2f(0.0f, 0.0f);
glTexCoord2f(frame_width, frame_height);
glVertex2f(window_width, 0.0f);
glTexCoord2f(frame_width, 0.0f);
glVertex2f(window_width, window_height);
}
glEnd();
}