OpenGL API simple summary

  • first edition 2018-8-28

OpenGL API

Drawing Primitives

  • glBegin(Glenum mode)
    • mode: GL_TRIANGLES, GL_QUADS, etc
  • glVertex3f(GLfloat x,GLfloat y,GLfloat z)
    • Draw one vertex; must be after glBegin();
  • glEnd()
    • End of a group of primitives
  • glColor3f(GLbyte red, GLbyte blue,GLbyte green)
    • Set the color for vertices drawn after the call
  • glNormal3f(GLfloat nx,GL float ny, GLfloat nz)
    • Set the normal vector
  • glTexCoord2f(GLfloat s,GLfloat v)
    • Set the texture coordinates
  • glMatrixMode(GLenum mode)
    • Set the current matrix
    • mode: GL_MODELVIEW, GL_PROJECTION
  • glLoadIdentity()
    • Loads the identity matrix into the current matrix
  • glLoadMatrixf(Glfloat *matrix)
    • Load and arbitrary matrix
    • matrix: An array of values in column-major form; elements from same column are contiguous
  • glGetFloatv(GL_MODELVIEW_MATRIX,matrix)
  • glGetFloatv(GL_PROJECTION_MATRIX,matrix)
    • Gets a matrix- use sparingly

Transformations

  • glFrustum(GLfloat left,GLfloat right,GLfloat bottom,GLfloat top,GLfloat near,GLfloat far)
    • Multiplies the current matrix by a perspective matrix
    • Parameters set up a viewing frustum( clipped pyramid ) representing the visible space
  • glOrtho(Glfloat left,Glfloat right,GLfloat bottom,GLfloat top,GLfloat near,Glfloat far)
    • Similar to glFrustum(), but sets up an orthographic projection instead

Matrix Stack

  • glPushMatix()
    • Pushes a copy of the current matrix down on the matrix stack
    • There is one matrix stack per mode; GL_PROJECTION and GL_MODEVIEW each have their own stack
  • glPopMatrix()
    • Replaces the current matrix with the top of the stack, and then pops the stack

Lighting

  • glEnable(GL_LIGHTING)
    • Enable lighting
  • glEnable(GL_LIGHTX)
    • Enable lightX
  • glLightfv(GL_LIGHo,GL_AMBIENT,GLfloat *params)
  • glLightfv(GL_LIGHo,GL_SPECULAR,GLfloat *params)
  • glLightfv(GL_LIGHo,GL_DIFFUSE,GLfloat *params)
    • sets the ambient,diffuse,specular light for the light #o
    • params: 4-vector:[red,green,blue,alpha]
  • glLightfv(GL_LIGHTo,GL_POSITION,GLfloat *params)
    • Set the light position or direction
    • params: 4-vector:[x,y,z,point?]; if last argument is non-zero the light is a point light.
  • glMaterialfv(GL_FRONT,GL_AMBIENT,GLfloat *params)
  • glMaterialfv(GL_FRONT,GL_SPECULAR,GLfloat *params)
  • glMaterialfv(GL_FRONT,GL_DIFFUSE,GLfloat *params)
    • sets the ambient, diffuse, and specular material colors
    • params: 4-vector: [red,blue,green,alpha]
  • glMaterialf(GL_FRONT,GL_SHININESS,Glfloat params)
    • sets the hardness/shininess(size of specular highlights)
    • param: shininess in the range[0,128]

Other

  • glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
    • Must call at the beginning of each frame
  • glEnable(GL_DEPTH_TEST)
    • Enable depth-testing using depth buffer
  • These functions let you draw from arrays, rather than using glColor,glVertex,etc.
    • glEnableClientState(GL_VERTEX_ARRAY)
    • glEnableClientState(GL_NORMAL_ARRAY)
    • glEnableClientState(GL_COLOR_ARRAY)
    • glVertexPointer()
    • glNormalPoint();
    • glColorPointer();
    • glDrawArrays();
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值