OpenGL drawing graphics unit skills introduction

Dot drawing

OpenGL provides a series of functions. They all start with glVertex, followed by a number and 1~2 letters. E.g:
glVertex2d(x,y)
glVertex2f(x,y)
glVertex3f(x,y,z)

glVertex3fv(GLfloat *p)

The number indicates the number of parameters:

2 means there are two parameters, 3 means three;

The letter indicates the type of the parameter:

i represents a 32-bit integer (this type is defined in OpenGL as GLint and GLsizei),
f represents a 32-bit floating-point number (this type is defined in OpenGL as GLfloat and GLclampf),

d represents a 64-bit floating-point number (OpenGL defines this type as GLdouble and GLclampd).

glVertex2i(3, 3);
glVertex2f(3.0f, 3.0f);
glVertex3f(3.0f, 3.0f, 0.0f);

GLfloat p[] = { 3.0f,3.0f, 0.0f };

glVertex3fv(p)

Note: Points defined in OpenGL can have different sizes, and their function forms are:

Void glPointSize( GLfloat size );
The width of the parameter setpoint (in pixels) must be greater than 0.0, by default it is 1.0.

2 drawing

OpenGL requires that the command to specify the vertex must be included after the glBegin function and before the glEnd function (otherwise the specified vertex will be ignored).

When we call the glBegin function, we need to pass in a parameter to tell OpenGL what type of primitive we will draw.

2.1 points

glBegin(GL_POINTS);
glVertex2f(0.0f, 0.0f);
glVertex2f(0.5f, 0.0f);
glEnd();

2.2 line

glBegin(GL_LINES);
glVertex2f(0.0f, 0.0f);
glVertex2f(0.5f, 0.0f);
glEnd();

2.3 Triangle

glBegin(GL_TRIANGLES);
glVertex(1,0,1);
glVertex(0,1,0);
glVertex(1,1,0);
glEnd;

2.4 Square

glBegin(GL_QUADS);

glVertex3f(-1.0f, 1.0f, 0.0f);

glVertex3f( 1.0f, 1.0f, 0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glEnd();

Note:

1. Under normal circumstances, the front and back sides of polygons in OpenGL are determined by the order of the vertices of the drawn polygons, and the faces drawn counterclockwise are the front sides of the polygons. However, using glFrontFace function in OpenGL can customize the front of polygons. .

The function's parameter mode specifies the front direction. It can be CL_CCW and CL_CW, which specify the positive direction of the polygon counterclockwise and clockwise, respectively.

Void glFrontFace(GLenum mode);

2. OpenGL specifies that the segments in a polygon cannot intersect. There must be no void in the region. That is, the polygon must be a convex polygon (any two non-adjacent points of the polygon are within the interior of the polygon). It cannot be a concave polygon. Otherwise, it cannot. Accepted by OpenGL functions.

3. Color

3.1 color mode

OpenGL supports two color modes: one is RGBA, and the other is color index mode.

In RGBA mode, the data directly represents the color. In the color index mode, the data represents an index. To get the real color, you must also check the index table.
RGBA color
In the RGBA mode, each pixel holds the following data: R value (red component), G value (green component), B value (blue component), and A value (alpha component). The combination of red, green, and blue colors gives us all the colors we need, and alpha does not directly affect the color. It will be left for future introduction.

The glColor* series of functions can be used to set the color, where the three parameter versions can specify R, G, B values, and the A value is the default; the four parameter version can specify R, G, B, and A values, respectively. E.g:
Void glColor3f(GLfloat red, GLfloat green, GLfloat blue);
Void glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);

glColor3f(1.0f, 0.0f, 0.0f); means that green and blue are not used, and red is used the most, so that the purest red color is obtained.
glColor3f(0.0f, 1.0f, 1.0f); means to use green and blue to most, but not to use red. The effect of mixing is light blue.
glColor3f(0.5f, 0.5f, 0.5f); Indicates that all colors are used in half and the effect is gray.

3.2 coloring mode
OpenGl also provides two coloring modes: smooth and planar coloring

Flat coloring applies a fixed color to the entire primitive

Smooth coloring Blends the different colors of each vertex of a primitive to create a nice color blend.

glBegin(GL_TRIANGLES);

glColor3f(1.0f,0.0f,0.0f);
glVertex(1,0,1);

glColor3f(0.0f,1.0f,0.0f);

glVertex(0,1,0);

glColor3f(0.0f,0.0f,1.0f);
glVertex(1,1,0);
glEnd;

Thus, the three vertices of the triangle have different colors, and they are merged in the middle of the triangle.

Tetragonal plane coloring

glColor3f(0.5f,0.5f,1.0f);
glBegin(GL_QUADS);
glVertex3f(-1.0f, 1.0f, 0.0f);

glVertex3f( 1.0f, 1.0f, 0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glEnd();

Air Purifier

10K PCS Ready HOT OEM Ozone Generator in Car Air Purifier Mite Anti Virus Filter Sterilizer Disinfecting

Features:

O-zone & Anoin Two Mode --- This advanced air cleaner purifier with Anion and O-zone 2-in1 air sterili-zation mode to fresh air and kill harmful mold decompose smoke, odor and formaldehyde, Keep the air fresh!

Anoin Mode Powerful and Enviroment Friendly --- Releas 8million/cm3 Negtive Ion captures up the airborne particles(PM 2.5), pet odor, smoke, kill harmful mold and other harmful gases. No chemical composition and filter requied. Effectively improving the air quality and Prevent harmful substances inhaled into the lungs.

Car Air Purifier,Car Air Cleaner,Car Air Purifier Ionizer,Best Air Purifier For Car

Jiangmen soundrace electronics and technology co.,ltd. , https://www.soundracegroup.com

This entry was posted in on