Open GL Primitives Curso Graficacin Prof Gueorgi Khatchatourov

  • Slides: 22
Download presentation
Open. GL Primitives Curso: Graficación Prof. Gueorgi Khatchatourov

Open. GL Primitives Curso: Graficación Prof. Gueorgi Khatchatourov

Open. GL Primitives back The Vertex–A Position in Space A vertex = a coordinate

Open. GL Primitives back The Vertex–A Position in Space A vertex = a coordinate in 2 D or 3 D space. The geometric definition of a vertex is not just a point in space, but rather the point at which an intersection of two lines or curves occurs. This is the essence of primitives. In both 2 D and 3 D, when you draw an object, you actually compose it with several smaller shapes called primitives. A primitive is simply the interpretation of a set or list of vertices into some shape drawn on the screen. There are 10 primitives in Open. GL, from a simple point drawn in space to a closed polygon of any number of sides. Primitives are one- or two-dimensional entities or surfaces such as points, lines, and polygons (a flat, multisided shape) that are assembled in 3 D space to create 3 D objects. For example, a three-dimensional cube consists of six two-dimensional squares, each placed on a separate face. Each corner of the square (or of any primitive) is represented by a vertex.

Guía de los tipos geométricos primitivos (ver la tabla de Geometric Primitive Types) Puntos(Vertices)

Guía de los tipos geométricos primitivos (ver la tabla de Geometric Primitive Types) Puntos(Vertices) Líneas Triángulos Cuadrilaterales Polígonos

