160 likes | 287 Views
Outline. Announcements HWII on web, due Friday Sign-up for CTC account http://www.tc.cornell.edu/Services/allocations/explore.asp Dynamic Libraries. HW I Issues. Some problems: cc -lm csin.c -ocsin -l<name> tells compiler to find a library called “libname.a,” and get any routines it needs
E N D
Outline Announcements HWII on web, due Friday Sign-up for CTC account http://www.tc.cornell.edu/Services/allocations/explore.asp Dynamic Libraries
HW I Issues Some problems: cc -lm csin.c -ocsin -l<name> tells compiler to find a library called “libname.a,” and get any routines it needs -lm says to look for libm.a (or .so) -lblas says to look for libblas.a (or .so)
HW I Issues Calling BLAS Look on BLAS sheet for routines that do y<-Ax nothing matches, but find several routines that solve y<-Ax+y CALL SGEMV('n',m,n,1.0,C,MMAX,v,1, 0.0, PC, 1) As a matrix, C is m-by-n, but as an array, it is MMAX-by-NMAX BLAS needs both: MMAX (LDA) lets BLAS know where columns start Also, & should be real (1.0 and 0.0, 1 and 0 won’t work on some systems) m MMAX
BLAS Increments BLAS lets (makes) you specify an increment. Allows you to use 2D arrays as vectors: INC=MMAX(6) INC=MMAX+1
Why Add Graphics? Writing graphics routines can be difficult (not as hard as you think, though) There are many packages for scientific visualization (MATLAB, AVS, OpenDX) So, why bother coding yourself? Get a quick view of results Make program accessible to non-specialists It’s cool!
OpenGL OpenGL is the graphics library Started as proprietary library on Silicon Graphics workstations Now available everywhere (standard with most systems) Tightly coupled with graphics cards Underlying system for most games and scientific visualization systems
OpenGL 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 CS417
OpenGL and GLUT OpenGL is a rich description of graphics operations 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 and managing simple user interaction (mouse, keyboard, menus) Can call from C (C++), FORTRAN, and now Java
GLUT Can build simple GUI’s with GLUT for more sophisticated GUI’s consider Java or system-dependent tools However, GLUT GUI’s demonstrate basic GUI ideas: Developer writes Callbacks--routines that are executed upon user events: Mouse click in window, keyboard input The program tells GUI system which routines go with which events Control is turned over to GUI system GUI system calls Callback for corresponding event
Event-Driven Programming Most scientific programs are simple Read data Compute something Output answer Quit GUIs are fundamentally different Start Process mouse or keyboard Do something Repeat 1-3
Event-Driven Programming GUIs have two key features Never quit until user demands it Process events Suggests a simple structure While(true){ Get next event Determine event type Action determined by type }
Event-Driven Programming All GUIs regardless of OS and language do the same thing Some systems require (allow) you more flexibility Write event loop yourself Parse events yourself GLUT is not designed for writing “full-fledged” GUIs GLUT has its own event loop Hidden from you GLUT allows you to “register” subroutines to handle a limited number of events.
GLUT Programs follow a simple structure Create window(s) Register subroutines to handle events Turn control over to GLUT GLUT Program Structure
GLUT and RAD1D I added GLUT routines to RAD1D to plot C at several 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 Periodically calls AddC which stores current C in array GLC array Gives control to GLUT
plots a line for every time observation of C stored in GLC first line is red, last line is blue, color varies in between DrawC
Drawing with OpenGL GLUT creates windows and handles events, Graphics in DrawC are produced by OpenGL OpenGL is very powerful, but drawing is fairly simple Set color: glColor3f Tell OpenGL you’re starting to draw: glBegin(GL_LINE_STRIP); Place several vertices: glVertex2d (creates one vertex) Tell OpenGL to stop drawing glEnd();