openGL旋转时变形!
void ImageGL::render(int field_num,int pos,bool control,int channelN) const {
float x0=0 ,y0=0,x1=1,y1=1;
// 加载纹理
//glPushMatrix();
//glRotated(1, 0.0, 0.0, 1.0);
//gluLookAt (0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0);
//glLoadIdentity();
////眼睛的位置,眼睛看物体的位子,眼睛看物体的角度
//gluLookAt (0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0);
//glScaled(0.6,0.6,0.0F);
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, gl_pbo_[field_num]); //上传纹理
glBindTexture (GL_TEXTURE_TYPE, gl_texid_[field_num]); //绑定纹理编号
glTexSubImage2D(GL_TEXTURE_TYPE, 0, 0, 0, nTexWidth_, nTexHeight_, GL_BGRA, GL_UNSIGNED_BYTE, 0);
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0); //借宿纹理
// fragment program is required to display floating point texture
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, gl_shader_);
glEnable(GL_FRAGMENT_PROGRAM_ARB);
glDisable(GL_DEPTH_TEST);
float fTexWidth = (float)nWidth_ / (float)nTexWidth_;
float fTexHeight= (float)nHeight_/ (float)nTexHeight_;
if(control == false){
MapChannel(nScreenMode,pos,&x0,&y0,&x1,&y1);
//gluLookAt (0.0, 0.0, 2.0, 0.0, 0.0, 0.0, x1/2, y1, 0.0);
}else{
ReMapChannel(nScreenMode,pos,&x0,&y0,&x1,&y1,channelN);
}
slice(x0*nWidth_,y0*nHeight_,x1*nWidth_,y1*nHeight_);
//glViewport(0, 0, 1362, 766);
//gluPerspective(45, 1080/1920, 3.0, 10.0);
glBindTexture(GL_TEXTURE_TYPE, 0);
glDisable(GL_FRAGMENT_PROGRAM_ARB);
if(bisCurrent){
glLineWidth(4);
glColor3i(1.0f,0,0);
}else{
glLineWidth(1);
glColor3i(0,1.0f,0);
}
if(t == 0){
glRotated(45, 0.0, 0.0, 1.0); // 这里坐标系设置的时(2.0, 2.0, 0.0),不是正常设置的(1.0, 1.0, 1.0)
glScalef(0.6,0.6,1.0f);
t++;
}
Frame(x0*nWidth_,y0*nHeight_,x1*nWidth_,y1*nHeight_);
}
void ImageGL::slice(float x,float y,float w,float h) const{
glBegin(GL_QUADS);{
glTexCoord2f(0 , (GLfloat) nTexHeight_); glVertex2f (x , y);
glTexCoord2f((GLfloat) nTexWidth_, (GLfloat) nTexHeight_); glVertex2f (x+w , y);
glTexCoord2f((GLfloat) nTexWidth_, 0); glVertex2f (x+w , y+h);
glTexCoord2f(0 , 0); glVertex2f (x , y+h) ;
}glEnd();
}
在旋转的过程中图像会被拉伸!求指导