1 / 17

Computer Graphics

Computer Graphics. Gliederung. Was ist das OpenGL Graphics System? OpenGL, die Zustandsmaschine GL Command Syntax Interfaces (GL Utility Library, GLUT) GL Operationen: Objekte Zeichnen und Transformieren Projektion Farbe und Shading Depht-Buffer-Test Blending Display-List

akio
Download Presentation

Computer Graphics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computer Graphics

  2. Gliederung • Was ist das OpenGL Graphics System? • OpenGL, die Zustandsmaschine • GL Command Syntax • Interfaces (GL Utility Library, GLUT) • GL Operationen: • Objekte Zeichnen und Transformieren • Projektion • Farbe und Shading • Depht-Buffer-Test • Blending • Display-List • Zusammenfassung / Ausblick

  3. Was ist das OpenGL Graphics System? • 3D Grafik-Standard (Open Graphics Library) • Geschichte: • Weiterentwicklung der IrisGL (Silicon Graphics, Inc.) zu OpenGL (Version 1.0, 1992) • Kontrolliert durch das Architecture Review Board (ARB): 3Dlabs, Apple, ATI, DELL, IBM, intel, Nvidea, SGI, SUN

  4. Vorteile • Zuverlässigkeit • Plattformunabhängigkeit • Performance • Weiterentwicklung • Effizienz

  5. OpenGL – Die Zustandsmaschine • Zustandsvariablen werden einmal festgelegt und gelten bis sie wieder geändert werden (z.B. Farbe, Position und Charakteristika von Licht, Eigenschaften von Oberflächen oder Material) • (De-)Aktivieren vieler Zustandsvariablen durch glDisable() bzw. glEnable() • Abfragen/Speichern/Wiederherstellen glGetZustand*(), glPushAttrib(), glPopAttrib()

  6. GL Command Syntax • Konstanten: GL_TRUE • Typen: GLfloat • Befehle, Funktionen: glColor3f(1.0f, 1.0f, 1.0f)

  7. Interfaces • GLU: Komplex programmierte GL-Befehle, mehr Modeling-Features (z.B. Kugel, Zylinder, Ringe, Scheiben, … gekrümmte Kurven und Flächen „Nurbs“) • GLUT: Realisierung von Fenstern, Ein-/Ausgabe, Pop-Up Menus, Dreidimensionale Objekte (z.B. Torus), Vorschau von Gitternetz- und festen Modellen

  8. GL-Operationen: Objekte Zeichnen • Zeichnen geometrischer Primitive (Punkte, Linien, Polygone) (Beispiel: hellblaues Quadrat) void display(void) { glClear (1.0f, 1.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT) glBegin(GL_POLYGON GL_COLOR_BUFFER_BIT); glColor3f (0.0f, 0.5f, 1.0f); glVertex3f (0.25, 0.25, 0.0); glVertex3f (0.75, 0.25, 0.0); glVertex3f (0.75, 0.75, 0.0); glVertex3f (0.25, 0.75, 0.0); glEnd(); glFlush (); }

  9. Objekte zeichnen mit Hilfe von GLUT #include <GL/glut.h> int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize (250, 250); glutInitWindowPosition (100, 100); glutCreateWindow ("hello"); glutDisplayFunc(display); glutMainLoop(); return 0; }

  10. GL-Operationen: Transformation Mit Hilfe der GLU-Bibliothek ganz einfach: gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0) Blickpunkt („Eye“), Zentrum der Szene, Up-Vektoren Blickrichtung gluLookAt führt automatisch alle komplexen Matrixtransformationen durch und nimmt dem Benutzer eine Menge Projektionstransformation ab.

  11. GL-Operationen: Projektion • Perspektivische Projektion: Definition des sichtbaren Volumenbereichs („Clipping Volume“) in Form eines Pyramidenstumpfes - was hinausschaut, wird abgeschnitten: glMatrixMode(GL_PROJECTION); //laden der Bearbeitungsfreigabe der Projektionsmatrix glLoadIdentity(); //Initialisirung der aktuell geladenen-, mit der Einheitsmatrix glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far); • Alternative: „Orthogonale Projektion“

  12. Depth-Buffer-Test • OpenGL zeichnet Objekte in der Reihenfolge, wie sie im Programmcode vorkommen. • damit keine Objekte verdeckt werden: Depth-Test • Depth-Buffer gehört zu Fragment-Operationen und speichert für jeden Pixel den Tiefenwert („z-Buffer“) • wird mit glEnable(GL_DEPTH_TEST) verfügbar und mit glClear(GL_DEPTH_BUFFER_BIT) auf den Standardwert, 1 gesetzt.

  13. Blending • Ziel: (teilweise) Transparenz von Objekten • Erinnerung: glColor4f(1.0f, 1.0f, 1.0f, 1.0f) „Alpha-Wert“: 1.0f entspricht solid, 0.0f entspricht transparent • Aktivieren der Transparenz: glEnable(GL_BLEND) • Definition der Transparenzeffekte: glBlendFunc(GLenum sfactor, GLenum dfactor) Standardwerte: GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA

  14. GL-Operationen: Farbe, Shading Farbe: • RGBAmode: Rot/Grün/Blau/Alpha-Werte für jeden Pixel („Bitplanes“)  ca. 16,77 Millionen Farben • color-index mode: Farbnummer für jeden Pixel („color-map“) Shading: glShadeModel(mode) GL_SMOOTH („Gouraud-Shading“) GL_FLAT

  15. Display-List • Generieren und Anlegen von Listen: listName = glGenLists (1); glNewList (listName, GL_COMPILE); glColor3f (1.0, 0.0, 0.0); glBegin (GL_TRIANGLES); … glEnd (); glTranslatef (1.5, 0.0, 0.0); glEndList (); • Ausführen einer Liste: glCallList (listName);

  16. Zusammenfassung und Ausblick OpenGL stellt neben DirectX eine interessante Alternative als Grafikprogrammierschnittstelle dar. Was OpenGL noch alles kann: Beleuchtung und Shadowing Rasterisation und Shading Texture Mapping Ray-Tracing, Radiosity

  17. Quellen • OpenGL Spezifikationen: http://www.opengl.org/documentation/spec.html • The OpenGL Programming Guide - The Redbook: http://www.rush3d.com/reference/opengl-redbook-1.1/ • Dieter Orlamünder/Wilfried Mascolus: Computergrafik und OpenGL • Frank Rieg: Grafikprogrammierung für Windows (beide Carl Hanser Verlag) • Lorenz Burggraf: OpenGL (Markt + Technik Verlag)

More Related