src/gl/compiler.cpp

changeset 30
1536f23cfab7
parent 28
c92c1daf735f
child 33
4c41bfe2ec6e
equal deleted inserted replaced
29:4cc6b582fde8 30:1536f23cfab7
95 object.buffer.setUsagePattern(QOpenGLBuffer::DynamicDraw); 95 object.buffer.setUsagePattern(QOpenGLBuffer::DynamicDraw);
96 object.vertexArray.create(); 96 object.vertexArray.create();
97 object.vertexArray.bind(); 97 object.vertexArray.bind();
98 object.program->enableAttributeArray(0); 98 object.program->enableAttributeArray(0);
99 object.program->enableAttributeArray(1); 99 object.program->enableAttributeArray(1);
100 object.program->setAttributeBuffer(0, GL_FLOAT, 0, 3); 100 constexpr int stride = 7 * sizeof(GLfloat);
101 object.program->setAttributeBuffer(1, GL_FLOAT, 3, 4); 101 object.program->setAttributeBuffer(0, GL_FLOAT, 0 * sizeof(GLfloat), 3, stride);
102 object.program->setAttributeBuffer(1, GL_FLOAT, 3 * sizeof(GLfloat), 4, stride);
102 object.vertexArray.release(); 103 object.vertexArray.release();
103 object.buffer.release(); 104 object.buffer.release();
104 object.program->release(); 105 object.program->release();
105 } 106 }
106 this->initialized = true; 107 this->initialized = true;
177 const QColor color = this->getColorForPolygon(polygon); 178 const QColor color = this->getColorForPolygon(polygon);
178 // Transform vertices so that they're suitable for GL rendering 179 // Transform vertices so that they're suitable for GL rendering
179 for (unsigned int i = 0; i < polygon.numPolygonVertices(); i += 1) 180 for (unsigned int i = 0; i < polygon.numPolygonVertices(); i += 1)
180 { 181 {
181 Point3D& point = polygon.vertices[i]; 182 Point3D& point = polygon.vertices[i];
182 polygon.vertices[i].y = -polygon.vertices[i].y;
183 polygon.vertices[i].z = -polygon.vertices[i].z;
184 this->boundingBox.consider(polygon.vertices[i]); 183 this->boundingBox.consider(polygon.vertices[i]);
185 vertexBuffer.push_back(static_cast<GLfloat>(point.x)); 184 vertexBuffer.push_back(static_cast<GLfloat>(point.x));
186 vertexBuffer.push_back(static_cast<GLfloat>(point.y)); 185 vertexBuffer.push_back(static_cast<GLfloat>(point.y));
187 vertexBuffer.push_back(static_cast<GLfloat>(point.z)); 186 vertexBuffer.push_back(static_cast<GLfloat>(point.z));
188 vertexBuffer.push_back(static_cast<GLfloat>(color.redF())); 187 vertexBuffer.push_back(static_cast<GLfloat>(color.redF()));

mercurial