-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathtest.c
241 lines (201 loc) · 4.84 KB
/
test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
//Copyright (c) 2011-2020 <>< Charles Lohr - Under the MIT/x11 or NewBSD License you choose.
// NO WARRANTY! NO GUARANTEE OF SUPPORT! USE AT YOUR OWN RISK
// Super basic test - see rawdrawandroid's thing for a more reasonable test.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "os_generic.h"
#include <GLES3/gl3.h>
#include <asset_manager.h>
#include <asset_manager_jni.h>
#include <android_native_app_glue.h>
#include <android/log.h>
#include <android/sensor.h>
#include "CNFGAndroid.h"
#define CNFG3D
#define CNFG_IMPLEMENTATION
#include "CNFG.h"
unsigned frames = 0;
unsigned long iframeno = 0;
#define GENLINEWIDTH 89
#define GENLINES 67
int genlinelen = 0;
char genlog[(GENLINEWIDTH+1)*(GENLINES+1)+2] = "log";
int genloglen;
int genloglines;
int firstnewline = -1;
void example_log_function( int readSize, char * buf )
{
static og_mutex_t * mt;
if( !mt ) mt = OGCreateMutex();
OGLockMutex( mt );
int i;
for( i = 0; (readSize>=0)?(i <= readSize):buf[i]; i++ )
{
char c = buf[i];
if( c == '\0' ) c = '\n';
if( ( c != '\n' && genlinelen >= GENLINEWIDTH ) || c == '\n' )
{
int k;
genloglines++;
if( genloglines >= GENLINES )
{
genloglen -= firstnewline+1;
int offset = firstnewline;
firstnewline = -1;
for( k = 0; k < genloglen; k++ )
{
if( ( genlog[k] = genlog[k+offset+1] ) == '\n' && firstnewline < 0)
{
firstnewline = k;
}
}
genlog[k] = 0;
genloglines--;
}
genlinelen = 0;
if( c != '\n' )
{
genlog[genloglen+1] = 0;
genlog[genloglen++] = '\n';
}
if( firstnewline < 0 ) firstnewline = genloglen;
}
genlog[genloglen+1] = 0;
genlog[genloglen++] = c;
if( c != '\n' ) genlinelen++;
}
OGUnlockMutex( mt );
}
volatile int suspended;
short screenx, screeny;
int lastbuttonx = 0;
int lastbuttony = 0;
int lastmotionx = 0;
int lastmotiony = 0;
int lastbid = 0;
int lastmask = 0;
int lastkey, lastkeydown;
static int keyboard_up;
void HandleKey( int keycode, int bDown )
{
lastkey = keycode;
lastkeydown = bDown;
if( keycode == 4 ) { AndroidSendToBack( 1 ); }
}
void HandleButton( int x, int y, int button, int bDown )
{
lastbid = button;
lastbuttonx = x;
lastbuttony = y;
}
void HandleMotion( int x, int y, int mask )
{
lastmask = mask;
lastmotionx = x;
lastmotiony = y;
}
extern struct android_app * gapp;
void HandleDestroy()
{
}
void HandleSuspend()
{
suspended = 1;
}
void HandleResume()
{
suspended = 0;
}
int main()
{
int i, x, y;
double ThisTime;
double LastFPSTime = OGGetAbsoluteTime();
double LastFrameTime = OGGetAbsoluteTime();
double SecToWait;
int linesegs = 0;
CNFGBGColor = 0x400000ff;
CNFGSetupFullscreen( "Test Bench", 0 );
const char * assettext = "Not Found";
AAsset * file = AAssetManager_open( gapp->activity->assetManager, "test.txt", AASSET_MODE_BUFFER );
if( file )
{
size_t fileLength = AAsset_getLength(file);
char * temp = malloc( fileLength + 1);
memcpy( temp, AAsset_getBuffer( file ), fileLength );
temp[fileLength] = 0;
assettext = temp;
}
while(1)
{
int i, pos;
float f;
iframeno++;
RDPoint pto[3];
CNFGHandleInput();
if( suspended ) { usleep(50000); continue; }
CNFGClearFrame();
CNFGColor( 0xffffffff );
CNFGGetDimensions( &screenx, &screeny );
// Mesh in background
CNFGColor( 0xffffffff );
CNFGPenX = 20; CNFGPenY = 20;
CNFGDrawText( assettext, 10 );
CNFGFlushRender();
CNFGPenX = 0; CNFGPenY = 480;
char st[50];
sprintf( st, "%dx%d %d %d %d %d %d %d\n%d %d", screenx, screeny, lastbuttonx, lastbuttony, lastmotionx, lastmotiony, lastkey, lastkeydown, lastbid, lastmask );
CNFGDrawText( st, 10 );
glLineWidth( 2.0 );
// Square behind text
CNFGBGColor = 0x444444ff;
CNFGTackRectangle( 600, 0, 950, 350);
CNFGPenX = 10; CNFGPenY = 10;
// Text
pos = 0;
CNFGColor( 0xffffffff );
for( i = 0; i < 1; i++ )
{
int c;
char tw[2] = { 0, 0 };
for( c = 0; c < 256; c++ )
{
tw[0] = c;
CNFGPenX = ( c % 16 ) * 20+606;
CNFGPenY = ( c / 16 ) * 20+5;
CNFGDrawText( tw, 4 );
}
}
// Green triangles
CNFGPenX = 0;
CNFGPenY = 0;
for( i = 0; i < 400; i++ )
{
RDPoint pp[3];
CNFGColor( 0x00ff00ff );
pp[0].x = (short)(50*sin((float)(i+iframeno)*.01) + (i%20)*30);
pp[0].y = (short)(50*cos((float)(i+iframeno)*.01) + (i/20)*20);
pp[1].x = (short)(20*sin((float)(i+iframeno)*.01) + (i%20)*30);
pp[1].y = (short)(50*cos((float)(i+iframeno)*.01) + (i/20)*20);
pp[2].x = (short)(10*sin((float)(i+iframeno)*.01) + (i%20)*30);
pp[2].y = (short)(30*cos((float)(i+iframeno)*.01) + (i/20)*20);
CNFGTackPoly( pp, 3 );
}
CNFGPenX = 5;
CNFGPenY = 600;
CNFGDrawText( genlog, 4 );
frames++;
CNFGSwapBuffers();
ThisTime = OGGetAbsoluteTime();
if( ThisTime > LastFPSTime + 1 )
{
printf( "FPS: %d\n", frames );
frames = 0;
linesegs = 0;
LastFPSTime+=1;
}
}
return(0);
}