Skip to content

Commit ae74790

Browse files
committed
Fix GL matrix handling.
1 parent 65d297b commit ae74790

File tree

1 file changed

+15
-23
lines changed

1 file changed

+15
-23
lines changed

calib_camera.cpp

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -876,9 +876,7 @@ static void drawBusyIndicator(int positionX, int positionY, int squareSize, stru
876876

877877
void drawView(void)
878878
{
879-
#if HAVE_GLES2
880879
GLfloat p[16], m[16];
881-
#endif // !HAVE_GLES2
882880
int i;
883881
struct timeval time;
884882
float left, right, bottom, top;
@@ -920,14 +918,8 @@ void drawView(void)
920918
//
921919
// Setup for drawing on top of video frame, in video pixel coordinates.
922920
//
923-
#if !HAVE_GLES2
924-
glMatrixMode(GL_PROJECTION);
925-
glLoadIdentity();
926-
if (vv->rotate90()) glRotatef(90.0f, 0.0f, 0.0f, -1.0f);
927-
#else
928921
mtxLoadIdentityf(p);
929922
if (vv->rotate90()) mtxRotatef(p, 90.0f, 0.0f, 0.0f, -1.0f);
930-
#endif // !HAVE_GLES2
931923
if (vv->flipV()) {
932924
bottom = (float)vs->getVideoHeight();
933925
top = 0.0f;
@@ -942,18 +934,19 @@ void drawView(void)
942934
left = 0.0f;
943935
right = (float)vs->getVideoWidth();
944936
}
937+
mtxOrthof(p, left, right, bottom, top, -1.0f, 1.0f);
938+
mtxLoadIdentityf(m);
945939
#if !HAVE_GLES2
946-
glOrtho(left, right, bottom, top, -1.0f, 1.0f);
940+
glMatrixMode(GL_PROJECTION);
941+
glLoadMatrixf(p);
947942
glMatrixMode(GL_MODELVIEW);
948-
glLoadIdentity();
943+
glLoadMatrixf(m);
949944
glDisable(GL_DEPTH_TEST);
950945
glDisable(GL_LIGHTING);
951946
glDisable(GL_BLEND);
952947
glActiveTexture(GL_TEXTURE0);
953948
glDisable(GL_TEXTURE_2D);
954949
#else
955-
mtxOrthof(p, left, right, bottom, top, -1.0f, 1.0f);
956-
mtxLoadIdentityf(m);
957950
glStateCacheDisableDepthTest();
958951
glStateCacheDisableBlend();
959952
#endif // !HAVE_GLES2
@@ -983,20 +976,20 @@ void drawView(void)
983976
unsigned char buf[12]; // 10 digits in INT32_MAX, plus sign, plus null.
984977
sprintf((char *)buf, "%d\n", i);
985978

979+
GLfloat mvp[16];
986980
#if !HAVE_GLES2
987981
glPushMatrix();
988982
glLoadIdentity();
989983
glTranslatef(corners[i].x, vs->getVideoHeight() - corners[i].y, 0.0f);
990984
glRotatef((float)(gDisplayOrientation - 1) * -90.0f, 0.0f, 0.0f, 1.0f); // Orient the text to the user.
991985
#else
992-
GLfloat mvp[16];
993986
mtxLoadMatrixf(mvp, p);
994987
mtxMultMatrixf(mvp, m);
995988
mtxTranslatef(mvp, corners[i].x, vs->getVideoHeight() - corners[i].y, 0.0f);
996989
mtxRotatef(mvp, (float)(gDisplayOrientation - 1) * -90.0f, 0.0f, 0.0f, 1.0f); // Orient the text to the user.
997990

998991
#endif // !HAVE_GLES2
999-
EdenGLFontDrawLine(0, NULL, buf, 0.0f, 0.0f, H_OFFSET_VIEW_LEFT_EDGE_TO_TEXT_LEFT_EDGE, V_OFFSET_VIEW_BOTTOM_TO_TEXT_BASELINE); // These alignment modes don't require setting of EdenGLFontSetViewSize().
992+
EdenGLFontDrawLine(0, mvp, buf, 0.0f, 0.0f, H_OFFSET_VIEW_LEFT_EDGE_TO_TEXT_LEFT_EDGE, V_OFFSET_VIEW_BOTTOM_TO_TEXT_BASELINE); // These alignment modes don't require setting of EdenGLFontSetViewSize().
1000993
#if !HAVE_GLES2
1001994
glPopMatrix();
1002995
#endif // !HAVE_GLES2
@@ -1058,16 +1051,15 @@ void drawView(void)
10581051
top = (float)contextHeight;
10591052
left = 0.0f;
10601053
right = (float)contextWidth;
1054+
mtxLoadIdentityf(p);
1055+
mtxOrthof(p, left, right, bottom, top, -1.0f, 1.0f);
1056+
mtxLoadIdentityf(m);
10611057
#if !HAVE_GLES2
10621058
glMatrixMode(GL_PROJECTION);
1063-
glLoadIdentity();
1064-
glOrtho(left, right, bottom, top, -1.0f, 1.0f);
1059+
glLoadMatrixf(p);
10651060
glMatrixMode(GL_MODELVIEW);
1066-
glLoadIdentity();
1061+
glLoadMatrixf(m);
10671062
#else
1068-
mtxLoadIdentityf(p);
1069-
mtxOrthof(p, left, right, bottom, top, -1.0f, 1.0f);
1070-
mtxLoadIdentityf(m);
10711063
glUseProgram(program);
10721064
glUniformMatrix4fv(uniforms[UNIFORM_MODELVIEW_PROJECTION_MATRIX], 1, GL_FALSE, p);
10731065
#endif // !HAVE_GLES2
@@ -1081,7 +1073,7 @@ void drawView(void)
10811073
if (statusBarMessage[0]) {
10821074
drawBackground(right, statusBarHeight, 0.0f, 0.0f, false);
10831075
glDisable(GL_BLEND);
1084-
EdenGLFontDrawLine(0, NULL, statusBarMessage, 0.0f, 2.0f, H_OFFSET_VIEW_CENTER_TO_TEXT_CENTER, V_OFFSET_VIEW_BOTTOM_TO_TEXT_BASELINE);
1076+
EdenGLFontDrawLine(0, p, statusBarMessage, 0.0f, 2.0f, H_OFFSET_VIEW_CENTER_TO_TEXT_CENTER, V_OFFSET_VIEW_BOTTOM_TO_TEXT_BASELINE);
10851077
}
10861078

10871079
// If background tasks are proceeding, draw a status box.
@@ -1098,12 +1090,12 @@ void drawView(void)
10981090
y = statusBarHeight + 2.0f;
10991091
drawBackground(w, h, x, y, true);
11001092
if (status == 1) drawBusyIndicator((int)(x + 4.0f + 1.5f*squareSize), (int)(y + 4.0f + 1.5f*squareSize), squareSize, &time);
1101-
EdenGLFontDrawLine(0, NULL, (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);
1093+
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);
11021094
}
11031095
}
11041096

11051097
// If a message should be onscreen, draw it.
1106-
if (gEdenMessageDrawRequired) EdenMessageDraw(0, NULL);
1098+
if (gEdenMessageDrawRequired) EdenMessageDraw(0, p);
11071099

11081100
SDL_GL_SwapWindow(gSDLWindow);
11091101
}

0 commit comments

Comments
 (0)