davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: openvg (Paeryn, ajstarks)

Sun Jan 03, 2016 9:20 am

ok - that was what I misunderstood.
I understood:
#include shapes.h and it will include all the others by itself.


update:
now it compiles and runs fine again with my attached Arduino
(edit: FTM just by the terminal window though)!

thanks a lot! 8-)
Last edited by davenull on Sun Jan 03, 2016 4:41 pm, edited 1 time in total.
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: openvg (Paeryn, ajstarks)

Sun Jan 03, 2016 4:57 pm

hey,

I now started to rework the Terminal output for X Window but the X window does not appear - I have no clue what I am missing again...

the Terminal window just shows my debug output
Initializing...

but as I wrote, then no X window appears :(

what am I doing wrong again?

Code: Select all

/*     Tx master 
 *     Raspberry Pi 
 * 
 *     ver 0007.1      
 */
 
// (C) (HaWe) 2015

// Programming language: gcc  C/C++, Geany IDE
// protected under the friendly Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// http://creativecommons.org/licenses/by-nc-sa/3.0/
 


#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include <fcntl.h>
#include <string.h>
#include <sys/ioctl.h>
#include <stdint.h>
#include <time.h>
#include <sys/time.h>
#include <errno.h>
#include <pthread.h>

#include "VG/openvg.h"   
#include "VG/vgu.h"
#include "fontinfo.h"
#include "shapes.h"

#include <wiringPi.h>
#include <wiringSerial.h>

#define  byte  uint8_t

char   * uart  =  "/dev/ttyAMA0";
int    Serial1;

 

//=====================================================================================
// openvg 

int _scrwidth_, _scrheight_;

#define   cls()       Background(0, 0, 0);   

int      _fontsize_ = 10;

inline void lcdprintxy(float x, float y, char * buf) {
   Text(x, y, buf, MonoTypeface , _fontsize_);
}


void Initgraph() {
     initWindowSize(20,20,600,360);
     init(&_scrwidth_, &_scrheight_);  

     Start(_scrwidth_, _scrheight_);   // Start the picture
  
     cls();   
   
     Stroke(255, 255, 255, 1);  // Set these at the start, no need to   
     Fill(255,255,255, 1);      // keep calling them if colour hasn't changed

}



//=====================================================================================
// debug monitor

void displayvalues(int line, char * caption, uint8_t array[]) {
  int cnt;
  char sbuf[128];
 
  //sprintf(sbuf, "%s cks=%-4d", caption, array[1]);
  //lcdprintxy(0, line, sbuf);
  //printf(sbuf); printf("\n");
  for(cnt=0; cnt<8; ++cnt) {
    sprintf(sbuf, "%3d ", array[cnt]);      // print on TFT
    lcdprintxy(cnt*3*8, line+10, sbuf);
    //printf(sbuf);
  }   
  //printf("\n");
 
}

//=====================================================================================
//=====================================================================================
// serial com


const    uint8_t  MSGSIZE=32;
uint8_t  bsync=255;
uint8_t  sendbuf[MSGSIZE];
uint8_t  recvbuf[MSGSIZE];


uint8_t calcchecksum(uint8_t array[]) {
  int32_t  sum=0;
  for(int i=2; i<MSGSIZE; ++i) sum+=(array[i]);
  return (sum & 0x00ff);
}

bool checksumOK(uint8_t array[]){
return (calcchecksum(array)==array[1]);
}

// ================================================================
// addToBuffer and receive function courtesy of chucktodd

bool addToBuffer( uint8_t buf[], uint8_t *cnt, uint16_t timeout){
bool inSync = *cnt>0;
unsigned long start=millis();
while((*cnt<MSGSIZE)&&(millis()-start<timeout)){
  if( serialDataAvail( Serial1 ) ) { // grab new char, test for sync char, if so start adding to buffer
    buf[*cnt] = (uint8_t)serialGetchar( Serial1 );
    if(inSync) *cnt += 1;  // my origional *cnt++ was updating the pointer address, not
                           // the pointed to sendbuffer
    else{
     if(buf[*cnt]==0xFF){
       inSync = true;
       *cnt +=1;
       }
     }
    }
  }
return (*cnt==MSGSIZE);
}


//=====================================================================================

bool receive(uint8_t * buf, uint16_t timeout, uint8_t *cnt){ // by passing cnt in and out,
// i can timeout and still save a partial buffer, so a resync costs less (less data lost)

bool inSync=false;
unsigned long start=millis();
uint8_t * p;  // pointer into buf for reSync operation
bool done=false;

do{
  done = addToBuffer(buf,cnt,timeout); // if this return false, a timeout has occured, and the while will exit.
  if(done){                         // do checksumOK test of buffer;
    done=checksumOK(buf);
    if(!done){                      // checksumOK failed, scan buffer for next sync char
       p = (uint8_t*)memchr((buf+1),0xff,(MSGSIZE-1)); //forgot to skip the current sync at 0
       
       
       if(p){ // found next sync char, shift buffer content, refill buffer
         *cnt = MSGSIZE -(p-buf); // count of characters to salvage from this failure
         memcpy(buf,p,*cnt); //cnt is now where the next character from Serial is stored!
         }
       else *cnt=0; // whole buffer is garbage
       }
    }
   
  } while(!done&&(millis()-start<timeout));

return done; // if done then buf[] contains a sendbufid buffer, else a timeout occurred
}

//=====================================================================================


void loop()
{
  char     sbuf[128],  resOK;   
  static   uint8_t cnt=0;
  uint8_t  cbuf[MSGSIZE], chk;

 
  //   send to Rx slave Arduino
 
  //Serial.println();
  sendbuf[0]=bsync;
  sendbuf[1]=calcchecksum(sendbuf);
 
  for(uint8_t i=0; i<MSGSIZE; i++) {                     // better use write() ?
     serialPutchar( Serial1, sendbuf[i]);                // Send values to the Rx Arduino       
  }       
 
  displayvalues(20, "Transmitted...: ", sendbuf);
  //sprintf(sbuf, "%4d %4d", sendbuf[4], sendbuf[6]);
  lcdprintxy(0, 20, sbuf);
  //printf(sbuf); printf("\n");

 
  //     Receive from Rx slave Arduino

  memset(cbuf, 0, sizeof(cbuf));
   
  resOK = receive ( cbuf, 10000,&cnt);
 
  if( resOK ) {                         // byte 0 == syncbyte ?
    cnt=0;

    displayvalues(60, "Received...:", cbuf);
     chk=(byte)calcchecksum(cbuf);     
     memcpy(recvbuf, cbuf, sizeof(cbuf));
 
        // change values to send back!
        memcpy(sendbuf, recvbuf, sizeof(sendbuf));         // copy inbuf to outbuf
        sendbuf[4]+=1;                                     // change [4] to send back
    
  }
 
}


//=====================================================================================

 
int main() {
    unsigned long timesav;
    char  sbuf[128];
    char  instr[128];
     
    printf("initializing..."); printf("\n");
    Initgraph();
   
    // UART Serial com port
    Serial1 = serialOpen (uart, 115200); // for Arduino code compatibility reasons
   
    while(1) { loop(); } 
   
    serialClose( Serial1);
    
    End();
    finish();   
    exit(0);
}

//=====================================================================================
//=====================================================================================

#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

User avatar
Paeryn
Posts: 2702
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: openvg (Paeryn, ajstarks)

Sun Jan 03, 2016 7:31 pm

You've not got any X window code - I take it you mean the openvg window.

You've not got an End() call in the while loop (the one in main(), either there or at the end of the loop() function), you only ever call it right at the end, just before it gets closed. Until you call End() the openvg window won't be updated with what you drew to it.
She who travels light — forgot something.

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: openvg (Paeryn, ajstarks)

Sun Jan 03, 2016 7:44 pm

aah - not even an empty (black or either colored) window frame - that point I didn't recognize.
I'll try immediately :)
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: openvg (Paeryn, ajstarks)

Sun Jan 03, 2016 7:48 pm

aaaaahhhhhhh...

now something's happening :)

Thanks ! :)
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: openvg (Paeryn, ajstarks)

