4 * OpenGL video rendering
15 #include <GLES/glext.h>
18 static uint8_t *pixbuf = NULL;
19 static GLuint texture;
21 static long otick = 0;
25 int tex_width, tex_height;
26 GLint crop[4] = { VIDEO_WIDTH, 0, -VIDEO_WIDTH, VIDEO_HEIGHT };
28 INFO("initializing OpenGL video rendering...\n");
30 // FIXME: this should be computed (smallest power of 2 > dimension)
36 pixbuf = malloc(tex_width * tex_height * 2);
38 memcpy(pixbuf, default_image, VIDEO_WIDTH*VIDEO_HEIGHT*2);
41 glEnable(GL_TEXTURE_2D);
42 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
43 glDeleteTextures(1, &texture);
44 glGenTextures(1, &texture);
45 glBindTexture(GL_TEXTURE_2D, texture);
46 // Call glTexImage2D only once, and use glTexSubImage2D later
47 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex_width, tex_height, 0, GL_RGB,
48 GL_UNSIGNED_SHORT_5_6_5, pixbuf);
49 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
50 // use NEAREST instead of LINEAR for faster (but uglier) results
51 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
52 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
53 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
54 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
55 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
58 glDisable(GL_DEPTH_TEST);
59 glDepthMask(GL_FALSE);
60 glDisable(GL_CULL_FACE);
61 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
62 glShadeModel(GL_FLAT);
63 glClear(GL_COLOR_BUFFER_BIT);
66 // Called from the app framework.
69 INFO("terminating OpenGL video rendering...\n");
70 //glDeleteTextures(1, &texture);
77 void video_render(long tick, int width, int height)
81 glBindTexture(GL_TEXTURE_2D, texture);
83 if (num_picture_decoded != num) {
84 /* a new frame is available, update texture */
85 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, VIDEO_WIDTH,VIDEO_HEIGHT,
86 GL_RGB, GL_UNSIGNED_SHORT_5_6_5, picture_buf);
87 num = num_picture_decoded;
89 /* and draw it on the screen */
90 glDrawTexiOES(0, 0, 0, width, height);