80 likes | 174 Views
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);
E N D
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 Type b 8-bit int signed char GLbyte s 16-bit int short GLshort i 32-bit int long GLint, GLsizei f 32-bit float float GLfloat, GLclampf d 64-bit float double GLdouble, Glclampd ub 8-bit uns int unsigned char Glubyte, GLboolean us 16-bit uns int unsigned short GLushort ui 32-bit usn int unsigned long GLuint, GLenum uns: unsigned
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 Color
glVertex glVertex{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(Glenummode) … 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 segments GL_POLYGON boundary of simple polygon GL_TRIANGLES triples of vertices interpreted as triangles GL_QUADS quadruples of vertices, as quads GL_LINE_STRIP series of connected line segment GL_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() ;
Examples GLfloat 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() ;
Examples GLfloat 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() ;