是每个OpenGL显示设备都支持的一个指定像素格式的表示结构。这个结构包含26个属性信息。
typedef struct tagPIXELFORMATDESCRIPTOR
{
WORD nSize;
WORD nVersion;
DWORD dwFlags;
BYTE iPixelType;
BYTE cColorBits;
BYTE cRedBits;
BYTE cRedShift;
BYTE cGreenBits;
BYTE cGreenShift;
BYTE cBlueBits;
BYTE cBlueShift;
BYTE cAlphaBits;
BYTE cAlphaShift;
BYTE cAccumBits;
BYTE cAccumRedBits;
BYTE cAccumGreenBits;
BYTE cAccumBlueBits;
BYTE cAccumAlphaBits;
BYTE cDepthBits;
BYTE cStencilBits;
BYTE cAuxBuffers;
BYTE iLayerType;
BYTE bReserved;
DWORD dwLayerMask;
DWORD dwVisibleMask;
DWORD dwDamageMask;
} PIXELFORMATDESCRIPTOR;
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
1,
PFD_DRAW_TO_WINDOW | // support window
PFD_SUPPORT_OPENGL | // support OpenGL
PFD_DOUBLEBUFFER, // double buffered
PFD_TYPE_RGBA, // RGBA type
24, // 24-bit color depth
0, 0, 0, 0, 0, 0, // color bits ignored
0, // no alpha buffer
0, // shift bit ignored
0, // no accumulation buff
0, 0, 0, 0, // accum bits ignored
32, // 32-bit z-buffer
0, // no stencil buffer
0, // no auxiliary buffer
PFD_MAIN_PLANE, // main layer
0, // reserved
0, 0, 0 // layer masks ignored
};
2. glViewport (GLint x, GLint y, GLsizei width, GLsizei height),指定视口,详情见图。
3. glTranslatef(glTranslated)是三维世界中,viewer的视野控制(注意,如果图形超过视野的时候,会导致过界的部分被切除)。在glLoadIdentity调用后,如果没有移动原点,坐标原点在屏幕正中心。glTranslatef每次移动的时候的原点是上一次移动后的坐标原点。或者说,glTranslatef 移动后的中心就是新的坐标原点。
e.g.
gltranslatef( 3.0f, 2.0f, -6.0f ); //right 3.0, up 2.0, and into screen 6.0 units.
gltranslatef( 2.0f, -1.0f, 3.0f ); //right 2.0, down 1.0, and out to screen 3.0 units. 当前原点距离屏幕中心为 right 5, up 1 and into screen 3 units.
4. gluPerspective 是在建立3D视角(注意,这个视角的关于Y方向的)。OpenGL 的 3D世界是固定的,但是计算机不可能把整个3D世界保存记录下来,因此需要我们确定一个3D视角,用以观察里面内容。下图可以比较直观地显示这个视角信息。
void gluPerspective(GLdouble fovy, //Specifies the field of view angle, in degrees, in the y direction.
GLdouble aspect, //Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height).
GLdouble zNear, //Specifies the distance from the viewer to the near clipping plane (always positive).
GLdouble zFar) //Specifies the distance from the viewer to the far clipping plane (always positive).
//this is the first triangle and quid for me by learning openGL.
glTranslatef(0.0f,0.0f,-6.0f);
glPointSize(4.0);
glBegin(GL_POINTS);
{
glColor3f( 1, 1, 1 );
glVertex3i( 0, 0, 0 );
}
glEnd();
glTranslatef(-1.5f,0.0f,0.0f);
glBegin(GL_TRIANGLES);
{
glColor3f( 0, 1, 0 );
glVertex2i( 0, 0 );
glColor3f( 1, 0, 0 );
glVertex2i( 0, 1 );
glColor3f( 0, 0, 1 );
glVertex2i( 1, 1 );
}
glEnd();
glTranslatef(3.0f,0.0f,0.0f);
glBegin(GL_QUADS);
{
glColor3f( 0, 1, 0 );
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();