void GLSLShader::initialize() { //#0 PREPARE SHADER GLuint vertexShader; GLuint fragmentShader; vertexShader = prepareShader("basicNew.vert", GLSL::VERTEX); fragmentShader = prepareShader("basicNew.frag", GLSL::FRAGMENT); //#1 CREATE PROGRAM HANDLER programHandle = glCreateProgram(); //programHandle = glCreateProgram(); if(0 == programHandle) { logString += "Error creating program object\n"; exit(1); } //#2 ATTACH SHADER TO PROGRAM glAttachShader( programHandle, fragmentShader ); glAttachShader( programHandle, vertexShader ); ///////////////////////////////////////////////////////////////////////////////////////////////////// std::vector<Eigen::Vector4f> vdata; vdata.push_back(Eigen::Vector4f(-1, -1, 0, 1)); vdata.push_back(Eigen::Vector4f(1, -1, 0, 1)); vdata.push_back(Eigen::Vector4f(0, 1, 0, 1)); std::vector<Eigen::Vector4f> vdataColor; vdataColor.push_back(Eigen::Vector4f(1, 0, 0, 1)); vdataColor.push_back(Eigen::Vector4f(0, 1, 0, 1)); vdataColor.push_back(Eigen::Vector4f(0, 0, 1, 1)); createVertexAttribute(0, "in_Vertex_Position", vdata); // createVertexTFAttribute(0, "in_Vertex_Position", vdata); size = vdata.size() * 4; createVertexTFAttribute2("Color"); // createVertexAttribute(1, "in_Vertex_Color", vdataColor); ////////////////////////////////////////////////////////////////////// //#3 LINK PROGRAM link(); //#4 USE PROGRAM if(isLinked())use(); printActiveAttribs(); }
void SmokeSource::createArrayBuffer(GLfloat* vertex_data, GLfloat* position_data) { GLuint error; // create vertex array glGenVertexArrays(1, &vertex_array); if ((error = glGetError()) != GL_NO_ERROR) std::cerr << "init buffer error, gen vertex array: " << error << std::endl; // bind vertex array glBindVertexArray(vertex_array); if ((error = glGetError()) != GL_NO_ERROR) std::cerr << "init buffer error, bind vertex array: " << error << std::endl; createVertexAttribute(vertex_data); createTextureAttribute(texture_data); createPositionAttribute(); }
std::shared_ptr< GLSLMaterial > MaterialFactory::createMaterial( tinyxml2::XMLElement* node , const aiScene* scene ) { std::shared_ptr< GLSLMaterial > myMaterial = std::shared_ptr< GLSLMaterial > ( new GLSLMaterial() ); for( tinyxml2::XMLElement* loopNode = node->FirstChildElement(); loopNode != NULL; loopNode=loopNode->NextSiblingElement() ) { if( strcmp( loopNode->Name() , "vertex_attribute" ) == 0 ) { myMaterial->addVertexAttribute( createVertexAttribute( loopNode , scene ) ); } else if( strcmp( loopNode->Name() , "program" ) == 0 ) { myMaterial->setProgram( createProgram( loopNode , myMaterial ) ); } } return myMaterial; }