Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Triangle {
- GLushort vertex[3];
- GLushort color[3];
- };
- QOpenGLBuffer arrayBuf;
- QOpenGLBuffer indexBuf;
- QOpenGLBuffer colorBuf;
- void init() {
- QVector3D vertices[] = {
- QVector3D(-1, -1, 1),
- QVector3D(1, -1, 1),
- QVector3D(1, 1, 1),
- QVector3D(-1, 1, 1),
- QVector3D(1, -1, -1),
- QVector3D(-1, -1, -1),
- QVector3D(-1, 1, -1),
- QVector3D(1, 1, -1)
- };
- QVector3D colors[] = {
- QVector3D(1,1,1),
- QVector3D(1,1,1),
- QVector3D(1,1,1)
- };
- Triangle index[] = {
- {{0,1,2},{0,1,2}},
- {{2,3,0},{0,1,2}}
- };
- arrayBuf.bind();
- arrayBuf.allocate(vertices, sizeof(vertices));
- colorBuf.bind();
- colorBuf.allocate(colors, sizeof(colors));
- indexBuf.bind();
- indexBuf.allocate(index, sizeof(index));
- }
- void draw(QOpenGLShaderProgram *program) {
- arrayBuf.bind();
- colorBuf.bind();
- indexBuf.bind();
- // HERFRA SKURRER DET VELDIG
- int vertexLocation = program->attributeLocation("a_position");
- program->enableAttributeArray(vertexLocation);
- program->setAttributeBuffer(vertexLocation, GL_FLOAT, 0, 3, sizeof(QVector3D));
- int colorLocation = program->attributeLocation("a_color");
- program->enableAttributeArray(colorLocation);
- program->setAttributeBuffer(colorLocation, GL_FLOAT, 1, 3, sizeof(QVector3D));
- glDrawElements(GL_TRIANGLES, indexCount, GL_UNSIGNED_SHORT, 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement