OpenGl ES 绘制一个动态时钟
试着自己用OpenGl ES 画了一个时钟,指针是可以运动的,如下图所示。(画的比较简陋,但是具备基本功能)欢迎补充和讨论~~
这是静态效果图,实际指针是可以动起来的
下面是完整代码.
#include "esUtil.h"
#include <math.h>
#define PI 3.1415926
typedef struct
{
// Handle to a program object
GLuint programObject;
GLuint programObject2;
// GLuint programObject3;
} UserData;
///
// Create a shader object, load the shader source, and
// compile the shader.
//
GLuint LoadShader ( GLenum type, const char *shaderSrc )
{
GLuint shader; // GLuint is typedefed as unsigned int
GLint compiled; // GLint is typedefed as int
// Create the shader object
shader = glCreateShader ( type )
glShaderSource ( shader, 1, &shaderSrc, NULL );// Load the shader source
glCompileShader ( shader );// Compile the shader
glGetShaderiv ( shader, GL_COMPILE_STATUS, &compiled ); // Check the compile status
return shader;
}
///
// Initialize the shader and program object
//
int Init ( ESContext *esContext )
{
UserData *userData = esContext->userData;
char vShaderStr[] = //顶点着色器
"#version 300 es \n" //声明着色器版本
"layout(location = 0) in vec4 vPosition; \n" //输入一个属性数组
"void main() \n"
"{ \n"
" gl_Position = vPosition; \n" //将属性数组拷贝到gl_Position的特殊输出变量中