@@ -879,7 +879,7 @@ static void init(int argc, char *argv[])
879879 }
880880}
881881
882- static void drawBackground (const float width, const float height, const float x, const float y, const bool drawBorder)
882+ static void drawBackground (const float width, const float height, const float x, const float y, const bool drawBorder, const GLfloat p[ 16 ] )
883883{
884884 GLfloat vertices[4 ][2 ];
885885#if HAVE_GLES2
@@ -893,7 +893,7 @@ static void drawBackground(const float width, const float height, const float x,
893893 vertices[3 ][0 ] = x; vertices[3 ][1 ] = height + y;
894894
895895#if !HAVE_GLES2
896- glLoadIdentity ();
896+ glLoadIdentity (); // Reset to ortho origin. Assumes MODELVIEW mode.
897897 glDisable (GL_DEPTH_TEST);
898898 glDisable (GL_LIGHTING);
899899 glDisable (GL_TEXTURE_2D);
@@ -912,6 +912,8 @@ static void drawBackground(const float width, const float height, const float x,
912912 glDrawArrays (GL_LINE_LOOP, 0 , 4 );
913913 }
914914#else
915+ glUseProgram (program);
916+ glUniformMatrix4fv (uniforms[UNIFORM_MODELVIEW_PROJECTION_MATRIX], 1 , GL_FALSE, p);
915917 glStateCacheDisableDepthTest ();
916918 glStateCacheBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
917919 glStateCacheEnableBlend ();
@@ -930,15 +932,17 @@ static void drawBackground(const float width, const float height, const float x,
930932
931933// An animation while we're waiting.
932934// Designed to be drawn on background of at least 3xsquareSize wide and tall.
933- static void drawBusyIndicator (int positionX, int positionY, int squareSize, struct timeval *tp)
935+ static void drawBusyIndicator (int positionX, int positionY, int squareSize, struct timeval *tp, const GLfloat p[ 16 ] )
934936{
935- #if !HAVE_GLES2
936937 const GLfloat square_vertices [4 ][2 ] = { {0 .5f , 0 .5f }, {squareSize - 0 .5f , 0 .5f }, {squareSize - 0 .5f , squareSize - 0 .5f }, {0 .5f , squareSize - 0 .5f } };
937938 int i;
938939
939940 int hundredthSeconds = (int )tp->tv_usec / 1E4 ;
941+ int secDiv255 = (int )tp->tv_usec / 3921 ;
942+ int secMod6 = tp->tv_sec % 6 ;
940943
941944 // Set up drawing.
945+ #if !HAVE_GLES2
942946 glPushMatrix ();
943947 glLoadIdentity ();
944948 glDisable (GL_DEPTH_TEST);
@@ -950,14 +954,28 @@ static void drawBusyIndicator(int positionX, int positionY, int squareSize, stru
950954 glDisableClientState (GL_NORMAL_ARRAY);
951955 glClientActiveTexture (GL_TEXTURE0);
952956 glDisableClientState (GL_TEXTURE_COORD_ARRAY);
957+ #else
958+ GLfloat mvp[16 ];
959+ glStateCacheDisableDepthTest ();
960+ glStateCacheDisableBlend ();
961+ glVertexAttribPointer (ATTRIBUTE_VERTEX, 2 , GL_FLOAT, GL_FALSE, 0 , square_vertices);
962+ glEnableVertexAttribArray (ATTRIBUTE_VERTEX);
963+ #endif
953964
954965 for (i = 0 ; i < 4 ; i++) {
966+ float tx = (float )(positionX + ((i + 1 )/2 != 1 ? -squareSize : 0 .0f ));
967+ float ty = (float )(positionY + (i / 2 == 0 ? 0 .0f : -squareSize));
968+ #if !HAVE_GLES2
955969 glLoadIdentity ();
956- glTranslatef ((float )(positionX + ((i + 1 )/2 != 1 ? -squareSize : 0 .0f )), (float )(positionY + (i / 2 == 0 ? 0 .0f : -squareSize)), 0 .0f ); // Order: UL, UR, LR, LL.
970+ glTranslatef (tx, ty , 0 .0f ); // Order: UL, UR, LR, LL.
971+ #else
972+ mtxLoadMatrixf (mvp, p);
973+ mtxTranslatef (mvp, tx, ty, 0 .0f );
974+ glUseProgram (program);
975+ glUniformMatrix4fv (uniforms[UNIFORM_MODELVIEW_PROJECTION_MATRIX], 1 , GL_FALSE, mvp);
976+ #endif
957977 if (i == hundredthSeconds / 25 ) {
958978 unsigned char r, g, b;
959- int secDiv255 = (int )tp->tv_usec / 3921 ;
960- int secMod6 = tp->tv_sec % 6 ;
961979 if (secMod6 == 0 ) {
962980 r = 255 ; g = secDiv255; b = 0 ;
963981 } else if (secMod6 == 1 ) {
@@ -971,13 +989,24 @@ static void drawBusyIndicator(int positionX, int positionY, int squareSize, stru
971989 } else {
972990 r = 255 ; g = 0 ; b = secDiv255;
973991 }
992+ #if !HAVE_GLES2
974993 glColor4ub (r, g, b, 255 );
994+ #else
995+ const float color[4 ] = {(float )r/255 .0f , (float )g/255 .0f , (float )b/255 .0f , 1 .0f };
996+ glUniform4fv (uniforms[UNIFORM_COLOR], 1 , color);
997+ #endif
975998 glDrawArrays (GL_TRIANGLE_FAN, 0 , 4 );
976999 }
1000+ #if !HAVE_GLES2
9771001 glColor4ub (255 , 255 , 255 , 255 );
1002+ #else
1003+ const float colorWhite[4 ] = {1 .0f , 1 .0f , 1 .0f , 1 .0f };
1004+ glUniform4fv (uniforms[UNIFORM_COLOR], 1 , colorWhite);
1005+ #endif
9781006 glDrawArrays (GL_LINE_LOOP, 0 , 4 );
9791007 }
9801008
1009+ #if !HAVE_GLES2
9811010 glPopMatrix ();
9821011#endif // !HAVE_GLES2
9831012}
@@ -1136,20 +1165,26 @@ void drawView(void)
11361165 //
11371166 // Setup for drawing on top of video frame, in viewPort coordinates.
11381167 //
1139- #if 0
1140- glMatrixMode(GL_PROJECTION);
1141- glLoadIdentity();
1168+ #if 0 // NOT USED
11421169 bottom = 0.0f;
11431170 top = (float)(viewPort[viewPortIndexHeight]);
11441171 left = 0.0f;
11451172 right = (float)(viewPort[viewPortIndexWidth]);
1173+ # if !HAVE_GLES2
1174+ glMatrixMode(GL_PROJECTION);
1175+ glLoadIdentity();
11461176 glOrthof(left, right, bottom, top, -1.0f, 1.0f);
11471177 glMatrixMode(GL_MODELVIEW);
11481178 glLoadIdentity();
1149-
1179+ # else
1180+ mtxLoadIdentityf(p);
1181+ mtxOrthof(p, left, right, bottom, top, -1.0f, 1.0f);
1182+ glUseProgram(program);
1183+ glUniformMatrix4fv(uniforms[UNIFORM_MODELVIEW_PROJECTION_MATRIX], 1, GL_FALSE, p);
1184+ # endif
11501185 EdenGLFontSetViewSize(right, top);
11511186 EdenMessageSetViewSize(right, top, gDisplayDPI);
1152- #endif
1187+ #endif // 0
11531188
11541189 //
11551190 // Setup for drawing on screen, with correct orientation for user.
@@ -1161,12 +1196,11 @@ void drawView(void)
11611196 right = (float )contextWidth;
11621197 mtxLoadIdentityf (p);
11631198 mtxOrthof (p, left, right, bottom, top, -1 .0f , 1 .0f );
1164- mtxLoadIdentityf (m);
11651199#if !HAVE_GLES2
11661200 glMatrixMode (GL_PROJECTION);
11671201 glLoadMatrixf (p);
11681202 glMatrixMode (GL_MODELVIEW);
1169- glLoadMatrixf (m );
1203+ glLoadIdentity ( );
11701204#else
11711205 glUseProgram (program);
11721206 glUniformMatrix4fv (uniforms[UNIFORM_MODELVIEW_PROJECTION_MATRIX], 1 , GL_FALSE, p);
@@ -1179,7 +1213,7 @@ void drawView(void)
11791213
11801214 // Draw status bar with centred status message.
11811215 if (statusBarMessage[0 ]) {
1182- drawBackground (right, statusBarHeight, 0 .0f , 0 .0f , false );
1216+ drawBackground (right, statusBarHeight, 0 .0f , 0 .0f , false , p );
11831217 glDisable (GL_BLEND);
11841218 EdenGLFontDrawLine (0 , p, statusBarMessage, 0 .0f , 2 .0f , H_OFFSET_VIEW_CENTER_TO_TEXT_CENTER, V_OFFSET_VIEW_BOTTOM_TO_TEXT_BASELINE);
11851219 }
@@ -1196,8 +1230,8 @@ void drawView(void)
11961230 h = MAX (FONT_SIZE, 3 *squareSize) + 2 *4 .0f /* box margin */ ;
11971231 x = right - (w + 2 .0f );
11981232 y = statusBarHeight + 2 .0f ;
1199- drawBackground (w, h, x, y, true );
1200- if (status == 1 ) drawBusyIndicator ((int )(x + 4 .0f + 1 .5f *squareSize), (int )(y + 4 .0f + 1 .5f *squareSize), squareSize, &time);
1233+ drawBackground (w, h, x, y, true , p );
1234+ if (status == 1 ) drawBusyIndicator ((int )(x + 4 .0f + 1 .5f *squareSize), (int )(y + 4 .0f + 1 .5f *squareSize), squareSize, &time, p );
12011235 EdenGLFontDrawLine (0 , p, (unsigned char *)uploadStatus, x + 4 .0f + 3 *squareSize, y + (h - FONT_SIZE)/2 .0f , H_OFFSET_VIEW_LEFT_EDGE_TO_TEXT_LEFT_EDGE, V_OFFSET_VIEW_BOTTOM_TO_TEXT_BASELINE);
12021236 }
12031237 }
0 commit comments