Cocos2dx绘制贴图

Cocos2dx下 基本的OpenGL ES 绘图

分类: cocos2dx   4652人阅读  评论(3)  收藏  举报
[cpp]  view plain copy
  1. void GLFirstLayer::draw()  
  2. {  
  3.    // CCLayer::draw();  
  4.       
  5.       
  6.     //顶点数据  
  7.     static GLfloat vertex[] = {  
  8.         0,0,0,  
  9.         200,0,0,  
  10.         0,200,0,  
  11.         200,200,0  
  12.     };  
  13.       
  14.     //纹理坐标  
  15.     static GLfloat coord[] = {  
  16.         0,1,  
  17.         1,1,  
  18.         0,0,  
  19.         1,0  
  20.     };  
  21.       
  22.     //颜色数据  
  23.     static GLfloat color[] = {  
  24.         1,1,1,1,  
  25.         1,1,1,1,  
  26.         1,1,1,1,  
  27.         1,1,1,1  
  28.     };  
  29.       
  30.       
  31.     //初始化纹理  
  32.     static CCTexture2D* texture2d = NULL;  
  33.     if (!texture2d) {  
  34.         texture2d = CCTextureCache::sharedTextureCache()->addImage("HelloWorld.png");  
  35.     }  
  36.       
  37.     //设置着色器  
  38.     ccGLEnableVertexAttribs(kCCVertexAttribFlag_PosColorTex);  
  39.     texture2d->getShaderProgram()->use();  
  40.     texture2d->getShaderProgram()->setUniformForModelViewProjectionMatrix();  
  41.       
  42.       
  43.     //绑定纹理  
  44.     glBindTexture(GL_TEXTURE_2D, texture2d->getName());  
  45.       
  46.       
  47.     //设置顶点数据  
  48.     glVertexAttribPointer(kCCVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, 0, vertex);  
  49.     glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_FLOAT, GL_FALSE, 0, color);  
  50.     glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, 0, coord);  
  51.       
  52.     //绘图  
  53.     glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);  
  54. }  
上面就绘制了一个矩形,直接重写 draw()方法即可
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值