/** * @brief * Returns the currently picked wrapped texture coordinate (always between 0..1) */ bool PickingResult::GetWrappedTextureCoordinate(Vector2 &vTexCoord, uint32 nTexCoordChannel) const { // Get the currently picked texture coordinate if (GetTextureCoordinate(vTexCoord, nTexCoordChannel)) { // Perform wrapping to get into the 0..1 interval vTexCoord.x = vTexCoord.x - static_cast<int>(vTexCoord.x); if (vTexCoord.x < 0.0f) vTexCoord.x = vTexCoord.x + 1.0f; vTexCoord.y = vTexCoord.y - static_cast<int>(vTexCoord.y); if (vTexCoord.y < 0.0f) vTexCoord.y = vTexCoord.y + 1.0f; // Done return true; } else { // Error! return false; } }
void IShape::Update() { const unsigned int numVertices = GetVertexCount(); // Get all the data. std::unique_ptr<glm::vec3[]> vertexPositions(new glm::vec3[numVertices]); std::unique_ptr<glm::vec4[]> vertexColors(new glm::vec4[numVertices]); std::unique_ptr<glm::vec2[]> vertexTextureCoordinates(new glm::vec2[numVertices]); for (unsigned int i = 0; i < numVertices; ++i) { const glm::vec2 position = GetVertexPosition(i); vertexPositions[i] = glm::vec3(position, 0.0f); vertexColors[i] = m_fillColor; vertexTextureCoordinates[i] = GetTextureCoordinate(i); } // Bind the Vertex Array Object. glBindVertexArray(m_VAO); // Send the vertex position data to the corresponding VBO. glBindBuffer(GL_ARRAY_BUFFER, m_positionVBO); glBufferData( GL_ARRAY_BUFFER, sizeof(glm::vec3) * numVertices, &vertexPositions[0], GL_STATIC_DRAW ); // Set the vertex position data to be the first attribute // passed to the shader (index 0). glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); // Send the vertex color data to the corresponding VBO. glBindBuffer(GL_ARRAY_BUFFER, m_colorVBO); glBufferData( GL_ARRAY_BUFFER, sizeof(glm::vec4) * numVertices, &vertexColors[0], GL_STATIC_DRAW ); // Set the vertex color data to be the third attribute // passed to the shader (index 2). glEnableVertexAttribArray(2); glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, 0, 0); // Texturing... if (m_texture) { // Send the texture coordinate data to the corresponding VBO. glBindBuffer(GL_ARRAY_BUFFER, m_textureCoordinatesVBO); glBufferData( GL_ARRAY_BUFFER, sizeof(glm::vec2) * numVertices, &vertexTextureCoordinates[0], GL_STATIC_DRAW ); // Set the vertex texture coordinate data to be the fourth // attribute passed to the shader (index 3). glEnableVertexAttribArray(3); glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, 0, 0); } // Unbind the Vertex Array Object. glBindVertexArray(0); }