I have an 3d cube phong lighting model, and I want to add the axis3d to it.
Here is my axis3d.h:
#ifndef AXIS3D_H
#define AXIS3D_H
#include "../geoObject.h"
#include <QOpenGLFunctions>
#include <QOpenGLShaderProgram>
class axis3d: public QOpenGLFunctions
{
public:
axis3d();
void initialize();
void render(QOpenGLShaderProgram *const program);
private:
GLuint axisVBO[2];
};
#endif // AXIS3D_H
And here is my axis3d.cpp:
#include "axis3d.h"
#include <glm/glm.hpp>
#define GLM_ENABLE_EXPERIMENTAL
//#include "camera.h"
#include <glm/gtx/transform.hpp>
#include <glm/gtc/type_ptr.hpp>
axis3d::axis3d()
{
}
void axis3d::initialize()
{
glGenBuffers(2, &axisVBO[0]);
GLfloat verts[] = {
-1.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f,
0.0f, -1.0f, 0.0f,
0.0f, 1.0f, 0.0f,
0.0f, 0.0f, -1.0f,
0.0f, 0.0f, 1.0f
};
glBindBuffer(GL_ARRAY_BUFFER, axisVBO[0]);
glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STATIC_DRAW);
GLfloat axisColors[] = {
1.0f, 1.0f, 0.0f, // -x
1.0f, 0.0f, 0.0f,// x
1.0f, 0.0f, 1.0f, // -y
0.0f, 1.0f, 0.0f, //y
1.0f, 1.0f, 1.0f, //-z
0.0f, 1.0f, 0.0f, //z
};
glBindBuffer(GL_ARRAY_BUFFER, axisVBO[1]);
glBufferData(GL_ARRAY_BUFFER, sizeof(axisColors), axisColors, GL_STATIC_DRAW);
}
void axis3d::render(QOpenGLShaderProgram *const program)
{
program->bind();
GLuint m_posAttr = program->attributeLocation("posAttr");
GLuint m_colAttr = program->attributeLocation("colAttr");
glm::mat4 pvm = glm::mat4(1.0f);
program->setUniformValue("mvpMatrix", QMatrix4x4(glm::value_ptr(pvm)).transposed());
glBindBuffer(GL_ARRAY_BUFFER, axisVBO[0]);
program->enableAttributeArray(m_posAttr);
program->setAttributeBuffer(m_posAttr, GL_FLOAT, 0, 3);
glBindBuffer(GL_ARRAY_BUFFER, axisVBO[1]);
program->enableAttributeArray(m_colAttr);
program->setAttributeBuffer(m_colAttr, GL_FLOAT, 0, 3);
glDrawArrays(GL_LINES, 0, 6);
program->release();
}
I initializ(s)e using:
drawAxis = new axis3d();
drawAxis->initialize();
I render using:
drawAxis->render(axis3dProgram);
I also put $protected QOpenGLFunctions$ on the main opengl widget. That may be the problem.
I have a warning like this:
/usr/local/Qt/5.15.0/gcc_64/include/QtGui/qopenglext.h:60:0: warning: "GL_GLEXT_VERSION" redefined
#define GL_GLEXT_VERSION 20190228
In file included from /usr/include/GL/gl.h:2050:0,
from src/geoObjects/primitives/../geoObject.h:4,
from src/geoObjects/primitives/axis3d.h:3,
from src/geoObjects/primitives/axis3d.cpp:1:
/usr/include/GL/glext.h:54:0: note: this is the location of the previous definition
#define GL_GLEXT_VERSION 20190911
I have tried using only QOpenGLBuffer or directly using GL/glew and some others but to no avail.
Bookmarks