Changes between Version 15 and Version 16 of tutorial
- Timestamp:
- Jun 27, 2013, 9:43:17 AM (11 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
tutorial
v15 v16 4 4 approaches standardized with version 3.x+. OpenGL Shading Language (GLSL) is used for that without 5 5 tendency 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 10 7 Running this tutorial on Linux desktop one requires at least the OpenGL 2.0 graphics 11 8 with the GLSL 1.1 and supporting libraries GL, GLU, GLUT, GLEW. 12 This can be verified with the following commands: 9 This can be verified with the following commands: 13 10 {{{ 14 11 #!sh … … 103 100 104 101 105 == Exercise #1: ==102 == Exercises #1: == 106 103 1. Add RGB color to vertices with {{{ glColor3f(0.0, 0.4, 1.0);}}}. 107 104 2. Replace single line drawing in {{{display()}}} with the following snippet … … 136 133 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]. 137 134 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 138 148 139 149 140 150 == Modern OpenGL == 141 [[Image( triangle.png,right)]]151 [[Image(OpenGL-pipeline.svg, 320px, right, title=OpenGL pipeline)]] 142 152 We extend previous exercise with example that introduces OpenGL 3.x techniques: 143 153 * OpenGL Shading Language where simple vertex and fragment shader are required. 144 154 * Vertex Aray Objects (VAOs) stored in GPU 145 Create {{{triangle.c}}} and update {{{Makefile}}} with new target 155 Create {{{triangle.c}}} and update {{{Makefile}}} with new target 146 156 {{{ 147 157 #!sh … … 189 199 #define NumVertices 6 190 200 191 void init(void) 201 void init(void) 192 202 { 193 203 glGenVertexArrays(NumVAOs, VAOs); … … 236 246 } 237 247 }}} 238 248 [[Image(triangle.png,align=bottom,right,title=Triangles )]] 239 249 == Exercises #2 == 240 250 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: … … 276 286 } 277 287 }}} 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 296 static 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 }; 301 static 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 }}}