Results 1 to 14 of 14

Thread: qml porting changes the opengl scene placement

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2011
    Posts
    212
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    24

    Default Re: qml porting changes the opengl scene placement

    I am not doing much of different that what is described in http://doc.qt.io/qt-5/qtquick-sceneg...l-example.html . Lets compare the sync() there and mine:

    Qt Code:
    1. void Squircle::sync()
    2. {
    3. if (!m_renderer) {
    4. m_renderer = new SquircleRenderer();
    5. connect(window(), SIGNAL(beforeRendering()), m_renderer, SLOT(paint()), Qt::DirectConnection);
    6. }
    7. m_renderer->setViewportSize(window()->size() * window()->devicePixelRatio());
    8. m_renderer->setT(m_t);
    9. }
    To copy to clipboard, switch view to plain text mode 

    Whereas I am doing the following:

    Qt Code:
    1. void TriangleSceneItem::sync()
    2. {
    3. if(mScene)
    4. {
    5. connect(mTimer,SIGNAL(timeout()),this,SLOT(updateTime()),Qt::DirectConnection);
    6.  
    7. mScene->setViewportSize(window()->width() * window()->devicePixelRatio(),
    8. window()->height() * window()->devicePixelRatio());
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 

    I am creating the timer for the animation and then setting the viewport size that is lated used during rendering. The renderer intialization is done inside the constructor.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: qml porting changes the opengl scene placement

    As I said, look at the code of resize, not sync. By the way, what does initialize() do?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2011
    Posts
    212
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    24

    Default Re: qml porting changes the opengl scene placement

    This what TriangleScene::initialize() do :

    Qt Code:
    1. void TriangleScene::initialise()
    2. {
    3. //return if already initialized
    4. if(mInitialized)
    5. return;
    6.  
    7. if(!initializeOpenGLFunctions())
    8. {
    9. std::cerr << "Modern OpenGL Functions could not be initialized." << std::endl;
    10. std::exit(EXIT_FAILURE);
    11. }
    12.  
    13. GL_CHECK_ERRORS;
    14.  
    15. //make the projection and model-view matrix
    16. //identity matrices
    17. mProjectionMatrix = glm::mat4(1.0f);
    18. mModelViewMatrix = glm::mat4(1.0f);
    19.  
    20. loadShaders();
    21.  
    22. //setup the triangle geometry
    23. mVertices[0].color = glm::vec3(1.0,0.0,0.0);
    24. mVertices[1].color = glm::vec3(0.0,1.0,0.0);
    25. mVertices[2].color = glm::vec3(0.0,0.0,1.0);
    26.  
    27. mVertices[0].position = glm::vec3(-1,-1,0);
    28. mVertices[1].position = glm::vec3(0,1,0);
    29. mVertices[2].position = glm::vec3(1,-1,0);
    30.  
    31. //setup the triangle indices
    32. mIndices[0] = 0;
    33. mIndices[1] = 1;
    34. mIndices[2] = 2;
    35.  
    36. //check for opengl errors
    37. GL_CHECK_ERRORS;
    38.  
    39. //setup the triangle vao and vbo stuff
    40. glGenVertexArrays(1,&mVaoID);
    41.  
    42. glGenBuffers(1,&mVerticesID);
    43. glGenBuffers(1,&mIndicesID);
    44.  
    45. //get the size of the Vertex struct
    46. GLsizei stride = sizeof(Vertex);
    47.  
    48. glBindVertexArray(mVaoID);
    49.  
    50. glBindBuffer(GL_ARRAY_BUFFER,mVerticesID);
    51. //pass triangle vertices to the buffer object
    52. glBufferData(GL_ARRAY_BUFFER, //specifies the target buffer object
    53. sizeof(mVertices),//specifies the size in bytes
    54. &mVertices[0], // pointer to the data
    55. GL_STATIC_DRAW); //usage pattern of the data
    56.  
    57. GL_CHECK_ERRORS;
    58.  
    59. glEnableVertexAttribArray(mTriangleShader->getAttribute("vVertex"));
    60. glVertexAttribPointer(mTriangleShader->getAttribute("vVertex"),3,GL_FLOAT,GL_FALSE,stride,0);
    61.  
    62. GL_CHECK_ERRORS;
    63.  
    64. //enable vertex attribute array for the color
    65. glEnableVertexAttribArray(mTriangleShader->getAttribute("vColor"));
    66. glVertexAttribPointer(mTriangleShader->getAttribute("vColor"),3,GL_FLOAT,GL_FALSE,stride,(const GLvoid*)offsetof(Vertex,color));
    67.  
    68. GL_CHECK_ERRORS;
    69.  
    70. glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,mIndicesID);
    71. glBufferData(GL_ELEMENT_ARRAY_BUFFER,sizeof(mIndices),&mIndices[0],GL_STATIC_DRAW);
    72.  
    73. glDisableVertexAttribArray(mTriangleShader->getAttribute("vVertex"));
    74. glDisableVertexAttribArray(mTriangleShader->getAttribute("vColor"));
    75. glBindVertexArray(0);
    76.  
    77. GL_CHECK_ERRORS;
    78.  
    79. mInitialized = true;
    80.  
    81. }
    82.  
    83. I think the issue lies here and I am examining it right now. Any hint from your end within the function will accelerate the process.
    84.  
    85.  
    86. Thanks
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 1
    Last Post: 8th October 2013, 19:54
  2. Current webcam image behind an OpenGL Scene
    By vrcat in forum Qt Programming
    Replies: 0
    Last Post: 4th June 2009, 14:26
  3. placement new question
    By Teerayoot in forum General Programming
    Replies: 3
    Last Post: 23rd May 2007, 22:13
  4. QTabWidget Placement and Display
    By mclark in forum Newbie
    Replies: 1
    Last Post: 16th January 2007, 20:34
  5. c++, placement delete upon exception
    By stinos in forum General Programming
    Replies: 6
    Last Post: 31st October 2006, 15:38

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
  •  
Qt is a trademark of The Qt Company.