lecture04-1

# glbegingltriangles glvertex3fvv1 glvertex3fvv2

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: appens immediately each OpenGL: Drawing Triangles You can draw multiple triangles between You glBegin(GL_TRIANGLES) and glEnd(): glBegin(GL_TRIANGLES) glEnd() float v1[3], v2[3], v3[3], v4[3]; ... glBegin(GL_TRIANGLES); glVertex3fv(v1); glVertex3fv(v2); glVertex3fv(v3); glVertex3fv(v1); glVertex3fv(v3); glVertex3fv(v4); glEnd(); Each set of 3 vertices forms a triangle • What do the triangles drawn above look like? • How much redundant computation is happening? OpenGL: Triangle Strips An OpenGL triangle strip primitive reduces this redundancy by sharing vertices: An triangle glBegin(GL_TRIANGLE_STRIP); glVertex3fv(v0); glVertex3fv(v1); v2 glVertex3fv(v2); glVertex3fv(v3); v0 v4 glVertex3fv(v4); v5 glVertex3fv(v5); glEnd(); v1 • triangle 0 is v0, v1, v2 • triangle 1 is v2, v1, v3 (why not v1, v2, v3?) • triangle 2 is v2, v3, v4 • triangle 3 is v4, v3, v5 (again, not v3, v4, v5) triangle not v3 OpenGL: More Examples Example: GL supports quadrilaterals: glBegin(GL_QUADS); glVertex3f(-1, 1, 0); glVertex3f(-1, glVertex3f(-1, -1, 0); glVertex3f(-1, glVertex3f(1, -1, 0); glVertex3f(1, 1, 0); glEnd(); • This type of operation is called immediate-mode rendering; This immediate-mode each command happens immediately each OpenGL: Front/Back Rendering Each polygon has two sides, front and back OpenGL can render the two differently The ordering of vertices in the list determines The which is the front side: which • When looking at the front side, the vertices go When front counterclockwise counterclockwise – This is basically the right-hand rule – Note that this still holds after perspective projection OpenGL: Drawing Triangles You can draw multiple triangles between You glBegin(GL_TRIANGLES) and glEnd(): glBegin(GL_TRIANGLES) glEnd() float v1[3], v2[3], v3[3], v4[3]; ... glBegin(GL_TRIANGLES); glVertex3fv(v1); glVertex3fv(v2); glVertex3fv(v3); glVertex3fv(v1); glVertex3fv(v3); glVertex3fv(v4); glEnd(); Each set of 3 vertices forms a triangle • What do the triangles drawn above look like? • How much redundant computation is happening? OpenGL: Triangle Strips An OpenGL triangle strip primitive reduces this redundancy by sharing An triangle vertices: vertices: glBegin(GL_TRIANGLE_STRIP);...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online