Results 1 to 2 of 2

Thread: Axis doesn't show

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2020
    Posts
    5
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Axis doesn't show

    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.

  2. #2
    Join Date
    Jul 2020
    Posts
    5
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Axis doesn't show

    I removed the #include "../geoObject.h", and now I get:
    ASSERT: "QOpenGLFunctions::isInitialized(d_ptr)" in file /usr/local/Qt/5.15.0/gcc_64/include/QtGui/qopenglfunctions.h, line 1440

Similar Threads

  1. Qt.inputMethod.show () doesn't show any keyboard
    By TheIndependentAquarius in forum Qt Quick
    Replies: 0
    Last Post: 23rd February 2015, 11:45
  2. Replies: 4
    Last Post: 18th October 2013, 18:15
  3. Replies: 5
    Last Post: 1st March 2012, 11:13
  4. Replies: 5
    Last Post: 24th February 2012, 17:47
  5. QGraphicsTextItem doesn't show up
    By chapu in forum Qt Programming
    Replies: 6
    Last Post: 12th July 2010, 01:48

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.