我是OpenGL的新手,当我将图像渲染为与图像大小相同的四边形的纹理时,我遇到了一些问题。这是我的代码。如果有人能帮我解决这个问题,我将不胜感激。图像看起来要小得多,而且被挤压了。(顺便说一句,图像尺寸为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();发布于 2011-01-12 01:22:15
首先,您的图像尺寸必须是2的幂,而不是任意的500x375。其次,glTexImage2D的internalformat (第三个)参数应该是一个符号常量,用于描述内部格式布局,而不仅仅是"4",因为从OpenGL 1.2开始就不推荐使用它了。第三,您的dataP和bufferP存储布局必须与当前GL_UNPACK_ALIGNMENT相对应。第四,你试图在其上放置纹理的等边四边形基本上是正方形的,因此你的非正方形纹理将在这样的纹理坐标下看起来被挤压或拉伸。
发布于 2010-03-18 02:33:53
我想我在这里看到你的问题了。glViewport定义视口大小,而不是窗口大小。因此,当您创建窗口时(使用glut、sdl或wgl或其他任何工具),您必须指定大小。要获得glViewport到此窗口的1:1映射,这两个窗口需要匹配。
https://stackoverflow.com/questions/2463733
复制相似问题