Skip to content

Commit

Permalink
merge changes from Paeryn (see issue #41)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajstarks committed Jan 8, 2016
1 parent c4faace commit d0e60d3
Show file tree
Hide file tree
Showing 8 changed files with 467 additions and 60 deletions.
5 changes: 4 additions & 1 deletion client/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
INCLUDEFLAGS=-I/opt/vc/include -I/opt/vc/include/interface/vmcs_host/linux -I/opt/vc/include/interface/vcos/pthreads -I..
LIBFLAGS=-L/opt/vc/lib -lGLESv2 -lEGL -lbcm_host -lpthread -ljpeg

all: shapedemo hellovg mouse-hellovg particles screensize
all: shapedemo hellovg mouse-hellovg particles screensize clip

shapedemo: shapedemo.c ../libshapes.o ../oglinit.o
gcc -Wall $(INCLUDEFLAGS) $(LIBFLAGS) -o shapedemo shapedemo.c ../libshapes.o ../oglinit.o
Expand All @@ -24,5 +24,8 @@ particles: particles.c ../libshapes.o ../oglinit.o
screensize: screensize.c ../libshapes.o ../oglinit.o
gcc -Wall $(INCLUDEFLAGS) -o screensize screensize.c ../libshapes.o ../oglinit.o $(LIBFLAGS)

clip: clip.c ../libshapes.o ../oglinit.o
gcc -Wall $(INCLUDEFLAGS) -o clip clip.c ../libshapes.o ../oglinit.o $(LIBFLAGS)

indent:
indent -linux -c 60 -brf -l 132 shapedemo.c hellovg.c mouse-hellovg.c particles.c screensize.c
33 changes: 18 additions & 15 deletions client/clip.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,45 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <time.h>
#include "VG/openvg.h"
#include "VG/vgu.h"
#include "shapes.h"

int main(int argc, char **argv) {
int w, h, fontsize;
VGint x, cx, cy, cw, ch, midy, speed;
int main() {
int w, h, cx, cy, cw, ch, midy, fontsize;
char *message = "Now is the time for all good men to come to the aid of the party";
char done[3];
char s[3];

init(&w, &h);
speed = 15;
midy = (VGfloat) h / 2;
float speed, x, rx, ry, rw, rh;
speed = 15.0;
x = 0;
midy = (h / 2);
fontsize = w / 50;
cx = 0.0;
cx = 0;
ch = fontsize * 2;
cw = w;
cy = midy - (ch / 2);

rx = (float)cx;
ry = (float)cy;
rw = (float)cw;
rh = (float)ch;

// scroll the text, only in the clipping rectangle
for (x = 0; x < cw+speed; x += speed) {
for (x = 0.0; x < rw+speed; x += speed) {
Start(w, h);
Background(255, 255, 255);
Fill(0,0,0,.2);
Rect(cx, cy, cw, ch);
Fill(0, 0, 0, .2);
Rect(rx, ry, rw, rh);
ClipRect(cx, cy, cw, ch);
Translate(x, cy + (fontsize / 2));
Translate(x, ry+(fontsize/2));
Fill(0, 0, 0, 1);
Text(0, 0, message, SansTypeface, fontsize);
ClipEnd();
End();
}
fgets(done, 2, stdin); // press [Return] when done
fgets(s, 2, stdin);
finish();
exit(0);
}
13 changes: 12 additions & 1 deletion eglstate.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
typedef struct {
// Screen dimentions
uint32_t screen_width;
uint32_t screen_height;
// OpenGL|ES objects
// Window dimentions
int32_t window_x;
int32_t window_y;
uint32_t window_width;
uint32_t window_height;
// dispman window
DISPMANX_ELEMENT_HANDLE_T element;

// EGL data
EGLDisplay display;

EGLSurface surface;
EGLContext context;
} STATE_T;

extern void oglinit(STATE_T *);
extern void dispmanMoveWindow(STATE_T *, int, int);
extern void dispmanChangeWindowOpacity(STATE_T *, unsigned int);
2 changes: 2 additions & 0 deletions fontinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ extern "C" {
const short *CharacterMap;
const int *GlyphAdvances;
int Count;
int descender_height;
int font_height;
VGPath Glyphs[500];
} Fontinfo;

Expand Down
27 changes: 21 additions & 6 deletions fontutil/font2openvg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include FT_OUTLINE_H

#define OUTPUT_INTS

#define NGLYPHS 500
class Vector2
{
public:
Expand Down Expand Up @@ -109,9 +109,12 @@ int main (int argc, char * const argv[])
std::vector<float> gbbox;
std::vector<float> advances;

unsigned int characterMap[256];
float global_miny = 1000000.0f;
float global_maxy = -10000000.0f;

unsigned int characterMap[NGLYPHS];
int glyphs = 0;
for(int cc=0;cc<256;cc++)
for(int cc=0;cc<NGLYPHS;cc++)
{
characterMap[cc] = 0xffffffffu; //initially nonexistent

Expand Down Expand Up @@ -224,6 +227,13 @@ int main (int argc, char * const argv[])
gbbox.push_back( maxy );
advances.push_back(advance);

if (miny < global_miny) {
global_miny = miny;
}
if (maxy > global_maxy) {
global_maxy = maxy;
}

int size;
size = gpvec.size();
gpvec.resize( size + pvec.size() );
Expand Down Expand Up @@ -320,6 +330,9 @@ int main (int argc, char * const argv[])
}
fprintf (f,"};\n\n");
*/
//print minimum and maximum y values over the whole font
fprintf (f,"static const int %s_descender_height = %d;\n",argv[3],(int)(65536.0f*global_miny));
fprintf (f,"static const int %s_font_height = %d;\n",argv[3],(int)(65536.0f*global_maxy));
#else
//print points
fprintf (f,"static const float %s_glyphPoints[%d*2] = {", argv[3],gpvec.size());
Expand Down Expand Up @@ -352,17 +365,19 @@ int main (int argc, char * const argv[])
}
fprintf (f,"};\n\n");
*/
fprintf (f,"static const float %s_descender_height = %d;\n",argv[3],global_miny));
fprintf (f,"static const float %s_font_height = %d;\n",argv[3],global_maxy));
#endif


//print the number of glyphs and the character map
fprintf (f,"static const int %s_glyphCount = %d;\n",argv[3],glyphs);
fprintf (f,"static const short %s_characterMap[256] = {", argv[3]);
for(int i=0;i<256;i++)
fprintf (f,"static const short %s_characterMap[500] = {", argv[3]);
for(int i=0;i<NGLYPHS;i++)
{
if ((i % 20)==0)
fprintf (f,"\n ");
fprintf (f,"%d%c",characterMap[i],(i==(256-1))?' ':',');
fprintf (f,"%d%c",characterMap[i],(i==(NGLYPHS-1))?' ':',');
}
fprintf (f,"};\n\n");
fclose(f);
Expand Down
Loading

0 comments on commit d0e60d3

Please sign in to comment.