1OutlineOutline• Announcements– HWII due Monday– HWIII out soon– Sign-up for CTC account• OpenGL graphics• Portability with GLUTWhy Add Graphics?Why Add Graphics?• Writing graphics routines can be difficult(not as hard as you think, though)• There are many packages for scientificvisualization (MATLAB, AVS, OpenDX)• So, why bother coding yourself?– Get a quick view of results– Make program accessible to non-specialists– It’s cool!OpenGLOpenGL• OpenGL is the graphics library– Started as proprietary library on SiliconGraphics workstations– Now available everywhere (standard withmost systems)– Tightly coupled with graphics cards– Underlying system for most games andscientific visualization systems2OpenGLOpenGL• Built-in primitives to draw points, lines,polygons• Can easily transform objects in 3D– scale, rotate, translate, change viewpoint• Can control opacity of objects, not just color• Can add textures to objects• For more info:– www.opengl.org or– CS417OpenGL and GLUTOpenGL and GLUT• OpenGL is a rich description of graphicsoperations• But, OpenGL needs to interact with system– needs windows to draw in– needs windows to recognize graphics commands• GLUT--Graphics Library Utility Toolkit– System independent library for creating windows andmanaging simple user interaction (mouse, keyboard,menus)– Can call from C (C++), FORTRAN, and now JavaGLUTGLUT• Can build simple GUI’s with GLUT– for more sophisticated GUI’s consider Java orsystem-dependent tools• However, GLUT GUI’s demonstrate basic GUIideas:– Developer writes Callbacks--routines that areexecuted upon user events:• Mouse click in window, keyboard input– The program tells GUI system which routines go withwhich events– Control is turned over to GUI system• GUI system calls Callbacks as needed3GLUT and RAD1DGLUT and RAD1D• I added GLUT routines to RAD1D to plot C atseveral times• main:– Creates a window– Registers “DrawC” as “DisplayFunc”• DrawC is called when screen must be re-drawn• No inputs to display functions!– Registers “ResizeIt” as “ReshapeFunc”• ResizeIt(width,height) is called when window is resized– Calls RunRad• Original RAD1D main– Gives control to GLUTRunRadRunRad• Accepts 1 more input: Nsamp--numberof time samples• C is stored every T/(Nsamp-1) timeunits– AddC stores C in array GLC in Glout.c• plots a line for every time observation of C• first line is red, last line is blue, color varies
View Full Document