OpenGL: Introduction

parakeetincurableΛογισμικό & κατασκευή λογ/κού

13 Δεκ 2013 (πριν από 3 χρόνια και 10 μήνες)

92 εμφανίσεις

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

Color


glClearColor(
GLcampf
r
, GLcampf
g
, GLcampf
b
, GLcampf
a
);

Sets the current clearing color.


Colors

0.0, 0.0, 0.0 black

1.0, 1.0, 0.0 yellow

0.0, 1.0, 1.0 cyan

1.0, 1.0, 1.0 white


glClear(
Glbitfield
mask
)

Clears the specified buffer


Buffers

Color Buffer GL_COLOR_BUFFER_BIT

Depth Buffer GL_DEPTH_BUFFER_BIT

Accum Buffer GL_ACCUM_BUFFER_BIT

Stencil Buffer GL_STENCIL_BUFFER_BIT

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(
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 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++)


glVertex
2
v(list[i]);

glEnd() ;

glBegin(GL_LINE_LOOP)


for (int i =
0
; i <
6
;i++)


glVertex
2
v(list[i]);

glEnd() ;

Examples

GLfloat list[6][2] ;

glColor
3
f(
0.0
,
1.0
,
0.0
);

glBegin(GL_TRIANGLES)


for (int i =
0
; i <
6
;i++)


glVertex
2
v(list[i]);

glEnd() ;

glBegin(GL_TRIANGLES)


glColor
3
f(
1.0
,
0.0
,
0.0
);


for ( i =
0
; i <
3
;i++)


glVertex
2
v(list[i]);


glColor
3
f(
1.0
,
1.0
,
1.0
);


for ( i =
3
; i <
6
;i++)


glVertex
2
v(list[i]);

glEnd() ;