原文:http://blog.csdn.net/yu0089/article/details/18600903
前面我们对使用Android OpenGL ES 2.0绘图做过综述。对于刚刚接触到OpenGL的人来说,纹理和贴图往往令其感动很头疼。在解开这些谜团之前,我们先来了解一下绘制图形的基础--坐标系。
1坐标系分类
在使用OpenGL的场景中,存在世界坐标、局部坐标、纹理坐标和屏幕坐标几种。1.1OpenGL坐标系

1.2屏幕坐标系

1.3纹理坐标系

1.4坐标系组合

2顶点
2.1顶点坐标
那么什么是顶点呢?就是一个有xyz坐标的点。如(0,0,0)或(1,1,1)。XY就和通常的二维坐标一样定位平面的位置。Z轴表示的是深度,OpenGL就是为了绘制3D图形而诞生的。顶点坐标是做了归一化处理的float类型。那么这里就会涉及到屏幕坐标系到OpenGL坐标系的转化工作。
2.2转化方法
/**
* Convert x to openGL
*
* @param x
* Screen x offset top left
* @return Screen x offset top left in OpenGL
*/
public static float toGLX(float x) {
return -1.0f * ratio + toGLWidth(x);
}
/**
* Convert y to openGL y
*
* @param y
* Screen y offset top left
* @return Screen y offset top left in OpenGL
*/
public static float toGLY(float y) {
return 1.0f - toGLHeight(y);
}
/**
* Convert width to openGL width
*
* @param width
* @return Width in openGL
*/
public static float toGLWidth(float width) {
return 2.0f * (width / screenWidth) * ratio;
}
/**
* Convert height to openGL height
*
* @param height
* @return Height in openGL
*/
public static float toGLHeight(float height) {
return 2.0f * (height / screenHeight);
}
/**
* Convert x to screen x
*
* @param glX
* openGL x
* @return screen x
*/
public static float toScreenX(float glX) {
return toScreenWidth(glX - (-1 * ratio));
}
/**
* Convert y to screent y
*
* @param glY
* openGL y
* @return screen y
*/
public static float toScreenY(float glY) {
return toScreenHeight(1.0f - glY);
}
/**
* Convert glWidth to screen width
*
* @param glWidth
* @return Width in screen
*/
public static float toScreenWidth(float glWidth) {
return (glWidth * screenWidth) / (2.0f * ratio);
}
/**
* Convert height to screen height
*
* @param glHeight
* @return Height in screen
*/
public static float toScreenHeight(float glHeight) {
return (glHeight * screenHeight) / 2.0f;
}