YamateDD

iPhone开发 web开发

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

 在群里有同學們為了怎樣用 OpenGL ES 縮放圖像而煩惱,正好我也很久沒更新這個教程了,所以把第三篇的代碼更新了一下,加了縮放和混色的功能。

我也用了 SDK Final 的模塊,重新建立了一次項目。

這次的修改,主要是 CCSprite 的 render, 大家可以參考一下,怎麼用glScalef 來作縮放。

 
复制代码
    1. void CCSprite::render(float x, float y, float angle, float xScale, float yScale)
    2. {
    3.     y = SCREEN_HEIGHT-y;        // for OpenGL ES, (0,0) is at lower left corner!
    4.     
    5.     GLfloat _minU = mX/mTexture->getTextureWidth();
    6.     GLfloat _maxU = (mX+mWidth)/mTexture->getTextureWidth();
    7.     GLfloat _minV = mY/mTexture->getTextureHeight();
    8.     GLfloat _maxV = (mY+mHeight)/mTexture->getTextureHeight();
    9.     
    10.     GLfloat    coordinates[] =
    11.     {
    12.         _minU,    _maxV,
    13.         _maxU,    _maxV,
    14.         _minU,    _minV,
    15.         _maxU,    _minV
    16.     };
    17.     
    18.     GLfloat    xx = - mWidth/2;
    19.     GLfloat yy = - mHeight/2;
    20.     
    21.     GLfloat    vertices[] =
    22.     {
    23.         xx,            yy,                
    24.         xx+mWidth,    yy,                
    25.         xx,            yy+mHeight,
    26.         xx+mWidth,    yy+mHeight    
    27.     };
    28.     
    29.     mTexture->bind();
    30.     
    31.     glColor4f(mRed, mGreen, mBlue, mAlpha);
    32.     
    33.     glPushMatrix();
    34.     glTranslatef(x, y, 0.0f);
    35.     glRotatef(angle, 0.0f, 0.0f, 1.0f);
    36.     glScalef(xScale, yScale, 1.0f);
    37.     glVertexPointer(2, GL_FLOAT, 0, vertices);
    38.     glTexCoordPointer(2, GL_FLOAT, 0, coordinates);
    39.     glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    40.     glPopMatrix();
    41.     
    42.     glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
    43.     
    44. }
posted on 2012-02-03 15:01  YamateDD  阅读(158)  评论(0编辑  收藏  举报