|
我知道可以通过控制glTranslatef的z参数,来控制远近,但是到底要多少,才能绘制出和原图大小一样的图形.还是说,和gluPerspective这个函数有关系?求指教..感激
下面这个是我的当view尺寸变化时,用来重新初始化的
- (void) reshape
{
float aspect;
NSSize bound = [self frame].size;
aspect = bound.width / bound.height;
// change the size of the viewport to the new width and height
// this controls the affine transformation of x and y from normalized device
// coordinates to window coordinates (from the OpenGl 1.1 reference book, 2nd ed)
glViewport(0, 0, bound.width, bound.height);
glMatrixMode(GL_PROJECTION);
// you must reload the identity before this or you'll lose your picture
glLoadIdentity();
gluPerspective(45.0f, (GLfloat)aspect, 0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
下面是我绘制的代码
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// this is where you would want to draw
glTranslatef(0.0,0.0,-15.0);
glColor3f(1.0,1.0,1.0);
glBindTexture(GL_TEXTURE_2D, texture);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Texture and Quad
glEnd();
// flush the buffer! (send drawing to the screen)
[[self openGLContext] flushBuffer]; |
|