Changes between Version 15 and Version 16 of tutorial


Ignore:
Timestamp:
Jun 27, 2013, 9:43:17 AM (11 years ago)
Author:
leon
Comment:

Prepare for temperature

Legend:

Unmodified
Added
Removed
Modified
  • tutorial

    v15 v16  
    44approaches standardized with version 3.x+. OpenGL Shading Language (GLSL) is used for that without
    55tendency to introduce ''photo-realism''as output but rather useful colors for scientific data exploration.
    6 {{{
    7 #!html
    8 <object data="/sohpc/raw-attachment/wiki/tutorial/OpenGL-pipeline.svg" type="svg+xml"></object>
    9 }}}
     6
    107Running this tutorial on Linux desktop one requires at least the OpenGL 2.0 graphics
    118with the GLSL 1.1 and supporting libraries GL, GLU, GLUT, GLEW.
    12 This can be verified with the following commands:
     9This can be verified with the following commands: 
    1310{{{
    1411#!sh
     
    103100
    104101
    105 == Exercise #1: ==
     102== Exercises #1: ==
    106103 1. Add RGB color to vertices with {{{ glColor3f(0.0, 0.4, 1.0);}}}.
    107104 2. Replace single line drawing in {{{display()}}} with the following snippet
     
    136133 How can we add color to vertices? See [http://www.opengl.org/sdk/docs/man2/xhtml/glColorPointer.xml glColorPointer] and [http://www.opengl.org/sdk/docs/man2/xhtml/glEnableClientState.xml glEnableClientState].
    137134 6. Change background to {{{glClearColor(0.9,1,1,1.0);}}}
     135 7. Add [http://www.opengl.org/resources/libraries/glut/spec3/node49.html keyboard event]
     136  to quit the program when pressing ESCape key with keycode 27 by adding callback function
     137  {{{
     138  #!c
     139   void keyboard(unsigned char key, int x, int y)
     140   {
     141     if (key == 27)
     142            exit(0);
     143   }
     144  }}}
     145  and registering event within `main()` by `glutKeyboardFunc(keyboard);`
     146 
     147 
    138148
    139149
    140150== Modern OpenGL ==
    141 [[Image(triangle.png,right)]]
     151[[Image(OpenGL-pipeline.svg, 320px, right, title=OpenGL pipeline)]]
    142152We extend previous exercise with example that introduces OpenGL 3.x techniques:
    143153 * OpenGL Shading Language where simple vertex and fragment shader are required.
    144154 * Vertex Aray Objects (VAOs) stored in GPU
    145 Create {{{triangle.c}}} and update {{{Makefile}}} with new target
     155Create {{{triangle.c}}} and update {{{Makefile}}} with new target 
    146156{{{
    147157#!sh
     
    189199#define NumVertices  6
    190200
    191 void init(void)
     201void init(void) 
    192202{
    193203  glGenVertexArrays(NumVAOs, VAOs);
     
    236246}
    237247}}}
    238 
     248[[Image(triangle.png,align=bottom,right,title=Triangles )]]
    239249== Exercises #2 ==
    240250 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:
     
    276286     }
    277287  }}}
     288 2. Introduce vertex temperature with additional array
     289  {{{
     290  #!c
     291  GLfloat vertex_temperature[] = {0, 0.5, 1, 0.7, 0.2, 0.9};
     292  }}}
     293  and replace shaders with
     294  {{{
     295  #!c
     296static const GLchar * vertex_shader[] = {
     297"attribute float VertexTemp;" // receive this custom attribute along with vertex position
     298"varying float Temperature;"  // communicate between the vertex and the fragment shader
     299"void main() { gl_position  = gl_ModelViewProjectionMatrix * gl_Vertex; }"
     300};
     301static const GLchar * fragment_shader[] = {
     302"vec3 Cool = vec3(0, 0, 1);" // Red
     303"vec3 Hot  = vec3(1, 0, 1);" // Blue
     304"void main()
     305"{"
     306"  vec3 color = mix(Cool, Hot, Temperature);" // use the built-in mix() function
     307"  gl_FragColor = vec4(color, 1.0);"          // append alpha channel
     308"}"
     309};
     310  }}}