opengl: introduction
DESCRIPTION
OpenGL: Introduction. #include main() { OpenWindow() ; glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); glColor3f(1.0, 1.0, 1.0);. glBegin(); glVertex2f(-0.5, -0.5); - PowerPoint PPT PresentationTRANSCRIPT
OpenGL: Introduction#include <SomeWindowLib.h>main() { OpenWindow() ; glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); glColor3f(1.0, 1.0, 1.0);
glBegin(); glVertex2f(-0.5, -0.5); glVertex2f(-0.5, -0.5); glVertex2f(-0.5, -0.5); glVertex2f(-0.5, -0.5);glEnd();
glFlush(); WaitForAWhille() ; }
OpenGL Data Types
Suffix Data Type C-Language Type OpenGL Typeb 8-bit int signed char GLbytes 16-bit int short GLshorti 32-bit int long GLint, GLsizeif 32-bit float float GLfloat, GLclampf d 64-bit float double GLdouble, Glclampdub 8-bit uns int unsigned char Glubyte, GLbooleanus 16-bit uns int unsigned short GLushortui 32-bit usn int unsigned long GLuint, GLenum
uns: unsigned
Color• glClearColor(GLcampf r, GLcampf g, GLcampf b, GLcampf a);
Sets the current clearing color.
• Colors0.0, 0.0, 0.0 black1.0, 1.0, 0.0 yellow0.0, 1.0, 1.0 cyan1.0, 1.0, 1.0 white
• glClear(Glbitfield mask)Clears the specified buffer
• Buffers Color Buffer GL_COLOR_BUFFER_BITDepth Buffer GL_DEPTH_BUFFER_BITAccum Buffer GL_ACCUM_BUFFER_BITStencil Buffer GL_STENCIL_BUFFER_BIT
glVertexglVertex{234}{sifd}[v]{TYPE coords);Specifies a vertex for use in geometric objects
glVertex2s(2,3);glVertex3d(5.2, 4.1, 4.0);GLint vert[3] = {3,7,11};glVertex3iv(vert);glVertex2f(2.5, 7.0);
glBegin(Glenum mode) … glEnd()Marks a beginning of a vertex list that describes a geometric object
Mode Meaning GL_POINT individual points GL_LINES pairs of vertices as individual line segmentsGL_POLYGON boundary of simple polygonGL_TRIANGLES triples of vertices interpreted as triangles GL_QUADS quadruples of vertices, as quadsGL_LINE_STRIP series of connected line segmentGL_LINE_LOOP closed polyline
Examples
glBegin(GL_POLYGON); glVertex2i(0,0); glVertex2i(0,1); glVertex2i(1,1); glVertex2i(1,0);glEnd() ;
glBegin(GL_POINTS); glVertex2i(0,0); glVertex2i(0,1); glVertex2i(1,1); glVertex2i(1,0);glEnd() ;
ExamplesGLfloat list[6][2] ;
glBegin(GL_LINES) for (int i = 0 ; i < 6 ;i++) glVertex2v(list[i]);glEnd() ;
glBegin(GL_LINE_STRIP) for (int i = 0 ; i < 6 ;i++) glVertex2v(list[i]);glEnd() ;
glBegin(GL_LINE_LOOP) for (int i = 0 ; i < 6 ;i++) glVertex2v(list[i]);glEnd() ;
ExamplesGLfloat list[6][2] ;
glColor3f(0.0, 1.0, 0.0);glBegin(GL_TRIANGLES) for (int i = 0 ; i < 6 ;i++) glVertex2v(list[i]);glEnd() ;
glBegin(GL_TRIANGLES) glColor3f(1.0, 0.0, 0.0); for ( i = 0 ; i < 3 ;i++) glVertex2v(list[i]); glColor3f(1.0, 1.0, 1.0); for ( i = 3 ; i < 6 ;i++) glVertex2v(list[i]);glEnd() ;