Sun Jan 03, 2016 8:01 pm

what's actually sort of strange:

when I'm writing different numbers to the same (x,y) position (for a quicly changing table chart) all numbers are written one over the other - so the old numbers are not cleared when writing new ones after that and so it makes everything unreadable.

But clearing the whole window by
Background(0,0,0); End();
for just 1 position or even a line makes this display function unreasonable slow - how can one enable "clear character at pos (x,y) before writing new"?
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

User avatar
Paeryn
Posts: 2702
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: openvg (Paeryn, ajstarks)

Sun Jan 03, 2016 9:02 pm

davenull wrote:what's actually sort of strange:

when I'm writing different numbers to the same (x,y) position (for a table chart) all numbers are written one over the other - so the old numbers are not cleared when writing new ones after that.

But clearing the whole window by
Background(0,0,0); End();
for just 1 position or even a line makes this display function unreasonable slow - how can one enable "clear character at pos (x,y) before writing new"?
Erm, yes - you need to clear the window for each new frame (or draw a background coloured box over where you want to overwrite), End() doesn't clear the buffer. You don't need to use Background() in my version each time, calling WindowClear() will clear it to whatever colour was last set by Background().

The way ajstarks set the library up to preserve the buffer after an End() can be slower than not preserving it, I assume he did it so that if you only need to update a small part of the window each frame then you don't have to re-draw everything. Usually the buffer isn't preserved (it's quicker to not preserve it) and you have to clear the window each time before use.

A usual loop would be something along the lines of (draw_everything could be part of do_calculations)

Code: Select all

  while (!finished) {
    WindowClear(); // Clear the window
    do_calculations(); // Do whatever (possibly including drawing to the window)
    draw_everything_else(); // Any other window drawing not done above
    End(); // Show the window
  }
Don't call Background() for each line or position you write - it clears the whole screen every time, and you don't need to call End() straight after it, only call End() when you want to see the result of all the drawing operations.
She who travels light — forgot something.

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: openvg (Paeryn, ajstarks)

Sun Jan 03, 2016 9:08 pm

ok, but that does not sound very optimistic though...
I'm now away from my Raspi but I will try tomorrow what happens if I 1st drew a line of blank space over the old one

Code: Select all

"                                                   "
(followed by an End()
and see if it will overwrite the existing chars...
then, 2nd, I could build up the related updated line anew :roll:
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

User avatar
Paeryn
Posts: 2702
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: openvg (Paeryn, ajstarks)

Mon Jan 04, 2016 12:21 am

davenull wrote:ok, but that does not sound very optimistic though...
I'm now away from my Raspi but I will try tomorrow what happens if I 1st drew a line of blank space over the old one

Code: Select all

"                                                   "
(followed by an End()
and see if it will overwrite the existing chars...
then, 2nd, I could build up the related updated line anew :roll:
Writing spaces won't have any effect because spaces don't draw anything. When you draw text the only part that gets drawn is the actual character, the background is left alone. If you want to clear just the rectangle where the text is written then you need to do something like :-

Change the Fill to the background colour,
If you previously set the stroke width to anything other than 0 then change the stroke width to 0 (you don't need an outline around the rectangle),
Draw a filled rectangle over the area where the text was,
Change Fill (and stroke width) back to what you want for drawing.

So in your displayvalues() function, to erase the area where the previous line was written you'd have something along the lines of

Code: Select all

void displayvalues(int line, char * caption, uint8_t array[]) {
  int cnt;
  char sbuf[128];

  // Erase the background where the text will go 
  Fill(0, 0, 0, 1);
  StrokeWidth(0);
  Rect(0, line+10, 8*3*8-1, line+23);
  Fill(255, 255, 255, 1);
  StrokeWidth(1);

  for(cnt=0; cnt<8; ++cnt) {
    sprintf(sbuf, "%3d ", array[cnt]);      // print on TFT
    lcdprintxy(cnt*3*8, line+10, sbuf);
  }   
}
The y-coordinates might not totally clear the text, I'm not sure how much vertical space the font takes, the library has a function for saying how wide the text will be but not how high, you might need to lower the first y-coord (if characters have descenders they may be drawn below - I'm not sure if the y-coord for text is the absolute bottom or the baseline) and/or raise the second (depending on how high the characters really are - I've assumed 14 pixels based on 8 wide). I'm assuming you know the characters are 8 pixels wide since that's how much space to seem to allocate when deciding where to print them.

And only use End() when you've finished drawing the whole window, not half way through. Calling it halfway through will slow your code down a lot as it waits for all current drawing to finish and updates the window.
She who travels light — forgot something.

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: openvg (Paeryn, ajstarks)

Mon Jan 04, 2016 9:21 am

wooooo ...that's hard stuff.....
then I wonder if it's not more handy to just clear the entire screen.... :(

would it be possible for you provide a new function clear_end_of_line cleol(), e.g.
void cleol(float x, float y, _fontsize_);

- or -
would be possible to provide a "actual new print text function" which erases the letters first which already have been written at that screen position before writing anew?
- or -
a print-blank-space function which just clears 1 letter like as it's common to text editors?
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

User avatar
Paeryn
Posts: 2702
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: openvg (Paeryn, ajstarks)

Mon Jan 04, 2016 2:57 pm

davenull wrote:wooooo ...that's hard stuff.....
then I wonder if it's not more handy to just clear the entire screen.... :(
It's not hard, it's just drawing a black rectangle over the largest possible area where your text was.
davenull wrote:would it be possible for you provide a new function clear_end_of_line cleol(), e.g.
void cleol(float x, float y, _fontsize_);
clear_end_of_line makes little sense, how do you consistently define "end of line"? A lot of the time you don't want end of line to mean the right side of the window, and if you use a proportional font then you can't use the number of characters as that depends on which characters. The only sensible thing is to have the user define the size of box to clear, so in addition to WindowClear(), you'd have say, AreaClear(x, y, w, h) to clear a rectangle or TextClear(x, y, w, Font) where it would work out the height of the rectangle from the used font, but you'd still have to give a width.
davenull wrote:- or -
would be possible to provide a "actual new print text function" which erases the letters first which already have been written at that screen position before writing anew?
And how would the library know what was on the screen at that point, any other drawing commands that crossed into that area would be affected. Plus there's the problem of anti-aliasing, just drawing over the same text in a different colour may leave a partial outline.
davenull wrote:- or -
a print-blank-space function which just clears 1 letter like as it's common to text editors?
Again, how wide is your space? A text editor would know exactly what the bounding box is, and is in a better position to handle the clearing than a general-purpose library.

The main function that the library doesn't provide which is one that says how high the largest character of a font is (which is why I guessed at 14 in the example). It does provide a function to tell you how wide the printed text will be.
She who travels light — forgot something.

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: openvg (Paeryn, ajstarks)

Mon Jan 04, 2016 4:19 pm

ok, I see - it's not as simple as I assumed it could be.
Neverless, cleol() could be from the current position to the right border of the window by the height of the currently used fontsize.
And, to be dogged, being able to write a "blank" space by writing (painting) a " " in the color of the background would be fine, too.

Sort of printblankxybobross(x,y, _fonttype_, _fontsize_) //painting a " " with beautiful background colors
in obfuscated C:
#define pbyxbr printblankxybobross
:mrgreen:
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

User avatar
Paeryn
Posts: 2702
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: openvg (Paeryn, ajstarks)

Mon Jan 04, 2016 5:46 pm

davenull wrote:ok, I see - it's not as simple as I assumed it could be.
Neverless, cleol() could be from the current position to the right border of the window by the height of the currently used fontsize.
But there is no concept of "current position", nor a concept of "current fontsize", the library doesn't keep track of what you used last because you could quite easily have used a different font or size in-between.
davenull wrote:And, to be dogged, being able to write a "blank" space by writing (painting) a " " in the color of the background would be fine, too.

Sort of printblankxybobross(x,y, _fonttype_, _fontsize_) //painting a " " with beautiful background colors
in obfuscated C:
#define pbyxbb printblankxybobross
:mrgreen:
Yes, but how wide? In non-proportional fonts (which are most common) a "space" is wider than an "i" but not as wide as an "m" so you need to know how wide to fill.
When I get around to it I'll probably put an area clear function in (basically the AreaClear() I mentioned earlier) because it at least saves having to alter the fill and stroke settings to do it, anything more is really too specialised and better handled by the user rather than the library. I'll try and have some way to query the vertical size of fonts as at the moment there's no way to calculate it within the program.
She who travels light — forgot something.

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: openvg (Paeryn, ajstarks)

Mon Jan 04, 2016 6:24 pm

I agree, for proportional fonts it's tricky, but for FixedFonts it's actually simple.
The issues about space are conspicuous when writing table charts, e.g.

printf(sbuf, "3 values:%10d %10.1f %-10.3f written", 12345, 9876.54, 5000.0);
printf(sbuf, "3 values:%10d %10.1f %-10.3f written", 12, 3.14, 2.718);
showing, shortly wrutten on after the other

Code: Select all

3 values:     12345    9876.5 5000.000      written 
3 values:        12       3.1 2.718         written
and you can imagine the mess you'll get if you do that repetively not clearing the screen at blank spaces and either chars.
That issue really should be fixed IMO, e.g. ALWAYS clearing spaces completely to the background before writing anew.
(no offence of course, and no nitpicking, I appreciate your input and efforts very much indeed!)
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

User avatar
Paeryn
Posts: 2702
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: openvg (Paeryn, ajstarks)

Mon Jan 04, 2016 7:50 pm

davenull wrote:I agree, for proportional fonts it's tricky, but for FixedFonts it's actually simple.
The issues about space are conspicuous when writing table charts, e.g.

printf(sbuf, "3 values:%10d %10.1f %-10.3f written", 12345, 9876.54, 5000.0);
printf(sbuf, "3 values:%10d %10.1f %-10.3f written", 12, 3.14, 2.718);
showing, shortly wrutten on after the other

Code: Select all

3 values:     12345    9876.5 5000.000      written 
3 values:        12       3.1 2.718         written
and you can imagine the mess you'll get if you do that repetively not clearing the screen at blank spaces and either chars.
That issue really should be fixed IMO, e.g. ALWAYS clearing spaces completely to the background before writing anew.
(no offence of course, and no nitpicking, I appreciate your input and efforts very much indeed!)
But if the library always cleared the background before drawing text, what happens when you want to write text over previous graphics - you don't want the background erased then, which is why it's the user's responsibility not the library's.
The library can't do one thing for fixed and another for proportional, it doesn't know if the font is designed as fixed-width - as far as it is concerned there is only proportional - fixed is just proportional where all characters just happen to be the same width.
She who travels light — forgot something.

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: openvg (Paeryn, ajstarks)

Mon Jan 04, 2016 7:53 pm

yes, for Graphics it's different -
what about making clearing optional?

BTW, for table charts Monospace is of course the 1st choice, or perhaps Courier, DejaVu, OCR-A/B, FixedSys, 7-segmentLED...

For proportional fonts it would fit to just clear the space of the new char which will be written.
Anyway, writing 1 word on top of the other would not make sense for either purpose if the 1st one had not been cleared before - elsewise you wouldn't recognize afterwards anything either way ;)
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

User avatar
Paeryn
Posts: 2702
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: openvg (Paeryn, ajstarks)

Mon Jan 04, 2016 8:49 pm

davenull wrote:yes, for Graphics it's different -
what about making clearing optional?

BTW, for table charts Monospace is of course the 1st choice, or perhaps Courier, DejaVu, OCR-A/B, FixedSys, 7-segmentLED...

For proportional fonts it would fit to just clear the space of the new char which will be written.
Anyway, writing 1 word on top of the other would not make sense for either purpose if the 1st one had not been cleared before - elsewise you wouldn't recognize afterwards anything either way ;)
I still hold to it being the user's responsibility to clear the area they want, they know how much space they want clearing. If you're writing text for a table you should already know how much space you've allocated for it.

The general case is that you clear the whole window and draw everything from scratch each frame. In cases where you don't, you should already know the size of area you need clearing. The only thing I think the library needs is being able to ask how high (and low) the requested font is likely to be (it already allows you to ask how wide), and possibly a dedicated clear area function for when users aren't clearing the whole window. OpenVG already supplies a function for clearing an area that you can use - vgClear(x, y, width, height) - it uses the colour set in Background() (from my fork only, not ajstark's original) but it works on absolute pixel locations, i.e. any scale/rotate transforms don't affect it (but usually that's the use case anyway). WindowClear() is basically a single line function that calls vgClear(0, 0, window_width, window_height);
She who travels light — forgot something.

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: openvg (Paeryn, ajstarks)

Mon Jan 04, 2016 8:59 pm

ok, I see, thanks for your input!

Interesting BTW that a fontsize of 10 is actually not exactly 10 pixels high - I actually assumed a Monospace 10 would be 10 px high :roll:
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

User avatar
Paeryn
Posts: 2702
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: openvg (Paeryn, ajstarks)

Mon Jan 04, 2016 9:52 pm

davenull wrote:ok, I see, thanks for your input!

Interesting BTW that a fontsize of 10 is actually not exactly 10 pixels high - I actually assumed a Monospace 10 would be 10 px high :roll:
Point size has little to do with actual pixel size. Traditionally a point is 1/72th of an inch so you'd need to know the physical pixel size to be able to convert from point to pixel.
In addition, not all fonts are designed the same, fonts are roughly designed around an em-square (a square whose sides are the size of a capital M) scaled up to the point size (so the width of a 12 point M should be roughly 12 points wide, or 1/6 of an inch wide) but it's up to the designer, they don't have to adhere to it. And nothing really says how high a font can be (I've seem some really tall thin ones). If you try it on a word processor you'll find different fonts are different sizes for the same point size.

Below is the letter H in 12 point Courier New, Times New Roman, Comic Sans and DeJa Vu Sans Mono (very common fonts) zoomed in with a pixel bar on the side so you can count how high each is. As you can see here Courier New is 9 pixels high, Times New Roman is 11 pixels high and Comic Sans and DeJa Vu are 12 pixels high.
H12pt.PNG
H 12pt
H12pt.PNG (3.39 KiB) Viewed 2751 times
She who travels light — forgot something.

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: openvg (Paeryn, ajstarks)

Mon Jan 04, 2016 9:56 pm

how easy life might have been if only people switched their brain on before doing anything - especially setting standards
:twisted:
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

User avatar
PeterO
Posts: 5070
Joined: Sun Jul 22, 2012 4:14 pm

Re: openvg (Paeryn, ajstarks)

Mon Jan 04, 2016 10:15 pm

davenull wrote:how easy life might have been if only people switched their brain on before doing anything - especially setting standards
:twisted:
Are you really that clueless ?
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
ajstarks
Posts: 129
Joined: Fri Jun 22, 2012 2:14 am

Re: openvg (Paeryn, ajstarks)

Wed Jan 06, 2016 11:42 pm

davenull wrote:what's actually sort of strange:

when I'm writing different numbers to the same (x,y) position (for a quicly changing table chart) all numbers are written one over the other - so the old numbers are not cleared when writing new ones after that and so it makes everything unreadable.

But clearing the whole window by
Background(0,0,0); End();
for just 1 position or even a line makes this display function unreasonable slow - how can one enable "clear character at pos (x,y) before writing new"?
Note that you can use the ClipRect and ClipEnd functions to limit drawing to a specific region. See: https://github.com/ajstarks/openvg/blob ... ent/clip.c for an example

User avatar
Paeryn
Posts: 2702
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: openvg (Paeryn, ajstarks)

Wed Jan 06, 2016 11:52 pm

Temporary update:

I've added colour name defines, all colours names are prefixed with SH_ (so hopefully doesn't interfere with anything else) so red is SH_red. They are simple defines of the rgb triplets so you can use them in the Fill and Stroke etc.

Code: Select all

  // Old RGB triple way
  Fill(255, 255, 255, 1);
  // New name way
  Fill(SH_white, 1);
Also new functions :-
AreaClear(x, y, w, h); does what it says on the tin - clears an area of the screen to whatever the background colour was set to.
TextHeight(font, size); tells you how high above the baseline the highest character in the given font at the given point size will be.
TextDepth(font, size); tells you how low below the baseline the lowest character in the given font at the given point size will be.

Remember, when fonts are drawn, the Y value says where the baseline is - characters like 'g' have tails that are drawn below that point, that it why there's the TextDepth function. The total height of a font is therefore TextHeight() + TextDepth().

Due to the way I find out the size (I altered the font2openvg program to export two more variables in the .inc files) and not wanting to alter ajstarks' function calls, if you load your own fonts at the moment the font heights aren't set (they will both report 0), adding 2 lines after your own loadfont() call can set it, though I will probably change things when I add dynamic loading of fonts. The 3 built-in fonts have the height info set correctly.

Example from how DejaVuSans is loaded...

Code: Select all

  DejaVuSans = loadfont(DejaVuSans_glyphPoints, ...);
  // Need to add these next two lines for TextHeight and TextDepth to work properly
  DejaVuSans.descender_height = DejaVuSans_descender_height;
  DejaVuSans.font_height = DejaVuSans_font_height;
I modified the hellovg file in client/hellovg.c to show the new functions working.

If you want to download this update, it's the fonts branch of my git fork https://github.com/paeryn/openvg.git, so if you've got git set up properly you should be able to checkout, or clone it

Code: Select all

git clone https://github.com/paeryn/openvg.git -b fonts
or download the zip https://github.com/paeryn/openvg/archive/fonts.zip

Bedtime now...
She who travels light — forgot something.

User avatar
Paeryn
Posts: 2702
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: openvg (Paeryn, ajstarks)

Thu Jan 07, 2016 12:40 am

ajstarks wrote:
davenull wrote:what's actually sort of strange:

when I'm writing different numbers to the same (x,y) position (for a quicly changing table chart) all numbers are written one over the other - so the old numbers are not cleared when writing new ones after that and so it makes everything unreadable.

But clearing the whole window by
Background(0,0,0); End();
for just 1 position or even a line makes this display function unreasonable slow - how can one enable "clear character at pos (x,y) before writing new"?
Note that you can use the ClipRect and ClipEnd functions to limit drawing to a specific region. See: https://github.com/ajstarks/openvg/blob ... ent/clip.c for an example
Setting clip rects is a bit overkill if you're just using it for clearing an area to the background colour though, especially when there's a specific function designed for doing just that.
She who travels light — forgot something.

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: openvg (Paeryn, ajstarks)

Thu Jan 07, 2016 8:24 am

thank you very much, Paeryn!
I'll try to see through all of the new features later this day and try to figure out all the details! 8-)

About the line claering: from the 1st view
AreaClear(x, y, w, h);
over 1 complete line
AreaClear(0, yline, screenwidth, _fontwidth_*1.2); // factor 1.2-1.4 out of experience
is what I intended to do currently so far

after
git clone https://github.com/paeryn/openvg.git -b fonts
do I have to use again
make
make install
make library

and then the #includes
#include "VG/openvg.h"
#include "VG/vgu.h"
#include "fontinfo.h"
#include "shapes.h"

will remain the same?


BTW:
usually coordinates on screens (especially for writing text) are starting by 0,0 from upper left corner.
That makes sense if one wants to write several lines one beyong the next like in an normal text or in an Excel chart table.

Do you provide such a "mirrored" coordinate system as well ?
Currently I'm writing instead of
Text(x,y,...)
Text(x, screenHeight-y,...)
which admittedly muddles up the coding quite a degree... ;)
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

Return to “Graphics, sound and multimedia”