1 / 54

SISTEMAS GRÁFICOS

GRUPO DE PROCESADO DE IMAGEN Y REALIDAD VIRTUAL ETSI Telecomunicación. Universidad de Vigo. SISTEMAS GRÁFICOS. TMM: Tecnoloxia Multimedia. 2006. Donde Estamos? Generalidades. Gráficos Interactivos Interfaces herramientas CAD Interfaces herramientas de Modelado 3D Entretenimiento

chelsey
Download Presentation

SISTEMAS GRÁFICOS

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. GRUPO DE PROCESADO DE IMAGEN Y REALIDAD VIRTUAL ETSI Telecomunicación. Universidad de Vigo SISTEMAS GRÁFICOS TMM: Tecnoloxia Multimedia. 2006

  2. Donde Estamos?Generalidades • Gráficos Interactivos • Interfaces herramientas CAD • Interfaces herramientas de Modelado 3D • Entretenimiento • Interiores • etc...

  3. Donde NO Estamos?Generalidades • Imágen Fotorealista • Películas • Post Producción • Técnicas • Ray-Tracing (POV Ray)

  4. Arquitectura Hardware IGeneralidades • CPU • RAM • BUS • VRAM • GPU • DAC CPU RAM BUS (PCI, AGP, PCI Express) Tarjeta Gráfica

  5. Arquitectura Hardware IIGeneralidades RAM • Lee datos RAM • Escribe VRAM a través del Bus PCI • GPU lee VRAM • DAC genera señal de Video CPU BUS PCI/ISA/VESA LB VRAM Dual-Port Memory Flicker – Retrazo Vertical PCI : 133 MB/s VRAM DAC GPU

  6. Arquitectura Hardware IIIGeneralidades • GPU accede directamente a la RAM del equipo • Tarjeta Gráfica tiene memoria local • GPU procesador complejo CPU RAM Velocidades de bus AGP x4 : 1 GB/s AGP x8: 2.1 GB/s PCI-Express (x16): 4GB/s BUS AGP/PCI Express DAC VRAM GPU

  7. Arquitectura Hardware IVGeneralidades • MultiGPU • Permiten la conexión de varias tarjetas de videoMejora del rendimiento • Dos Soluciones: ATI CrossFire y nVidia SLI

  8. Arquitectura Hardware VGeneralidades • SLI: Scalable Link Interface • Require 2 PCI-Express x16 • 2 o 4 tarjetas (QUAD SLI) • Tarjetas idénticas conectadas por una PCB • Formas de trabajo: • SFR: Split Frame Rendering • AFR: Alternate Frame Rendering

  9. Arquitectura Hardware IVGeneralidades • ATI Cross-Fire • Las tarjetas no tienen que ser idénticas • Master Card Composition chip • Modos de Funcionamiento: • Super Tiling • Scissor (SFR) • Alternate Frame Rendering (AFR) • CrossFire SuperAA

  10. Arquitectura Hardware VGeneralidades • ATI Cross-Fire. Diagrama

  11. Coordenadas Homogéneas (x, y, z) -> (x, y, z, 1) Transformación Afín x -> Ax +b Matriz de Transformación A b 0 1 Matemáticas IGeneralidades • Coordenadas Homogéneas • Permiten representar transformaciones afines como operaciones con matrices • Transformaciones Afines: Transformación lineal + Traslación • Rotación, Escalado, Proyección... • Transformar un vector en coordenadas homogéneas == Multiplicarlo por la matriz • Composición de Transformaciones = = Producto de Matrices

  12. Quaternion v = a + b·i + c·j + d·k = a + u Propiedades i*i = j*j = k*k = -1 ij=k, jk=i, ki=j ji=-k, kj=-i, ik=-j Matemáticas IIGeneralidades • Quaternions • Se pueden ver como una generalización de los númeroscomplejos • Representan rotaciones respecto a un eje • Utilizados para realizar rotaciones suaves: • Spherical Linear Interpolation (SLERP)

  13. Notas Desarrollado por SGI en 1992 Soportado en la mayoria de plataformas existentes en la actualidad IntroduccionOpenGL • API de bajo nivel (primitivas gráficas sencillas) • Utilidades de mas alto nivel GLU, GLUT • Utility and Utility Toolkit • No proporciona Widgets/Ventanas • Se requiere un interfaz con el sistema de ventanas (glx/wglx, SDL, glut,...) • Alternativa: • Microsoft DirectX (Direct3D)

  14. Introduccion OpenGL • La especificacion la gestiona el Architecture Review Board (ARB) • Existen varias extensiones a la especificacion • ARB, NV, HP, SGI, etc... • Dos libros para empezar: • Libro Rojo (Redbook):OpenGL Programming Guide • Libro Azul (BlueBook): OpenGL Reference Manual Sitio Oficial www.opengl.org

  15. Aplicaciones GraficasOpenGL • Estructura general de una aplicación Gráfica • INICIALIZACIÓN • BUCLE INFINITO PRINCIPAL • Lee Eventos • Procesa Eventos • Render Frame • Duerme Proceso

  16. MatricesOpenGL. Conceptos Generales • Trabajaremos con coordenadas homogéneas y matrices de transformación. • Matrices • PROJECTION_MATRIX: Prespectiva/ortonormal • MODELVIEW_MATRIX: Representación • TEXTURE_MATRIX: Manipulación de texturas • OpenGL permite la manipulación sencilla de las matrices: glTranslatef (4.0f, 0.0f, -10.0f); -> Genera una traslación

  17. BuffersOpenGL Conceptos Generales • OpenGL gestiona diversos buffers necesarios para la representación de los gráficos: • COLOR_BUFFER: Imagen generada • Z_BUFFER: Información de profundidad de cada pixel de la imagen • STENCIL_BUFFER: Enmascarado de pixels • ACCUMULATION_BUFFER: Buffer de acumulación

  18. Hola Mundo con GLUT IOpenGL Programacion • Creando la ventana #include <GL/gl.h> #include <GL/glu.h> #include <GL/glut.h> int main (int argc, char *argv) { glutInit (&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize (500, 500); glutCreateWindow (argv[0]); init (); ...

  19. Hola Mundo con GLUT IIOpenGL Programacion • Preparando Eventos ... glutDisplayFunc (display); glutReshapeFunc(reshape); glutMainLoop(); return 0; } void init(void){ glClearColor (0.0f, 0.0f, 0.0f); glShadeMode (GL_FLAT); }

  20. Hola Mundo con GLUT IIIOpenGL Programacion • Render. La funcion display void display(void) { glClear (GL_COLOR_BUFFER_BIT); glColor3f (1.0, 1.0, 1.0); glLoadIdentity (); /* clear the matrix viewing transform*/ gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); glScalef (1.0, 2.0, 1.0); /* modeling transformation */ glutWireCube (1.0); glFlush (); }

  21. TransformacionesOpenGL Programacion • Tres transformaciones: • Translaciones • glTranslatef (desp_x, desp_y, desp_z); • Rotaciones • glRotatef (angulo, x, y, z); • Escalado • glScalef (escala_x, escala_y, escala_z);

  22. Hola Mundo con GLUT IIIOpenGL Programacion • Cambiando ViewPort. Funcion reshape void reshape (int w, int h) { glViewport (0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode (GL_PROJECTION); glLoadIdentity (); glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0); glMatrixMode (GL_MODELVIEW); } MATRIX DE PROJECCION glFrustum: Prespectiva glOrtho: Ortografica

  23. Hola Mundo con GLUT IIIOpenGL Programacion • Proyeccion: Prespectiva y Ortografica MATRIX DE PROJECCION glFrustum: Prespectiva glOrtho: Ortografica

  24. Usando el Teclado IOpenGL Programacion • Funcion de gestion de eventos de teclado ... /* En main */ glutKeyboardFunc (keyboard); ... void keyboard (unsigned char key, int x, int y) { switch (key) { case 'a': rotX += 10.0f; break; case 's': rotX -= 10.0f break; } glutPostRedisplay(); }

  25. Usando el Teclado IIOpenGL Programacion • Nueva funcion display static GLfloat rotX; void display(void) { glClear (GL_COLOR_BUFFER_BIT); glColor3f (1.0, 1.0, 1.0); glLoadIdentity (); gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); glScalef (1.0, 2.0, 1.0); glRotatef (rotX, 1.0f, 0.0f, 0.0f); glutWireCube (1.0); glFlush (); }

  26. Usando el RatonOpenGL Programacion • Funcion de gestion de eventos de raton ... /* En main */ glutMouseFunc (mouse); ... void mouse (int button, int state, int x, int y) { switch (button) { case GLUT_LEFT_BUTTON: if (state == GLUT_DOWN) rotX += 10.0f; break; case GLUT_RIGHT_BUTTON: (...)} glutPostRedisplay(); }

  27. GeometriasOpenGL Programacion • Dibujando un Triangulo Rojo void triangle(void) { glBegin (GL_TRIANGLES); glColor3f (1.0, 0.0, 0.0); glVertex2f (5.0, 5.0); glVertex2f (25.0, 5.0); glVertex2f (5.0, 25.0); glEnd(); } GL_POINTS GL_LINES GL_LINE_STRIP GL_LINE_LOOP GL_TRIANGLES GL_TRIANGLES_STRIP GL_TRIANGLES_FAN GL_QUADS GL_QUAD_STRIP GL_POLYGON glVertex2{fd} (x, y) glVertex3{fd} (x, y, z) glVertex4{fd} (x, y, z, w) void init(void) { glClearColor (0.0, 0.0, 0.0, 0.0); glShadeModel (GL_FLAT); }

  28. GeometriasOpenGL Programacion • Primitivas de Dibujo Geometrico GL_POINTS GL_LINES GL_LINE_STRIP GL_LINE_LOOP GL_TRIANGLES GL_TRIANGLES_STRIP GL_TRIANGLES_FAN GL_QUADS GL_QUAD_STRIP GL_POLYGON

  29. Geometrias y SombreadoOpenGL Programacion void init(void) { glClearColor (0.0, 0.0, 0.0, 0.0); glShadeModel (GL_SMOOTH); } • Triangulo de color void triangle(void) { glBegin (GL_TRIANGLES); glColor3f (1.0, 0.0, 0.0); glVertex2f (5.0, 5.0); glColor3f (0.0, 1.0, 0.0); glVertex2f (25.0, 5.0); glColor3f (0.0, 0.0, 1.0); glVertex2f (5.0, 25.0); glEnd(); }

  30. Hidden-Surface RemovalOpenGL Programacion • Uso del Z-Buffer int main (int argc, char* argv[]) { ... glutInitDisplayMode (GLUT_DEPTH | GLUT_SINGLE | GLUT_RGB); ... } void display(void) { glClear (GL_COLOR_BIT | GL_DEPTH_BUFFER_BIT); /* Dibuja figuras solapadas */ ... }

  31. Iluminacion IOpenGL Programacion • Definicion de Luces • Ambiente: Luz ambiental proveniente de todas direcciones • Difusa: Luz que proviene de una direccion y rebota en una superficie en todas direcciones • Especular: Luz que proviene de una direccion y rebota en otra direccion definida • Materiales • Definen la reflectancia ambiental, difusa y especular de una superficie

  32. Iluminacion IIOpenGL Programacion • Definiendo Luces y Materiales void init(void) { GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 }; GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat mat_shininess[] = { 50.0 }; glClearColor (0.0, 0.0, 0.0, 0.0); glShadeModel (GL_SMOOTH); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); Posicion luces Direccional: w=0 Posicional: w=1 GL_SHININESS GL_AMBIENT GL_DIFUSSE GL_SPECULAR GL_EMISSION GL_AMBIENT_AND_DIFFUSSE

  33. Iluminacion IIIOpenGL Programacion • Definiendo Luces y Materiales 2 glLightfv(GL_LIGHT0, GL_POSITION, light_position); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_DEPTH_TEST); } void display(void) { glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glutSolidSphere (1.0, 20, 16); glFlush (); } GL_POSITION GL_AMBIENT GL_DIFFUSE GL_SPECULAR GL_SPOT_DIRECTION GL_SPOT_EXPONENT GL_SPOT_CUTOFF GL_CONSTANT_ATTENUATION GL_LINEAR_ATTENUATION GL_CUADRATIC_ATTENUATION

  34. Iluminacion IVOpenGL Programacion • Resultados

  35. TransparenciasOpenGL Programacion • Usando Transparencias • Habilitarlo con glEnable • Seleccionar funcion para el mezclado de colores • El orden de dibujado importa void init(void) { glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glShadeModel (GL_FLAT); glClearColor (0.0, 0.0, 0.0, 0.0); }

  36. TransparenciasOpenGL Programacion • Usando Transparencias static void drawLeftTriangle(void) { /* draw yellow triangle on LHS of screen */ glBegin (GL_TRIANGLES); glColor4f(1.0, 1.0, 0.0, 0.75); glVertex3f(0.1, 0.9, 0.0); glVertex3f(0.1, 0.1, 0.0); glVertex3f(0.7, 0.5, 0.0); glEnd(); }

  37. Display Lists IOpenGL Programacion • Mejoran rendimiento cuando se dibuja una misma geometria repetidamente • Creacion y uso de Display Lists void init (void) { geom1 = glGenLists (1); glNewList (geom1, GL_COMPILE); /* Comandos OpenGL para generar la geometria*/ glEndList(); .... void display (void) { .... glCallList (geom1); GL_COMPILE GL_COMPILE_AND_EXECUTE

  38. Display Lists IIOpenGL Programacion • Ejecutando Multiples Display Lists void init (void) { GLuint base; base = glGenLists (128); glListBase (base); glNewList (base + 'A', GL_COMPILE); genera_letraA (); ... glNewList (base + 'Z', GL_COMPILE); genera_letraZ (); glEndList(); .... void display (void) { .... glCallLists (10, GL_BYTE, (GLbyte*) “HOLA MUNDO”);

  39. Texturas IOpenGL Programacion • Creacion de texturas Gluint texName; glGenTextures (1, &texName); glBindTexture (GL_TEXTURE_2D, texName); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, checkImageWidth, checkImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, checkImage); GL_REPEAT GL_CLAMP

  40. Texturas IIOpenGL Programacion • Mapeando texturas glEnable(GL_TEXTURE_2D); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glBindTexture(GL_TEXTURE_2D, texName); glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0); glTexCoord2f(0.0, 1.0); glVertex3f(-2.0, 1.0, 0.0); glTexCoord2f(1.0, 1.0); glVertex3f(0.0, 1.0, 0.0); glTexCoord2f(1.0, 0.0); glVertex3f(0.0, -1.0, 0.0); ....

  41. Texturas IIIOpenGL Programacion GL_TEXTURE_2D GL_PROXY_TEXTURE_2D • Generacion de Texturas void glTexImage2D( GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels ) LoD 2m + 2b (en general potencias de 2) 0 o 1 Formato de pixels RGB, BYTE...

  42. Texturas IVOpenGL Programacion • Otras operaciones con texturas • glCopyTexImage2D: Obtiene imagen del Framebuffer • glTexSubImage2D: Sustituye una parte de la textura • Render to Texture, Texturas animadas,... • Texturas 1D • glTexImage1D: Textura de una dimension (linea)

  43. Texturas VOpenGL Programacion • LoD (Level of Detail). Mip Mapping • Del latin (Multim im parvo) • Original, 1/4, 1/16, 1/64 • OpenGL determina que textura utilizar dependiendo del tamaño del objeto (pixels) en el que se mapea • MipMapping • Hay que porporcionar todas las texturas, desde la original hasta 1x1 pixels

  44. Texturas VIOpenGL Programacion • Generando un Mipmap GLubyte mipmapImage32[32][32][4]; .... GLubyte mipmapImage1[1][1][4]; .... glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, mipmapImage32); glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, mipmapImage16); ... glTexImage2D(GL_TEXTURE_2D, 5, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, mipmapImage1);

  45. Texturas VIIOpenGL Programacion • MipMap Render glBindTexture(GL_TEXTURE_2D, texName); glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0); glTexCoord2f(0.0, 8.0); glVertex3f(-2.0, 1.0, 0.0); glTexCoord2f(8.0, 8.0); glVertex3f(2000.0, 1.0, -6000.0); glTexCoord2f(8.0, 0.0); glVertex3f(2000.0, -1.0, -6000.0); glEnd();

  46. Texturas VIIIOpenGL Programacion • Filtrado de Texturas glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); GL_TEXTURE_MAG_FILTER GL_NEAREST GL_LINEAR GL_TEXTURE_MIN_FILTER GL_NEAREST GL_LINEAR GL_NEAREST_MIPMAP_NEAREST GL_NEAREST_MIPMAP_LINEAR GL_LINEAR_MIPMAP_NEAREST GL_LINEAR_MIPMAP_LINEAR

  47. Otras FuncionalidadesOpenGL Programacion • Graficos 2D • Pixels, Bitmaps y Fonts. BitBliting • Tessellators y Quadrics (GLUT) • OpenGL no puede renderizar poligonos concavos rellenos • Tessellation : conversion a poligonos convexos

  48. Otras FuncionalidadesOpenGL Programacion • Framebuffer • Color Buffer: • Front, Back, Front-left, Front-right, Back-left, Back-right,.. • Right/Left depende de la implementacion OpenGL • Debe soportar GL_STEREO o GL_DOUBLEBUFFER • Depth Buffer • Ocultacion de Caras • Stencil Buffer • Enmascarado, contornos de objetos,...

  49. Otras FuncionalidadesOpenGL Programacion • Framebuffer • Accumulation Buffer • Motion Blur, Depth of Field, etc... • En general es muy lento

  50. Otras FuncionalidadesOpenGL Programacion • Evaluadores y NURBS • Evaluadores OpenGL para dibujar curvas 2D y 3D • GLUT soporte para generar superficies NURBS (Non-Uniform Rational B-Spline)

More Related