Changes between Version 18 and Version 19 of tutorial


Ignore:
Timestamp:
Jun 28, 2013, 10:02:05 PM (11 years ago)
Author:
leon
Comment:

Add zoomin/out

Legend:

Unmodified
Added
Removed
Modified
  • tutorial

    v18 v19  
    100100
    101101
    102 == Exercises #1: ==
     102=== Exercises #1: ===
    103103 1. Add RGB color to vertices with {{{ glColor3f(0.0, 0.4, 1.0);}}}.
    104104 2. Replace single line drawing in {{{display()}}} with the following snippet
     
    251251}}}
    252252[[Image(triangle.png,align=bottom,right,title=Triangles )]]
    253 == Exercises #2 ==
     253=== Exercises #2 ===
    254254 1. To be able to continue and not get lost introduce shader compiler logs in case of compilation errors by adding the following code into {{{setShaders()}}} right at after vertex shader compilation:
    255255   {{{
     
    479479}
    480480}}}
    481 
     481=== Exercises #3 ===
     482 1. Introduce zoom in/out functionality of the viewer by adding mouse wheel events to the end of `mouse()`
     483  {{{
     484  #!c
     485  if (button == 3 && state == GLUT_DOWN)
     486    { zoom *= 1.1; glutPostRedisplay(); }
     487  else if (button == 4 && state == GLUT_DOWN)
     488    { zoom /= 1.1; glutPostRedisplay(); }
     489  }}}
     490  and introduction of global variable `float zoom = 1.0;` that is communicated to GPU by additional `uniform float Zoom;` in the `vertex_shader[]`. Last line is replaced by
     491  {{{
     492  #!c
     493    gl_Position = gl_ProjectionMatrix * RotationMatrix \
     494     * gl_ModelViewMatrix*vec4(Zoom*gl_Vertex.xyz, 1.0); \
     495  }}}
     496  In the `display()` we add zooming by
     497  {{{
     498  #!c
     499   location = glGetUniformLocation(p, "Zoom");
     500   if (location >= 0)  glUniform1f(location, zoom);
     501  }}}
    482502 
     503
     504
     505