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 char fragment_shader_texture[20000];
44 static float tex_coords[] = {
53 glUniform1f(uTime_location, t);
55 //glActiveTexture(GL_TEXTURE0);
56 //glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 320, 400, GL_RGB,
57 // GL_UNSIGNED_BYTE, image);
58 glUseProgram(bg_program.program);
59 u2gl_draw_textured_triangle_strip(&bg_program, bg_obj, 4);
63 static void init_texture()
67 u2gl_set_tex_coords(tex_coords);
69 glGenTextures(1, tex);
70 glActiveTexture(GL_TEXTURE0);
71 glBindTexture(GL_TEXTURE_2D, tex[0]);
72 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
73 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
74 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
75 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
77 image = calloc(3, 320 * 400);
79 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 320, 400, 0, GL_RGB,
80 GL_UNSIGNED_BYTE, image);
81 glGenerateMipmap(GL_TEXTURE_2D);
82 u2gl_check_error("init_texture 1");
86 extern int window_width;
87 extern int window_height;
97 in = fopen("plz.glsl", "r");
99 fread(fragment_shader_texture, 20000, 1, in);
103 v = u2gl_compile_vertex_shader(vertex_shader_texture);
104 f = u2gl_compile_fragment_shader(fragment_shader_texture);
105 u2gl_create_program(&bg_program, f, v);
106 u2gl_check_error("create program bg");
108 uRes_location = glGetUniformLocation(bg_program.program, "iResolution");
109 uTime_location = glGetUniformLocation(bg_program.program, "iGlobalTime");
110 u2gl_check_error("get uniform locations");
112 glUniform3f(uRes_location, (float)window_width, (float)window_height, 0.0f);
113 u2gl_check_error("set resolution");
115 glDisable(GL_DEPTH_TEST);
118 //glBlendFunc(GL_SRC_ALPHA, GL_ONE);
119 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
121 glClearColor(.0, .0, .0, 0);
122 u2gl_check_error("init_opengl");
125 //u2gl_check_error("init_texture");
127 u2gl_projection(0, view_width, 0, view_height, &bg_program);
134 glClear(GL_COLOR_BUFFER_BIT);