void Model::setTexCoords(const Vertices& texCoords) { m_texCoords.resize(texCoords.size()); std::memcpy(m_texCoords.data(), texCoords.data(), texCoords.size() * 2 * sizeof(float)); if (m_texCoordsVBO) { m_texCoordsVBO.bind(); m_texCoordsVBO.write(texCoords); m_texCoordsVBO.release(); } }
bool MDAL::LoaderGdal::initVertices( Vertices &vertices ) { Vertex *VertexsPtr = vertices.data(); unsigned int mXSize = meshGDALDataset()->mXSize; unsigned int mYSize = meshGDALDataset()->mYSize; const double *mGT = meshGDALDataset()->mGT; for ( unsigned int y = 0; y < mYSize; ++y ) { for ( unsigned int x = 0; x < mXSize; ++x, ++VertexsPtr ) { // VertexsPtr->setId(x + mXSize*y); VertexsPtr->x = mGT[0] + ( x + 0.5 ) * mGT[1] + ( y + 0.5 ) * mGT[2]; VertexsPtr->y = mGT[3] + ( x + 0.5 ) * mGT[4] + ( y + 0.5 ) * mGT[5]; VertexsPtr->z = 0.0; } } BBox extent = computeExtent( vertices ); // we want to detect situation when there is whole earth represented in dataset bool is_longitude_shifted = ( extent.minX >= 0.0 ) && ( fabs( extent.minX + extent.maxX - 360.0 ) < 1.0 ) && ( extent.minY >= -90.0 ) && ( extent.maxX <= 360.0 ) && ( extent.maxX > 180.0 ) && ( extent.maxY <= 90.0 ); if ( is_longitude_shifted ) { for ( Vertices::size_type n = 0; n < vertices.size(); ++n ) { if ( vertices[n].x > 180.0 ) { vertices[n].x -= 360.0; } } } return is_longitude_shifted; }
int ParticleSystem::createVAO(Shader newShader, Vertices vtx, Indices ind) { int rc = 0; GLint location; // location of the attributes in the shader; shader = newShader; //create vertex array object glGenVertexArrays(1, &vao); glBindVertexArray(vao); //create vertex buffer object glGenBuffers(1, &vtxVBO); glBindBuffer(GL_ARRAY_BUFFER, vtxVBO); glBufferData(GL_ARRAY_BUFFER, vtx.size() * sizeof(Vertex), vtx.data(), GL_STATIC_DRAW); //copy the vertex position location = glGetAttribLocation(shader.getProgId(), "vtxPos"); if (location == -1) { rc = -1; goto err; } glEnableVertexAttribArray(location); glVertexAttribPointer(location, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, pos)); //copy the vertex color location = glGetAttribLocation(shader.getProgId(), "vtxCol"); // if (location == -1) { // rc = -2; //goto err; //} glEnableVertexAttribArray(location); glVertexAttribPointer(location, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, col)); //copy the vertex normal location = glGetAttribLocation(shader.getProgId(), "vtxNorm"); // if (location == -1) { // rc = -2; //goto err; //} glEnableVertexAttribArray(location); glVertexAttribPointer(location, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, norm)); // copy the texture coords location = glGetAttribLocation(shader.getProgId(), "texCoord"); // if (location == -1) { // rc = -2; //goto err; //} glEnableVertexAttribArray(location); glVertexAttribPointer(location, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, texCoord)); //create index buffer glGenBuffers(1, &indVBO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indVBO); glBufferData(GL_ELEMENT_ARRAY_BUFFER, ind.size() * sizeof(GLuint), ind.data(), GL_STATIC_DRAW); // store the number of indices numIndices = vtx.size(); //numIndices = ind.size(); //end creation glBindVertexArray(0); err: return(rc); }