Changes between Version 41 and Version 42 of tutorial


Ignore:
Timestamp:
Jul 1, 2013, 2:40:59 AM (6 years ago)
Author:
leon
Comment:

Point cloud revised

Legend:

Unmodified
Added
Removed
Modified
  • tutorial

    v41 v42  
    650650   Verify that there are no compile problems and that the {{{main()}}} contains {{{read_wavefront("motorBike.obj");}}}.
    651651   Disable lengthy wavefront saving in {{{main()}}}.
    652  2. Instead of drawing of the teapot in {{{display()}}} we will draw single vertex array object as a point cloud with
    653   {{{
    654   #!c
    655    //glutSolidTeapot(0.6);
    656    glDrawArrays(GL_POINTS, 0, vertices);
    657   }}}
    658   To be able to draw this, we need to prepare Vertex Array Object and buffer with {{{init();}}} that is called from {{{main()}}} just before {{{glutMainLoop();}}}
    659   {{{
    660   #!c
    661 void init()
    662 {
    663   GLuint VAO[1];
    664   GLuint Buffer[1];
    665   glGenVertexArrays(1, VAO);
    666   glBindVertexArray(VAO[0]);
    667   glGenBuffers(1, Buffer);
    668   glBindBuffer(GL_ARRAY_BUFFER, Buffer[0]);
    669   glBufferData(GL_ARRAY_BUFFER, vertices*3*sizeof(GLfloat),
    670                vertex, GL_STATIC_DRAW);
    671   glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
    672   glEnableVertexAttribArray(0);
    673 }
    674 }}}
     652 2. Instead of drawing of the teapot in {{{display()}}} we will draw single vertex array object as a point cloud with adding
     653  {{{
     654  #!c
     655  //glutSolidTeapot(0.6);
     656  glVertexPointer(3, GL_FLOAT, 0, vertex);
     657  glEnableClientState(GL_VERTEX_ARRAY);
     658  glDrawArrays(GL_POINTS, 0, vertices);
     659  glDisableClientState(GL_VERTEX_ARRAY);
     660  }}}
     661  that pushes 132871 vertices (1.5MB) from client memory to GPU on every redraw. Better approach would be to follow VBOs principles by generating vertex buffer in GPU as {{{temperature.c}}} example.
    675662 3. We see that rotation of the motorbike around the front wheel is not really nice.
    676663   To compensate we translate all points in the {{{vertex_shader[]}}} by adding {{{vec3(-0.75, 0, -0.7);}}}