[OpenGL]Computer Graphics-3D_room


On the structure of the senior project, I have a preliminary understanding of some functions in OpenGL.

Init()

glEnable()

GL_DEPTH_TEST

Open depth test

GL_COLOR_MATERIAL

After executing it, the figure (material) will reflect according to the light shining

GL_NORMALIZE

According to the setting conditions of the function glNormal, enable the normal vector

GL_LIGHTING

Enable light source

GL_LIGHT0

Enable light 0

glClear()

GL_DEPTH_BUFFER_BIT

Clear the depth buffer

GL_COLOR_BUFFER_BIT

Clear the current writable color buffer

Reshape()

glViewport(GLint x,GLint y,GLsizei width,GLsizei height)

x, y are in pixels and specify the position of the lower left corner of the viewport. width, height represents the width and height of the viewport rectangle, and the window is redrawn according to the real-time changes of the window.

glMatrixMode()

GL_MODELVIEW

For the operation of the model view, the following statement describes a model
view transformation gluLookAt(GLdouble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx, GLdouble centery, GLdouble centerz, GLdouble upx, GLdouble upy, GLdouble upz)
This function defines a view Matrix, and multiply with the current matrix

  • eyex, eyey, eyez The position of the camera in the world coordinate system;
  • centerx, centery, centerz The position of the object pointed by the camera lens in world coordinates;
  • upx, upy, upz The upward direction of the camera in the world coordinate system;
    the position of the camera can be determined

GL_PROJECTION

Just like taking a picture, project a 3-dimensional object onto a 2-dimensional plane, and then you can use glFrustum() or gluPerspective() to
transform gluPerspective (GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar)

  • fovy: the angle of the field of view in the YZ plane, the range is [0.0, 180.0];
  • aspect: the ratio of the width to the height of the projection plane;
  • Near: The distance from the near clipping plane to the viewpoint
  • Far: the distance from the far clipping plane to the viewpoint

Display()

light

glLightfv()

  • GL_AMBIENT: ambient light component;
  • GL_DIFFUSE: diffuse reflection light component;
  • GL_SPECULAR: Concentrating component;
  • GL_POSITION: position The
    last parameter w: 0 -> directional source, otherwise it is a positional source;
  • GL_SPOT_DIRECTION: irradiation direction, the default direction (0, 0, 1);
  • GL_SPOT_EXPONENT: light distribution, the range is [0, 128], the larger the value, the more concentrated, when set to 0, it is equivalent to uniform distribution;
  • GL_SPOT_CUTOFF: the angle range of light irradiation, the value range is [0, 90] or 180;

Reflective

glMaterialfv(GL_FRONT,GL_DIFFUSE,@Diffuse)

  1. Decide whether the material is applied to the front or back of the primitive:
  • GL_FRONT front
  • GL_BACK reverse
  • GL_FRONT_AND_BACK front and back
  1. Indicates what kind of light is set:
  • GL_DIFFUSE diffused light, with directivity, comes from a specific direction, it is evenly reflected on the surface according to the angle of the incident light;
  • GL_AMBIENT ambient light does not come from any specific direction, it will reflect everywhere;
  • GL_AMBIENT_AND_DIFFUSE Ambient light and diffuse light
  • GL_SPECULAR Parallel/specular light, with strong directivity, but its reflection angle is very sharp, only reflecting in a specific direction;
  • GL_EMISSION The light emitted outward, weaker
  1. The RGB value of reflectivity, each value is between 0 and 1;

Translation, rotation

glTranslatef

Ordinary drawing

glBegin(GLenum mode)

  • GL_POINTS: each vertex as a point;
  • GL_LINES: each vertex as an independent line segment;
  • GL_LINE_STRIP: A group of line segments are connected in sequence without forming a ring;
  • GL_LINE_LOOP: A group of line segments are connected in sequence to form a loop;
  • GL_TRIANGLES: form triangles in sequence, not connected;
  • GL_TRIANGLE_STPIP: form triangles in sequence and connect;
  • GL_QUADS: form quadrilaterals in sequence, not connected;
  • GL_QUAD_STRIP: form quadrilaterals in sequence and connect;
  • GL_POLYGON: draw convex polygon;

Guess you like

Origin blog.csdn.net/weixin_44092088/article/details/110749686
Recommended