Skip to content

Commit b1c8178

Browse files
committed
Fix Android layout. Add mobile rendering of activity indicator. Can build Android on mac/linux/win.
1 parent 323b574 commit b1c8178

File tree

4 files changed

+84
-44
lines changed

4 files changed

+84
-44
lines changed

Android/app/src/main/res/layout/cameracalibrationactivity.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<FrameLayout
2222
android:id="@+id/content"
2323
android:layout_width="match_parent"
24-
android:layout_height="wrap_content"
24+
android:layout_height="0dp"
2525
app:layout_constraintBottom_toTopOf="@+id/toolbar"
2626
app:layout_constraintTop_toBottomOf="@+id/appbar">
2727
</FrameLayout>

build.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,13 @@ if [ $BUILD_IOS ] ; then
192192
xcodebuild -target "artoolkitX Camera Calibration Utility" -configuration Release -destination generic/platform=iOS
193193
)
194194
fi
195-
# /BUILD_MACOS
195+
# /BUILD_IOS
196+
197+
if [ "$OS" = "Darwin" ] || [ "$OS" = "Linux" ] || [ "$OS" = "Windows" ] ; then
198+
# ======================================================================
199+
# Build platforms hosted by macOS/Linux/Windows
200+
# ======================================================================
201+
196202

197203
if [ $BUILD_ANDROID ] ; then
198204

@@ -211,12 +217,16 @@ if [ $BUILD_ANDROID ] ; then
211217
(cd "${OURDIR}/Android"
212218
echo "Building Android project"
213219
./gradlew assembleRelease
220+
if [[ ]] ; then
221+
zipalign -v -p 4 my-app-unsigned.apk my-app-unsigned-aligned.apk
222+
223+
fi
214224
)
215225
fi
216226
# /BUILD_ANDROID
217227

218228
fi
219-
# /Darwin
229+
# /Darwin/Linux/Windows
220230

221231
if [ "$OS" = "Linux" ] ; then
222232
# ======================================================================

calib_camera.cpp

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

iOS/ARViewController.mm

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -665,34 +665,31 @@ - (void) drawBackgroundWidth:(const float)width height:(const float)height x:(co
665665

666666
// An animation while we're waiting.
667667
// Designed to be drawn on background of at least 3xsquareSize wide and tall.
668-
- (void) drawBusyIndicatorPositionX:(int)positionX positionY:(int)positionY squareSize:(int)squareSize tp:(struct timeval *)tp
668+
- (void) drawBusyIndicatorPositionX:(int)positionX positionY:(int)positionY squareSize:(int)squareSize tp:(struct timeval *)tp projection:(GLfloat [16])p
669669
{
670-
#if 0
671670
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} };
672671
int i;
673672

674673
int hundredthSeconds = (int)tp->tv_usec / 1E4;
674+
int secDiv255 = (int)tp->tv_usec / 3921;
675+
int secMod6 = tp->tv_sec % 6;
675676

676677
// Set up drawing.
677-
glPushMatrix();
678-
glLoadIdentity();
679-
glDisable(GL_DEPTH_TEST);
680-
glDisable(GL_LIGHTING);
681-
glDisable(GL_TEXTURE_2D);
682-
glDisable(GL_BLEND);
683-
glVertexPointer(2, GL_FLOAT, 0, square_vertices);
684-
glEnableClientState(GL_VERTEX_ARRAY);
685-
glDisableClientState(GL_NORMAL_ARRAY);
686-
glClientActiveTexture(GL_TEXTURE0);
687-
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
678+
GLfloat mvp[16];
679+
glStateCacheDisableDepthTest();
680+
glStateCacheDisableBlend();
681+
glVertexAttribPointer(ATTRIBUTE_VERTEX, 2, GL_FLOAT, GL_FALSE, 0, square_vertices);
682+
glEnableVertexAttribArray(ATTRIBUTE_VERTEX);
688683

689684
for (i = 0; i < 4; i++) {
690-
glLoadIdentity();
691-
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.
685+
float tx = (float)(positionX + ((i + 1)/2 != 1 ? -squareSize : 0.0f));
686+
float ty = (float)(positionY + (i / 2 == 0 ? 0.0f : -squareSize));
687+
mtxLoadMatrixf(mvp, p);
688+
mtxTranslatef(mvp, tx, ty, 0.0f);
689+
glUseProgram(program);
690+
glUniformMatrix4fv(uniforms[UNIFORM_MODELVIEW_PROJECTION_MATRIX], 1, GL_FALSE, mvp);
692691
if (i == hundredthSeconds / 25) {
693-
char r, g, b;
694-
int secDiv255 = (int)tp->tv_usec / 3921;
695-
int secMod6 = tp->tv_sec % 6;
692+
unsigned char r, g, b;
696693
if (secMod6 == 0) {
697694
r = 255; g = secDiv255; b = 0;
698695
} else if (secMod6 == 1) {
@@ -706,15 +703,14 @@ - (void) drawBusyIndicatorPositionX:(int)positionX positionY:(int)positionY squa
706703
} else {
707704
r = 255; g = 0; b = secDiv255;
708705
}
709-
glColor4ub(r, g, b, 255);
706+
const float color[4] = {(float)r/255.0f, (float)g/255.0f, (float)b/255.0f, 1.0f};
707+
glUniform4fv(uniforms[UNIFORM_COLOR], 1, color);
710708
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
711709
}
712-
glColor4ub(255, 255, 255, 255);
710+
const float colorWhite[4] = {1.0f, 1.0f, 1.0f, 1.0f};
711+
glUniform4fv(uniforms[UNIFORM_COLOR], 1, colorWhite);
713712
glDrawArrays(GL_LINE_LOOP, 0, 4);
714713
}
715-
716-
glPopMatrix();
717-
#endif
718714
}
719715

720716
- (void)tearDownGL
@@ -1028,7 +1024,7 @@ - (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
10281024
x = right - (w + 2.0f);
10291025
y = statusBarHeight + 2.0f;
10301026
[self drawBackgroundWidth:w height:h x:x y:y border:true projection:p];
1031-
if (status == 1) [self drawBusyIndicatorPositionX:(int)(x + 4.0f + 1.5f*squareSize) positionY:(int)(y + 4.0f + 1.5f*squareSize) squareSize:squareSize tp:&time];
1027+
if (status == 1) [self drawBusyIndicatorPositionX:(int)(x + 4.0f + 1.5f*squareSize) positionY:(int)(y + 4.0f + 1.5f*squareSize) squareSize:squareSize tp:&time projection:p];
10321028
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);
10331029
}
10341030
}

0 commit comments

Comments
 (0)