<1>HelloWorld.h
#ifndef __HELLOWORLD_SCENE_H__#define __HELLOWORLD_SCENE_H__#include "cocos2d.h"USING_NS_CC;#include<string>using namespace std;class HelloWorld : public cocos2d::Layer{public: HelloWorld(); ~HelloWorld(); static cocos2d::Scene* createScene(); virtual bool init(); CREATE_FUNC(HelloWorld); virtual voID visit(Renderer* renderer,const Mat4& parenttransform,uint32_t parentFlags); voID onDraw();private: CustomCommand _command;};#endif // __HELLOWORLD_SCENE_H__<2>HelloWorld.cpp
#include "HelloWorldScene.h"USING_NS_CC;using namespace std;HelloWorld::HelloWorld(){ }HelloWorld::~HelloWorld(){ }bool HelloWorld::init(){ if ( !Layer::init() ){ return false; } this->setGLProgram(GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_name_position_color)); return true;}voID HelloWorld::visit(Renderer *renderer,uint32_t parentFlags){ Node::visit(renderer,parenttransform,parentFlags); _command.init(_globalZOrder); _command.func = CC_CALLBACK_0(HelloWorld::onDraw,this); Director::getInstance()->getRenderer()->addCommand(&_command);}voID HelloWorld::onDraw(){ auto glProgram = getGLProgram(); glProgram->use(); glProgram->setUniformsForBuiltins(); auto winSize = Director::getInstance()->getWinSize(); float vert[] = { 0,winSize.wIDth,winSize.wIDth/2,winSize.height }; float color[] = { 0,1,//绿 1,//红 0,1 //蓝 }; GL::enabLevertexAttribs(GL::VERTEX_ATTRIB_FLAG_position | GL::VERTEX_ATTRIB_FLAG_color); glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_position,2,GL_float,GL_FALSE,vert); glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_color,4,color); glDrawArrays(GL_TRIANGLES,3); CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,3); CHECK_GL_ERROR_DEBUG();}Scene* HelloWorld::createScene(){ auto scene = Scene::create(); auto layer = HelloWorld::create(); scene->addChild(layer); return scene;}总结
以上是内存溢出为你收集整理的cocos2dx shader 第一个三角形<1>全部内容,希望文章能够帮你解决cocos2dx shader 第一个三角形<1>所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)