游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2522|回复: 1

请教关于Opengl纹理贴图,绘制出来的大小和原图大小不一

[复制链接]

20

主题

98

帖子

98

积分

注册会员

Rank: 2

积分
98
发表于 2011-11-9 17:14:00 | 显示全部楼层 |阅读模式
我知道可以通过控制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];

0

主题

86

帖子

453

积分

中级会员

Rank: 3Rank: 3

积分
453
发表于 2011-11-9 17:47:00 | 显示全部楼层

Re:请教关于Opengl纹理贴图,绘制出来的大小和原图大小不一

用正投影,glOrtho 代替 透视投影 gluPerspective
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-6-8 20:19

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表