본문 바로가기
Computer Vision

OpenGL 공부

by wisejlog 2022. 12. 27.

나중에 실 사용을 위해서 적어둔 글입니다.

 

 

Two matrix modes usually used

 

Conversion

1. GL_MODELVIEW (default) - Camera Matrix (Extrinsic)

It is a combination of view conversion and model conversion. 

View Conversion

used by (gluLookAt)

 

gluLookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ)

# eyeX, eyeY, eyeZ : viewer
# centerX, centerY, centeZ : where viewer looking at
# upX, upY, upZ : camera coordinate  (0,1,0) usually used

 

 

 

Model Conversion

- If you use glTranslate several times -> translation will be accumulated without any initialization.

- You should use glLoadIdentity here. (or glPushMatrix - glPopMatrix)

 

- About order of conversion (last -> first)

glRotate work based on 0,0,0

 

 

2. GL_PROJECTION

3D to 2D

- View volume and clipping 

- It is dependent on window size -> so should register glutReshapeFunction

 

Projection

1. Orthographic

glOrtho(left, right, bottom, top, nearVal, farVal)

 

2. Perspective

gluFrustum(left, right, bottom top, nearVal, farVal)

nearVal and farVal is distance from viewpoint -> should positive value

 

 

 

https://www.glprogramming.com/red/chapter03.html

 

 

gluPerspective(fovy, aspect, zNear, zFar)

 

https://www.glprogramming.com/red/chapter03.html

 

 

 

3. ViewPort Translation 

projected image to window (like instrinsic matrix) 

 

glViewport (x, y, width, height)

 

 

raster conversion (change float value to int pixel value) 

 

 

Light

Ambient (주변광), Diffuse(분산광), Specular(반사광) 

1. To use light effect

glEnable(GL_LIGHTING)

 

In opengl, usually support maximum 8 lights. 

glLight(light_numb, pname, param)
# pname : GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, GL_POSITION, \
# GL_SPOT_DIRECTION, GL_SPOPT_EXPONENT, GL_SPOT_CUTOFF, GL_CONSTANT_ATTENUATION, GL_LINEAR_ATTENUATION, GL_QUADRATIC_ATTENUATION)

 

 

2. Set Normal Vector 

glNormal3fv(normal vector)

 

'Computer Vision' 카테고리의 다른 글

[Python] Triangle Mesh to Pointcloud  (0) 2023.09.09
BVH File Format  (0) 2022.08.12