10 static int view_height;
12 static struct u2gl_program bg_program;
23 static const char vertex_shader_texture[] =
24 "uniform mat4 pMatrix;\n"
25 "uniform mat4 uMatrix;\n"
26 "attribute vec4 aPosition;\n"
27 "varying vec3 vPosition;\n"
28 "attribute vec2 aTexPosition;\n"
29 "varying vec2 vTexPosition;\n"
32 " mat4 Matrix = pMatrix * uMatrix;\n"
33 " vec4 position = Matrix * aPosition;\n"
34 " gl_Position = position;\n"
35 " vTexPosition = aTexPosition;\n"
36 " vPosition = vec3(position);\n"
39 static const char fragment_shader_texture[] =
40 "precision mediump float;\n"
41 "uniform sampler2D uTexture;\n"
42 "uniform vec4 uColor;\n"
43 "varying vec3 vPosition;\n"
44 "varying vec2 vTexPosition;\n"
47 " gl_FragColor = texture2D(uTexture, vTexPosition);\n"
55 int uLensTex_location;
58 static float tex_coords[] = {
65 static float color[256][4];
72 void setrgb(int c, int r, int g, int b)
76 color[c][0] = (float)r / CC;
77 color[c][1] = (float)g / CC;
78 color[c][2] = (float)b / CC;
82 void getrgb(int c, char *p)
84 p[0] = color[c][0] * CC;
85 p[1] = color[c][1] * CC;
86 p[2] = color[c][2] * CC;
91 //glActiveTexture(GL_TEXTURE0);
92 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 320, 400, GL_RGB,
93 GL_UNSIGNED_BYTE, image);
94 glUseProgram(bg_program.program);
95 u2gl_draw_textured_triangle_strip(&bg_program, bg_obj, 4);
98 static void init_texture()
102 u2gl_set_tex_coords(tex_coords);
104 glGenTextures(1, tex);
105 glActiveTexture(GL_TEXTURE0);
106 glBindTexture(GL_TEXTURE_2D, tex[0]);
107 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
108 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
109 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
110 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
112 image = calloc(3, 320 * 400);
114 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 320, 400, 0, GL_RGB,
115 GL_UNSIGNED_BYTE, image);
116 glGenerateMipmap(GL_TEXTURE_2D);
117 u2gl_check_error("init_texture 1");
128 v = u2gl_compile_vertex_shader(vertex_shader_texture);
129 f = u2gl_compile_fragment_shader(fragment_shader_texture);
130 u2gl_create_program(&bg_program, f, v);
131 u2gl_check_error("create program bg");
133 glDisable(GL_DEPTH_TEST);
136 //glBlendFunc(GL_SRC_ALPHA, GL_ONE);
137 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
139 glClearColor(.0, .0, .0, 0);
140 u2gl_check_error("init_opengl");
143 u2gl_check_error("init_texture");
145 u2gl_projection(0, view_width, 0, view_height, &bg_program);
152 glClear(GL_COLOR_BUFFER_BIT);