Presentation is loading. Please wait.

Presentation is loading. Please wait.

Curso: Graficación Prof. Gueorgi Khatchatourov

Similar presentations


Presentation on theme: "Curso: Graficación Prof. Gueorgi Khatchatourov"— Presentation transcript:

1 Curso: Graficación Prof. Gueorgi Khatchatourov
OpenGL Primitives Curso: Graficación Prof. Gueorgi Khatchatourov

2 OpenGL Primitives back
The Vertex–A Position in Space A vertex = a coordinate in 2D or 3D 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 2D and 3D, 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 OpenGL, 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 3D space to create 3D 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.

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

4 Ir a la guía Specificar un vertice (I de V): ejemplos
The point (50,50,0) as specified by glVertex3f(50.0f, 50.0f, 0.0f). Two other forms of glVertex take two glVertex2f(50.0f, 50.0f); and four arguments, respectively, glVertex4f(50.0f, 50.0f, 0.0f, 1.0f). The two commands glVertex2i(1, 3) and glVertex2f(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.

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

6 Ir a la guía Specificar un vertice (III de V): sintaxis
glVertex*v() refers to all the vector versions of the command you use to specify vertices. void glVertex{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 glVertex*() are only effective between a glBegin() and glEnd() pair.

7 Ir a la guía Specificar un vertice (IV de V):dibujar puntos
glBegin(GL_POINTS); // Select points as the primitive glVertex3f(0.0f, 0.0f, 0.0f); // Specify a point glVertex3f(50.0f, 50.0f, 50.0f); // Specify another point glEnd(); // Done drawing points

8 Ir a la guía Specificar un vertice (V de V): Establecer tamaño del punto
void glPointSize(GLfloat size); The glPointSize 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]; // Store supported point size range GLfloat step; // Store supported point size increments // Get supported point size range and step size glGetFloatv(GL_POINT_SIZE_RANGE,sizes); glGetFloatv(GL_POINT_SIZE_GRANULARITY,&step);

9 Ir a la guía Dibujar líneas (I de VI)
glBegin(GL_LINES); glVertex3f(0.0f, 0.0f, 0.0f); glVertex3f(50.0f, 50.0f, 50.0f); glEnd();

10 Ir a la guía Dibujar líneas (II de VI): uso del ciclo para construir varias líneas
glBegin(GL_LINES); // All lines lie in the xy plane. z = 0.0f; for(angle = 0.0f; angle <= GL_PI; angle += (GL_PI/20.0f)) { // Top half of the circle x = 50.0f*sin(angle); y = 50.0f*cos(angle); glVertex3f(x, y, z); // First endpoint of line // Bottom half of the circle x = 50.0f*sin(angle + GL_PI); y = 50.0f*cos(angle + GL_PI); glVertex3f(x, y, z); // Second endpoint of line } // Done drawing points glEnd();

11 Ir a la guía Dibujar líneas (III de VI): Líneas encadenadas abiertas (strips) y cerradas (loops)
glBegin(GL_LINE_STRIP); glVertex3f(0.0f, 0.0f, 0.0f); // V0 glVertex3f(50.0f, 50.0f, 0.0f); // V1 glVertex3f(50.0f, 100.0f, 0.0f); // V2 glEnd(); glBegin(GL_LINE_LOOP);

12 Ir a la guía Dibujar líneas (IV de VI): Establecer grosor de la línea
void glLineWidth(GLfloat width); The glLineWidth 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 glGetFloatv(GL_LINE_WIDTH_RANGE,sizes); glGetFloatv(GL_LINE_WIDTH_GRANULARITY,&step);

13 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 glEnable(GL_LINE_STIPPLE); Then the function glLineStipple establishes the pattern that the lines use for drawing: void glLineStipple(GLint factor, GLushort pattern);

14 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.

15 Ir a la guía Dibujar triángulos(I de IV)
glBegin(GL_TRIANGLES); glVertex2f(0.0f, 0.0f); // V0 glVertex2f(25.0f, 25.0f); // V1 glVertex2f(50.0f, 0.0f); // V2 glVertex2f(-50.0f, 0.0f); // V3 glVertex2f(-75.0f, 50.0f); // V4 glVertex2f(-25.0f, 0.0f); // V5 glEnd();

16 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 V0 to V1, then to V2, and finally back to V0 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.

17 Ir a la guía Dibujar triángulos(III de IV): Tiras formados de triángulos: (Triangle Strips)
glBegin(GL_TRIANGLE_STRIP); ……………….. glEnd(); Draws a series of triangles (three-sided polygons) using vertices v0, v1, v2, then v2, v1, v3 (note the order), then v2, v3, v4, 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.

18 Ir a la guía Dibujar triángulos(IV de IV): Abanicos formados de triángulos: (Triangle Fans)
glBegin(GL_TRIANGLE_FAN); glVertex3f(0.0f, 0.0f, 75.0f); // 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.0f; angle < (2.0f*GL_PI); angle += (GL_PI/8.0f)) { // Calculate x and y position of the next vertex x = 50.0f*sin(angle); y = 50.0f*cos(angle); // Alternate color between red and green if((iPivot %2) == 0) glColor3f(0.0f, 1.0f, 0.0f); else glColor3f(1.0f, 0.0f, 0.0f); iPivot++; // Increment pivot to change color next time glVertex2f(x, y); // Specify the next vertex for the triangle fan } glEnd(); // Done drawing fan for cone

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

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

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

22 Ir a la guía Table: Geometric Primitive Names and Meanings
Value Meaning GL_POINTS individual points GL_LINES 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


Download ppt "Curso: Graficación Prof. Gueorgi Khatchatourov"

Similar presentations


Ads by Google