I have a function that renders RGB video frames to a window. This works fine for the captured dimensions (640 x 480) if the window is the same dimensions but when I resize the window the rendering is not correct:
img http://img855.imageshack.us/img855/1694/screenshot20120404at536.png
Edit: The now working function.
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();
}
Your problem is a combination of two factors.
First, as datenwolf pointed out, your texture’s width/height is constant. It doesn’t change when the window’s size does. BTW, you shouldn’t be rebuilding the texture every frame unless the texture’s data changes. And even then, you can upload changes with
glTexSubImage2Drather thanglTexImage. You don’t need to call theglTexParameterstuff either.Second, this also means that your texture coordinates don’t change. So you need to change your quad drawing to be this: