views:

361

answers:

2

Hi there, I am relatively new to OpenGL and I am having some issues when I am rendering an image as a texture for a QUAD which is as the same size of the image. Here is my code. I would be very grateful if someone helps me to solve this problem. The image appears way smaller and is squished. (BTW, the image dimensions are 500x375).

glGenTextures( 1, &S_GLator_InputFrameTextureIDSu );
        glBindTexture(GL_TEXTURE_2D, S_GLator_InputFrameTextureIDSu);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
        glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);

        glTexImage2D( GL_TEXTURE_2D, 0, 4, S_GLator_EffectCommonData.mRenderBufferWidthSu, S_GLator_EffectCommonData.mRenderBufferHeightSu, 0, GL_RGBA, GL_UNSIGNED_BYTE, dataP);
glBindTexture(GL_TEXTURE_2D, S_GLator_InputFrameTextureIDSu);
        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, S_GLator_EffectCommonData.mRenderBufferWidthSu, S_GLator_EffectCommonData.mRenderBufferHeightSu, GL_RGBA, GL_UNSIGNED_BYTE, bufferP);
//set the matrix modes
        glMatrixMode( GL_PROJECTION );
        glLoadIdentity();
        //gluPerspective( 45.0, (GLdouble)widthL / heightL, 0.1, 100.0 );
        glOrtho (0, 1, 0, 1, -1, 1);
        // Set up the frame-buffer object just like a window.
        glViewport( 0, 0, widthL, heightL );
        glDisable(GL_DEPTH_TEST);
        glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );


        glMatrixMode( GL_MODELVIEW );
        glLoadIdentity();


        glBindTexture( GL_TEXTURE_2D, S_GLator_InputFrameTextureIDSu );


        //Render the geometry to the frame-buffer object


        glBegin(GL_QUADS); //input frame
            glColor4f(1.f,1.f,1.f,1.f);
            glTexCoord2f(0.0f,0.0f);    
            glVertex3f(0.f ,0.f ,0.0f);
            glTexCoord2f(1.0f,0.0f);    
            glVertex3f(1.f ,0.f,0.0f);
            glTexCoord2f(1.0f,1.f); 
            glVertex3f(1.f ,1.f,0.0f);
            glTexCoord2f(0.0f,1.f); 
            glVertex3f(0.f ,1.f,0.0f);
        glEnd();
A: 

I think I see you issue here. glViewport defines the viewport size, not the window size. So when you create your window (with glut, sdl, or wgl, or whatever), you have to specify the size. To get a 1:1 mapping of the glViewport to this window, those two need to match.

Timothy Baldridge
Thank you for the reply. If am rendering it to an FBO, so there is no window here. Even if put the view port sizes in the "glOrtho (0, 1, 0, 1, -1, 1);" I get the same problem. Also on an interesting note, I can draw the QUAD perfectly without any size issues, but I am having problem with the textures. Hope that might help a little bit more to understand the problem.
gutsblow
and I'm assuming your fbo is non-square? The one thing that's making this a tad hard to figure out is that you've got a different vertical and horizontal pixel size. You're texture is non-square, but yet you've coded the above as if it was.....now there's nothing wrong with this approach, but id does make it a bit hard to figure out. What happens if, instead of using 0-1 as your coordinates you re-write it to use 0-width.
Timothy Baldridge
btw...0-1 should read "zero to one" not "zero minus one"
Timothy Baldridge
+1  A: 

Ok, somebody replied me yesterday to change the texture coordinates by dividing the image dimensions with the nearest power of two number and that worked! I don't know why I dont see that answer today, but anyways thank you all for taking time to help me out.

gutsblow