libreriasgraficas
TRANSCRIPT
-
8/4/2019 libreriasGraficas
1/53
Libreras Grficas
Introduccin a OpenGL
-
8/4/2019 libreriasGraficas
2/53
-
8/4/2019 libreriasGraficas
3/53
Definicin de librera grfica
Software que genera imgenes en base a unosmodelos matemticos y unos patrones de
iluminacin, texturas, etc.
-
8/4/2019 libreriasGraficas
4/53
Libreras, ficheros, sintaxis
Origen IGL-Plot 10 (Tektronix) Starbase (Hewlett Packard)
Iris GL Library (SGI)
Distinguir la naturaleza de otros sistemasgrficos VRML, X3D (Lenguajes de descripcin)
DirectX-Direct3D Java 3D Open Inventor Performer, Fahrenheit Motores
-
8/4/2019 libreriasGraficas
5/53
Objetivos de las libreras grficas
Independencia del hardware (tantodispositivos de entrada como de salida).
Independencia de la aplicacin (la libreraes accedida a travs de un interface nico(al menos para cada lenguaje de
programacin) para cualquier aplicacin.
-
8/4/2019 libreriasGraficas
6/53
Tipos de libreras grficas
Direct Rendering and gfx packages: OpenGL, Direct3D, GKS, PHIGS, PEX, GKS, etc
Scene-graph based OpenGL Performer, Open Inventor, OpenGL
Optimizer, PHIGS+, etc
Toolkits World Toolkit, AVANGO, Game Engines, etc
-
8/4/2019 libreriasGraficas
7/53
... Gestin imgenes 3D
Bajo nivel Tareas
Gestin en serie de los elementos de la escena Elementos de la escena
Primitivas grficas Atributos ( edicin imgenes)
Variables de estado Generacin imagen
Sistemas OpenGL Direct 3D Java 3D
Alto nivel
-
8/4/2019 libreriasGraficas
8/53
... (... Gestin imgenes 3D)
Alto nivel Tareas
Gestin global de los elementos de la escena rbol escena Carga/descarga de memoria Gestin elementos no visibles Eleccin del modelo geomtrico: Nivel detalle, Textura Eleccin de la tcnica de presentacin (rendering)
Sistemas Inventor Performer ( Fahrenheit ) Hewlett Packard
-
8/4/2019 libreriasGraficas
9/53
DirectX Componentes
DirectDraw
DirectSound
DirectPlay
Direct3D
....
-
8/4/2019 libreriasGraficas
10/53
DirectX - Introduccin
Qu es DirectX?Conjunto de APIs que permite a los
desarrolladores de contenido interactivo(imagen, video, sonido...) acceder acaractersticas de hardware especializado sintener que escribir cdigo especfico de
hardware
-
8/4/2019 libreriasGraficas
11/53
DirectX - Introduccin
Componentes incluidos en DirectXNos permiten desarrollar aplicaciones de alto
rendimiento y en tiempo real API DirectPlay
API DirectInput
API DirectSound
API DirectDraw
API Direct3D
-
8/4/2019 libreriasGraficas
12/53
DirectX - Introduccin
Objetivos de DirectXDesarrollo de Aplicaciones Windows de altorendimiento
Tarjetas aceleradoras
Plugn Play Servicios de comunicaciones construidos bajo
Windows
Recursos instalados en el sistema
Utilizacin del nuevo hardware implementado
-
8/4/2019 libreriasGraficas
13/53
DirectX - Introduccin
DirectX & COM (Component ObjectModel) Objeto: caja negra que representa el hardware y
requiere comunicacin con las aplicaciones a travs
de una interface. Mtodo: comandos enviados y recibidos por el
objeto a travs de la interface COM
Ej.: Mtodo GetDisplayMode es enviado a
travs de la interface IDirectDraw2 paratomar el valor de la actual resolucin de lapantalla mediante el objeto DirectDraw
-
8/4/2019 libreriasGraficas
14/53
DirectX - DirectDraw
Se encarga del manejo de la memoria de vdeo
Proporciona herramientas para
Manipulacin de mltiples buffers de vdeo Acceso directo a la memoria de vdeo
Page flipping
Back Buffering
Manejo de la paleta grfica Clipping
-
8/4/2019 libreriasGraficas
15/53
DirectX - DirectDraw
Tipos de objetos IDirectDraw
IDirectDrawSurface IDirectDrawPalette
IDirectDrawClipper
IDirectDrawVideoPort
-
8/4/2019 libreriasGraficas
16/53
-
8/4/2019 libreriasGraficas
17/53
DirectX - DirectSound
Componente de Audio de DirectX:Mezclado de canales de audio
Aceleracin hardwareAcceso directo al dispositivo de sonido
Captura de Audio
-
8/4/2019 libreriasGraficas
18/53
DirectX - DirectSound
Interfaces COM IDirectSoundBuffer
IDirectSound3DBuffer IDirectSound3DListener
IDirectSoundCapture
IDirectSoundCaptureBuffer
-
8/4/2019 libreriasGraficas
19/53
DirectX - DirectPlay Simplifica el acceso de las aplicaciones a
los servicios de comunicacin
Otorga independencia para la creacin de
servidores de juegos Comunicaciones
Peer-to-Peer
Cliente/Servidor
-
8/4/2019 libreriasGraficas
20/53
DirectX - Direct3D
Interfaz grfica para hardware 3DPermitir grficos tridimensionales interactivos
en aplicaciones de Windows
2 Modos:Inmediato API 3D de bajo nivel
Independiente del dispositivo
Programadores experimentadosRetenido (Obsoleta)
Desarrollo rpidos
Capa superior del inmediato
-
8/4/2019 libreriasGraficas
21/53
DirectX - Direct3D Conceptos Bsicos
Sistemas de coordenadas 3-D Left-handed (mano izquierda) Podemos simular el right-handed
Transformaciones 3-D Traslacin Rotacin Escalado
Polgonos Normales de cara y vrtice Modos de sombreado Interpolaciones de tringulos
-
8/4/2019 libreriasGraficas
22/53
DirectX - Direct3D Conceptos Bsicos
Tringulos
Reglas de rasterizacin de tringulos
-
8/4/2019 libreriasGraficas
23/53
-
8/4/2019 libreriasGraficas
24/53
Objetivos de diseo de OpenGL:
API grfico de altas prestaciones (conaceleracin por hardware)
Posee cierta independencia del hardware Es un API natural (en C) con posibilidad de
extensibilidad
-
8/4/2019 libreriasGraficas
25/53
Se convierte en standard porque
No trata de hacer demasiadas cosas: Slo renderiza la imagen, no gestiona ventanas, etc...
No posee animacin de alto nivel, modelado, sonido,etc...
Hace lo suficiente: Efectos de renderizado tiles y altas prestaciones
Fue promovido por empresas lderes en el sector(SGI, Microsoft, etc)
-
8/4/2019 libreriasGraficas
26/53
-
8/4/2019 libreriasGraficas
27/53
Ventajas de OpenGL EvolvingBecause of its thorough and forward-looking design, OpenGL allows new
hardware innovations to be accessible through the API via the OpenGLextension mechanism. In this way, innovations appear in the API in a timelyfashion, letting application developers and hardware vendors incorporate newfeatures into their normal product release cycles.
ScalableOpenGL API-based applications can run on systems ranging from consumerelectronics to PCs, workstations, and supercomputers. As a result,applications can scale to any class of machine that the developer chooses totarget.
-
8/4/2019 libreriasGraficas
28/53
Ventajas de OpenGL Easy to useOpenGL is well structured with an intuitive design and logical commands.
Efficient OpenGL routines typically result in applications with fewer lines ofcode than those that make up programs generated using other graphicslibraries or packages. In addition, OpenGL drivers encapsulate informationabout the underlying hardware, freeing the application developer from havingto design for specific hardware features.
Well-documentedNumerous books have been published about OpenGL, and a great deal ofsample code is readily available, making information about OpenGLinexpensive and easy to obtain.
-
8/4/2019 libreriasGraficas
29/53
Renderizado de OpenGL
Primitivas geomtricas: Puntos, lneas y polgonos
Primitivas de imgenes: Imgenes y bitmaps
Pipelines separados para imgenes y geometraunidos mediante el mapeador de texturas
El renderizado depende del estado (luces, colores,materiales, etc)
-
8/4/2019 libreriasGraficas
30/53
Arquitectura OpenGL
-
8/4/2019 libreriasGraficas
31/53
-
8/4/2019 libreriasGraficas
32/53
Capacidades de OpenGL
Double buffering. Used to provide smooth animation of objects. Eachsuccessive scene of an object in motion can be constructed in the backor "hidden" buffer and then displayed. This allows only completeimages to ever be displayed on the screen.
Feedback. A mode where OpenGL will return the processed geometricinformation (colors, pixel positions, and so on) to the application ascompared to rendering them into the frame buffer.
Level of detail control for mipmap textures to allow loading only asubset of levels.
Materials lighting and shading. The ability to accurately compute the
color of any point given the material properties for the surface. Pixel operations. Storing, transforming, mapping, zooming. Polynomial evaluators. To support non-uniform rational B-splines
(NURBS). Primitives. A point, line, polygon, bitmap, or image. Raster primitives. Bitmaps and pixel rectangles.
-
8/4/2019 libreriasGraficas
33/53
-
8/4/2019 libreriasGraficas
34/53
Capacidades de OpenGL
Texture mapping. The process of applying an image to a graphicsprimitive. This technique is used to generate realism in images.
Three Dimensional Texturing. Three-dimensional texturing forsupporting hardware-accelerated volume rendering.
Transformation. The ability to change the rotation, size, andperspective of an object in 3D coordinate space. Vertex array enhancements to specify a subrange of the array and
draw geometry from that subrange in one operation. Z-buffering. The Z-buffer is used to keep track of whether one part of
an object is closer to the viewer than another.
-
8/4/2019 libreriasGraficas
35/53
APIs relacionadas
GLX, WGL, AGX Conexiones de OpenGL con el entorno de ventanas
GLU (OpenGL Utility library) Es parte de OpenGL Incluye soporte para cudricas, NURBS, etc.
GLUT (OpenGL Utility Toolkit) No forma parte oficialmente de OpenGL
Permite la portabilidad de las aplicaciones sobredistintos sistemas de ventanas MESA: OpenGL clone
-
8/4/2019 libreriasGraficas
36/53
APIs de OpenGL
Librera de funciones para generar imgenes a partir demodelos 3D, ms otras libreras auxiliares gl la librera opengl relacionada directamente con el H/W
glu librera de mayor nivel construida sobre opengl glaux librera fuera de uso glut librera para crear interfaces de usuario transportables (Linux,
Windows, Unix en general, MacOS) glut.dll windows\system(32)
glut.lib
DevStudio\Vc\lib glut.h DevStudio\Vc\include\gl
-
8/4/2019 libreriasGraficas
37/53
Arquitectura de APIs de OpenGL
-
8/4/2019 libreriasGraficas
38/53
Detalles de programacin
Aadir las libreras opengl32.lib glu32.libglut32.lib Project : settings : link : Object/Library Modules
Ficheros a incluir #include #include If you are using GLUT for managing your window
manager #include Note that glut.h includes gl.h, glu.h, and glx.h automatically,
so including all three files is redundant.
-
8/4/2019 libreriasGraficas
39/53
Estados
Mquina de estados Color de fondo Intensidad de luz Material de dibujo Luz encendida o apagada etc
Valor o estado glColor*(), glGetFloatv() glEnable(), glDisable(), glIsEnabled()
-
8/4/2019 libreriasGraficas
40/53
-
8/4/2019 libreriasGraficas
41/53
-
8/4/2019 libreriasGraficas
42/53
Constantes
Ejemplo : GL_COLOR_BUFFER_BIT
Defined constantsBegin with GL_Use all capital letters
Use underscores to separate words
Con frecuencia se realizan operaciones or
-
8/4/2019 libreriasGraficas
43/53
... (gl)
pure "output", but lacks connection with display glClear (command)
glClearColor (state)
glBegin glEnd
glVertex* (geometry)
glColor* (attribute, state)
glFlush, glFinish (command stack & processing)
(debbuging)
(mapping from modelling coord. to display coordinates) (aspect ratio)
(need for a transformation management system)
-
8/4/2019 libreriasGraficas
44/53
... (glut)
Window system independent management window management
glutInitDisplayModeg( GLUT_RGB | GLUT_SINGLE ); glutInitWindowSize( WIDTH, HEIGHT ); glutInitWindowPosition ( 550, 350 ); glutCreateWindow(Basic Draw");
input : event handling similar to : The X Window system, MOTIF, MFF, ... (event) void Display(void); (callback function) glutDisplayFunc(Display ); (binding event & callback)
voidDisplay ( void ) glutMainLoop(); (dispatching events)
-
8/4/2019 libreriasGraficas
45/53
Primitivas
-
8/4/2019 libreriasGraficas
46/53
-
8/4/2019 libreriasGraficas
47/53
Atributos glPointSize(GLfloat)
glLineWidth(GLfloat)
glLineStipple(GLint factor, GLushort pattern)
glEnable( GL_LINE_STIPPLE )
glPolygonMode( face, mode )
GL_FRONT GL_BACK GL_FRONT_AND_BACK GL_POINT GL_LINE GL_FILL
glPolygonStipple (enable) transparency
glEdgeFlag* mode Line, splitted concave polygons
glColor* glMaterial*
-
8/4/2019 libreriasGraficas
48/53
Variables de estado
Valor de defecto Valor actual
Gestin en una aplicacin o en un mdulo
reutilizable Valor de defecto en una aplicacin dada
Poltica de cambios de estado en un mdulo de software
glPushAttrib( ored mask ) / glPopAttrib() Permiten salvar grupos de atributos
GL_ACCUM_BUFFER_BIT accum-buffer
-
8/4/2019 libreriasGraficas
49/53
Grupos de
atributos
_ _ _
GL_ALL_ATTRIB_BITS --
GL_COLOR_BUFFER_BIT color-buffer
GL_CURRENT_BIT current
GL_DEPTH_BUFFER_BIT depth-buffer
GL_ENABLE_BIT enable
GL_EVAL_BIT eval
GL_FOG_BIT fog
GL_HINT_BIT hint
GL_LIGHTING_BIT lighting
GL_LINE_BIT lineGL_LIST_BIT list
GL_PIXEL_MODE_BIT pixel
GL_POINT_BIT point
GL_POLYGON_BIT polygon
GL_POLYGON_STIPPLE_BIT polygon-stippleGL_SCISSOR_BIT scissor
GL_STENCIL_BUFFER_BIT stencil-buffer
GL_TEXTURE_BIT texture
GL_TRANSFORM_BIT transform
GL_VIEWPORT_BIT viewport
-
8/4/2019 libreriasGraficas
50/53
Agrupamiento Arrays
Evitar prdidas de tiempo en llamadas a funciones
Display Lists
dem La informacin puede est preprocesada
Almacenar en el procesador grfico para aliviar el bus Workstations
PCs
-
8/4/2019 libreriasGraficas
51/53
Comandos entre : glBegin-glEndCommand Purpose of Command Reference
glVertex*() set vertex coordinates Chapter 2
glColor*() set current color Chapter 5
glIndex*() set current color index Chapter 5
glNormal*() set normal vector coordinates Chapter 2
glEvalCoord*() generate coordinates Chapter 11
glCallList(), glCallLists() execute display list(s) Chapter 4
glTexCoord*() set texture coordinates Chapter 9
glEdgeFlag*() control drawing of edges Chapter 2
glMaterial*() set material properties Chapter 6
-
8/4/2019 libreriasGraficas
52/53
Ejemplo : Window to viewport
gl glMatrixMode glLoadIdentity
viewport glOrtho glGetIntegerv
glut glutReshapeFunc( myNewSize )
void myNewSize( int w, int h )
-
8/4/2019 libreriasGraficas
53/53
Links Interesantes
www.opengl.org Official site ofOpenGL
nehe.gamedev.net NeHe, variousOpenGL tutorials
romka.demonews.com Romka,various OpenGL tutorials
Nexe.gamedev.net same as Nehefor DirextX