Ir a la guía Specificar un vertice (I de V): ejemplos The point (50,

Ir a la guía Specificar un vertice (I de V): ejemplos The point (50, 0) as specified by gl. Vertex 3 f(50. 0 f, 0. 0 f). Two other forms of gl. Vertex take two gl. Vertex 2 f(50. 0 f, 50. 0 f); and four arguments, respectively, gl. Vertex 4 f(50. 0 f, 1. 0 f). The two commands gl. Vertex 2 i(1, 3) and gl. Vertex 2 f(1. 0, 3. 0) are equivalent, except that the first specifies the vertex's coordinates as 32 -bit integers, and the second specifies them as single-precision floating-point numbers.

Ir a la guía Specificar un vertice (II de V): cómo se interpretan los

Ir a la guía Specificar un vertice (II de V): cómo se interpretan los vértices cuatro dimensionales

Ir a la guía Specificar un vertice (III de V): sintaxis • gl. Vertex*v()

Ir a la guía Specificar un vertice (III de V): sintaxis • gl. Vertex*v() refers to all the vector versions of the command you use to specify vertices. void gl. Vertex{234}{sifd}[v](TYPEcoords); • Specifies a vertex for use in describing a geometric object. You can supply up to four coordinates (x, y, z, w) for a particular vertex or as few as two (x, y) by selecting the appropriate version of the command. If you use a version that doesn't explicitly specify z or w, z is understood to be 0 and w is understood to be 1. • Calls to gl. Vertex*() are only effective between a gl. Begin() and gl. End() pair.

Ir a la guía Specificar un vertice (IV de V): dibujar puntos gl. Begin(GL_POINTS);

Ir a la guía Specificar un vertice (IV de V): dibujar puntos gl. Begin(GL_POINTS); // Select points as the primitive gl. Vertex 3 f(0. 0 f, 0. 0 f); // Specify a point gl. Vertex 3 f(50. 0 f, 50. 0 f); // Specify another point gl. End(); // Done drawing points

Ir a la guía Specificar un vertice (V de V): Establecer tamaño del punto

Ir a la guía Specificar un vertice (V de V): Establecer tamaño del punto void gl. Point. Size(GLfloat size); The gl. Point. Size function takes a single parameter that specifies the approximate diameter in pixels of the point drawn. Not all point sizes are supported, however, and you should make sure the point size you specify is available. Use the following code to get the range of point sizes and the smallest interval between them: GLfloat sizes[2]; GLfloat step; // Store supported point size range // Store supported point size increments // Get supported point size range and step size gl. Get. Floatv(GL_POINT_SIZE_RANGE, sizes); gl. Get. Floatv(GL_POINT_SIZE_GRANULARITY, &step);

Ir a la guía Dibujar líneas (I de VI) gl. Begin(GL_LINES); gl. Vertex 3

Ir a la guía Dibujar líneas (I de VI) gl. Begin(GL_LINES); gl. Vertex 3 f(0. 0 f, 0. 0 f); gl. Vertex 3 f(50. 0 f, 50. 0 f); gl. End();

Ir a la guía Dibujar líneas (II de VI): uso del ciclo para construir

Ir a la guía Dibujar líneas (II de VI): uso del ciclo para construir varias líneas gl. Begin(GL_LINES); // All lines lie in the xy plane. z = 0. 0 f; for(angle = 0. 0 f; angle <= GL_PI; angle += (GL_PI/20. 0 f)) { // Top half of the circle x = 50. 0 f*sin(angle); y = 50. 0 f*cos(angle); gl. Vertex 3 f(x, y, z); // First endpoint of line // Bottom half of the circle x = 50. 0 f*sin(angle + GL_PI); y = 50. 0 f*cos(angle + GL_PI); gl. Vertex 3 f(x, y, z); // Second endpoint of line } // Done drawing points gl. End();

Ir a la guía Dibujar líneas (III de VI): Líneas encadenadas abiertas (strips) y

Ir a la guía Dibujar líneas (III de VI): Líneas encadenadas abiertas (strips) y cerradas (loops) gl. Begin(GL_LINE_STRIP); gl. Vertex 3 f(0. 0 f, 0. 0 f); // V 0 gl. Vertex 3 f(50. 0 f, 0. 0 f); // V 1 gl. Vertex 3 f(50. 0 f, 100. 0 f, 0. 0 f); // V 2 gl. End(); gl. Begin(GL_LINE_LOOP); gl. Vertex 3 f(0. 0 f, 0. 0 f); // V 0 gl. Vertex 3 f(50. 0 f, 0. 0 f); // V 1 gl. Vertex 3 f(50. 0 f, 100. 0 f, 0. 0 f); // V 2 gl. End();

Ir a la guía Dibujar líneas (IV de VI): Establecer grosor de la línea

Ir a la guía Dibujar líneas (IV de VI): Establecer grosor de la línea void gl. Line. Width(GLfloat width); The gl. Line. Width function takes a single parameter that specifies the approximate width, in pixels, of the line drawn. Just like point sizes, not all line widths are supported, and you should make sure the line width you want to specify is available. Use the following code to get the range of line widths and the smallest interval between them: Use the following code to get the range of point sizes and the smallest interval between them: GLfloat sizes[2]; // Store supported line width range GLfloat step; // Store supported line width increments // Get supported line width range and step size gl. Get. Floatv(GL_LINE_WIDTH_RANGE, sizes); gl. Get. Floatv(GL_LINE_WIDTH_GRANULARITY, &step);

Ir a la guía Dibujar líneas (V de VI): Establecer un patrón de línea

Ir a la guía Dibujar líneas (V de VI): Establecer un patrón de línea salpicada (line stippling) (I) • In addition to changing line widths, you can create lines with a dotted or dashed pattern, called stippling. To use line stippling, you must first enable stippling with a call to gl. Enable(GL_LINE_STIPPLE); Then the function gl. Line. Stipple establishes the pattern that the lines use for drawing: void gl. Line. Stipple(GLint factor, GLushort pattern);

Ir a la guía Dibujar líneas (VI de VI): Establecer un patrón de línea

Ir a la guía Dibujar líneas (VI de VI): Establecer un patrón de línea salpicada (line stippling) (II) • The pattern parameter is a 16 -bit value that specifies a pattern to use when drawing the lines. Each bit represents a section of the line segment that is either on or off. By default, each bit corresponds to a single pixel, but the factor parameter serves as a multiplier to increase the width of the pattern. For example, setting factor to 5 causes each bit in the pattern to represent five pixels in a row that are either on or off. Furthermore, bit 0 (the least significant bit) of the pattern is used first to specify the line. Figure illustrates a sample bit pattern applied to a line segment.

Ir a la guía Dibujar triángulos(I de IV) gl. Begin(GL_TRIANGLES); gl. Vertex 2 f(0.

Ir a la guía Dibujar triángulos(I de IV) gl. Begin(GL_TRIANGLES); gl. Vertex 2 f(0. 0 f, 0. 0 f); // V 0 gl. Vertex 2 f(25. 0 f, 25. 0 f); // V 1 gl. Vertex 2 f(50. 0 f, 0. 0 f); gl. Vertex 2 f(-75. 0 f, 50. 0 f); gl. Vertex 2 f(-25. 0 f, 0. 0 f); gl. End(); // V 2 // V 3 // V 4 // V 5

Ir a la guía Dibujar triángulos(II de IV): Notas: Color y orientación de triángulo

Ir a la guía Dibujar triángulos(II de IV): Notas: Color y orientación de triángulo • The triangles will be filled with the currently selected drawing color. If you don't specify a drawing color at some point, you can't be certain of the result. • An important characteristic of any polygonal primitive is illustrated in Figura relacionada a la orienta. . Notice the arrows on the lines that connect the vertices. When the first triangle is drawn, the lines are drawn from V 0 to V 1, then to V 2, and finally back to V 0 to close the triangle. This path is in the order that the vertices are specified, and for this example, that order is clockwise from your point of view. The same directional characteristic is present for the second triangle as well.

Ir a la guía Dibujar triángulos(III de IV): Tiras formados de triángulos: (Triangle Strips)

Ir a la guía Dibujar triángulos(III de IV): Tiras formados de triángulos: (Triangle Strips) gl. Begin(GL_TRIANGLE_STRIP); ………………. . gl. End(); Draws a series of triangles (three-sided polygons) using vertices v 0, v 1, v 2, then v 2, v 1, v 3 (note the order), then v 2, v 3, v 4, and so on. The ordering is to ensure that the triangles are all drawn with the same orientation so that the strip can correctly form part of a surface. Preserving the orientation is important for some operations, such as culling. n must be at least 3 for anything to be drawn.

Ir a la guía Dibujar triángulos(IV de IV): Abanicos formados de triángulos: (Triangle Fans)

Ir a la guía Dibujar triángulos(IV de IV): Abanicos formados de triángulos: (Triangle Fans) gl. Begin(GL_TRIANGLE_FAN); gl. Vertex 3 f(0. 0 f, 75. 0 f); // Pinnacle of cone is shared vertex for fan, moved up z-axis // Loop around in a circle and specify even points along the circle // as the vertices of the triangle fan for(angle = 0. 0 f; angle < (2. 0 f*GL_PI); angle += (GL_PI/8. 0 f)) { // Calculate x and y position of the next vertex x = 50. 0 f*sin(angle); y = 50. 0 f*cos(angle); // Alternate color between red and green if((i. Pivot %2) == 0) gl. Color 3 f(0. 0 f, 1. 0 f, 0. 0 f); else gl. Color 3 f(1. 0 f, 0. 0 f); i. Pivot++; // Increment pivot to change color next time gl. Vertex 2 f(x, y); // Specify the next vertex for the triangle fan } gl. End(); // Done drawing fan for cone

Regresar a Notas: Color y orientación de triángulo. Figura relacionada a la orientación de

Regresar a Notas: Color y orientación de triángulo. Figura relacionada a la orientación de triángulos

Regresar a “line stippling” Figura: Un patrón para construir segmento de una linea salpicada

Regresar a “line stippling” Figura: Un patrón para construir segmento de una linea salpicada Ver mas opciones

Regresar a “line stippling” Figura: Más patrones para construir segmento de una linea salpicada

Regresar a “line stippling” Figura: Más patrones para construir segmento de una linea salpicada Where pattern and factor are parameters of gl. Line. Stipple(): void gl. Line. Stipple(GLint factor, GLushort pattern);

Ir a la guía Table: Geometric Primitive Names and Meanings • • • Value

Ir a la guía Table: Geometric Primitive Names and Meanings • • • Value GL_POINTS GL_LINES Meaning individual points pairs of vertices interpreted as individual line segments GL_LINE_STRIP series of connected line segments GL_LINE_LOOP same as above, with a segment added between last and first vertices GL_TRIANGLES triples of vertices interpreted as triangles GL_TRIANGLE_STRIP linked strip of triangles GL_TRIANGLE_FAN linked fan of triangles GL_QUADS quadruples of vertices interpreted as four-sided polygons GL_QUAD_STRIP linked strip of quadrilaterals GL_POLYGON boundary of a simple, convex polygon