Viewport resize and fit

Hello, I’me writing a project to display a video on screen and then draw enhanced information with OpenGL in overlay on it.
My problem is that I’d like to have a resizeable window with constanct aspect ratio, or I can force it to resize keeping the aspect ratio by myself, this is nor the problem.
The problem is that I’d like to have the video frames resize automatically and have the screen coordinates unchanged so that every opengl call keeps working as if the screen coordinates are always the same ones when the window was initialized.
I tried to do this drawing the video frame with glDrawPixels and resizing it with glPixelZoom but even though the zoom changed, the cropped area was always of the same amout of physical pixels and the remaining part was black.
So I tried with textures, but the problem is the same… with textures I also have another problem, that is blur and fastidious bad interpolation between frames… and I enabled GL_LINEAR for both MIN and MAX filters.

Please I am asking your help because I’m not kin with glViewport and resizement and how this impact on the management of screen coordinates.

some code


			glRasterPos2i(0, VIDEO_HEIGHT);
			glPixelZoom(1.0, -1.0);	

			//glPixelZoom(panelGL->Width*1.0/VIDEO_WIDTH, -panelGL->Height*1.0/VIDEO_HEIGHT);	
			//glRasterPos2i(0, VIDEO_HEIGHT);
			
			glDrawPixels(VIDEO_WIDTH, VIDEO_HEIGHT, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, (void*)context->pixels);



glTexImage2D(GL_TEXTURE_2D, 0, 3, VIDEO_WIDTH, VIDEO_HEIGHT, 0, GL_BGRA, GL_UNSIGNED_BYTE, (void*)context->pixels);




  glBegin(GL_POLYGON);
    glTexCoord2f(0.0f, 1.0f);
    glVertex3f(0, 0, 0.0f);
    glTexCoord2f(1.0f, 1.0f);
    glVertex3f( VIDEO_WIDTH, 0, 0.0f);
    glTexCoord2f(1.0f, 0.0f);
    glVertex3f( VIDEO_WIDTH, VIDEO_HEIGHT, 0.0f);
    glTexCoord2f(0.0f, 0.0f);
    glVertex3f( 0, VIDEO_HEIGHT, 0.0f);
  glEnd();

and when I have a resize event I call
glViewport(0,0,new_width,new_height);

You dont want to use glPixelZoom. You want to change your camera parameters to include more or less of the scene depending on your window size so the aspect ratio doesnt change.

Read section 9.140 “How do I keep my aspect ratio correct after a window resize?” over here:
http://www.opengl.org/resources/faq/technical/transformations.htm

Actually I am already doing this… My problem at the moment is not the aspect ratio, it is that the texture is cropped!
When I have a resize I call glViewport with the new dimensions.
The texture is a rect with the same new dimensions of the widget, and glOrtho is called with the same new dimensions.

Yet I still have the problem that the texture zooms but is cropped!

Here are two screenshot to show you what happens

Ok, I got you. I cant comment without seeing the bit of code that does the resizing. Post the entire resizing function. Also post the lines where the resize is being called.

Here it is


private: System::Void panelGL_Resize(System::Object^  sender, System::EventArgs^  e) {
			 //this->OpenGL->ReSizeGLScene(panelGL->Width, panelGL->Height);
			 glViewport(0, 0, panelGL->Width, panelGL->Height);
			 System::Diagnostics::Debug::Print("Resizing to {0} x {1}", panelGL->Width, panelGL->Height);
		 }

and then in the VLC callback, before drawing all the augmented reality information, I display the video like this


			glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

			glMatrixMode(GL_PROJECTION);
			glPushMatrix();
			glLoadIdentity();
			//glOrtho(0, VIDEO_WIDTH, 0, VIDEO_HEIGHT, -1, 1);
			glOrtho(0, panelGL->Width, 0, panelGL->Height, -1, 1);

			
			glMatrixMode(GL_MODELVIEW);
			glPushMatrix();
			glLoadIdentity();







			/*
			glRasterPos2i(0, VIDEO_HEIGHT);
			glPixelZoom(1.0, -1.0);	

			//glPixelZoom(panelGL->Width*1.0/VIDEO_WIDTH, -panelGL->Height*1.0/VIDEO_HEIGHT);	
			//glRasterPos2i(0, VIDEO_HEIGHT);
			
			glDrawPixels(VIDEO_WIDTH, VIDEO_HEIGHT, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, (void*)context->pixels);
			*/

  glEnable(GL_TEXTURE_2D);
  
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);



glTexImage2D(GL_TEXTURE_2D, 0, 3, VIDEO_WIDTH, VIDEO_HEIGHT, 0, GL_BGRA, GL_UNSIGNED_BYTE, (void*)context->pixels);




  glBegin(GL_POLYGON);
    glTexCoord2f(0.0f, 1.0f);
    glVertex3f(0, 0, 0.0f);
    glTexCoord2f(1.0f, 1.0f);
    glVertex3f(panelGL->Width, 0, 0.0f);
    glTexCoord2f(1.0f, 0.0f);
    glVertex3f(panelGL->Width, panelGL->Height, 0.0f);
    glTexCoord2f(0.0f, 0.0f);
    glVertex3f(0, panelGL->Height, 0.0f);
  glEnd();


/*
  glBegin(GL_POLYGON);
    glTexCoord2f(0.0f, 1.0f);
    glVertex3f(0, 0, 0.0f);
    glTexCoord2f(1.0f, 1.0f);
    glVertex3f(VIDEO_WIDTH, 0, 0.0f);
    glTexCoord2f(1.0f, 0.0f);
    glVertex3f(VIDEO_WIDTH, VIDEO_HEIGHT, 0.0f);
    glTexCoord2f(0.0f, 0.0f);
    glVertex3f(0, VIDEO_HEIGHT, 0.0f);
  glEnd();
*/

  glDisable(GL_TEXTURE_2D);



I dont think the screen-shots you posted above correspond to the code in your last post. I think the screen-shots are from your code that uses glPixelZoom rather than textures.

In any event, its not completely clear what you are trying to do, especially what you say here:

The problem is that I’d like to have the video frames resize automatically and have the screen coordinates unchanged so that every opengl call keeps working as if the screen coordinates are always the same ones when the window was initialized.

Here is what your code does:
-Loads a texture, retrieved from a frame of video
-Maps that onto a polygon (rectangle)
-Draws the polygon to fill the screen.

If this is the case, then no matter how much you resize the screen, the image should always fill the complete screen (even though the aspect ratio may not be correct).

Is that what you are trying to do?

Yes this is what I am trying to do at the moment, I assure you that those screenshots were taken using a texture and not glDrawPixels… the code I used is the one I posted above… anyway even when I use a texture the problem I have is the same one I have when I use glDrawPixels… actually if possible I’d prefer using glDrawPixels because there is less overhead and above all there is no annoying blur on images introduced by the bad MAG or MIN filters when resizing the texture.
So please if anyone can post the source code to display an image arranged like a RGB matrix in a resizeable window with OpenGL automatically fitting when resizing the window… any help will be much appreciated.

So anyone can help me to find out the reason of this strange behaviour?
I think that if I put ad image on a texture and I use a Ortho view with the same size of the texure I should see an image fitting the whole screen, but it does not work.
I testify that the code I used is above. Please help me.