|
Post by alexfish on Jan 29, 2016 18:02:27 GMT 1
Hi All For those with a Raspberry PI 2 , BaCon EGL canvas (Beta Testing), this will form the base for an EGL GL canvas There are for archives , download and extract into one folder , the file to Convert is Test_SDC.bac Requirement GTK2 libs dev , also check the VC folder in the /opt/ . should see /opt/vc from the File Manager the test program , as some know the EGL frame buffer has no means to be resized or moved this lib resolves those bits via a gtk window , all positioning an clipping happens relative to where and size of the gtk window this also resolves the issue of print though to the desk top area when using the Alpha Channel . the test program next post Update as dated @ Edit reasons Added Font see below .. also method to free the contexts , call with See Text Examples next Post:: BR Alex
|
|
|
Post by alexfish on Jan 29, 2016 18:03:42 GMT 1
Added Font libs. Edit >> now updated the myfont.bac as FUNCTION , returns width of text line .. see example 3 , as a button with text. Required myfont.h and myfont.bac Example of usage , INCLUDE SDC.bac INCLUDE myfont.bac
' *********************************************************** SUB QUIT() DeInit() PRINT "BYE" SLEEP 500 END END SUB
' *********************************************************** win = WINDOW("Text-Demo",600,400)
CALLBACK(win,"delete_event",QUIT)
CLS(win) ORTHO INK(255,0,0,255) TEXT("This is a line of text",100,100) ' All done : Swap Buffers SYNC
REM loop for ever static draw , on static drawing must use loop with a call to DoEvents WHILE 1 DO REM must call DOEVENTS within main loop DOEVENTS WEND
version , keep all bits together , + ROTATED text INCLUDE SDC.bac INCLUDE myfont.bac
' *********************************************************** SUB QUIT() DeInit() PRINT "BYE" SLEEP 500 END END SUB
' *********************************************************** win = WINDOW("Text-Demo",600,400)
CALLBACK(win,"delete_event",QUIT)
WHILE 1 DO CLS(win) ORTHO INK(255,0,0,255) ROTATE(20,0,0,1) TEXT("This is a line of text",150,50) ' All done : Swap Buffers SYNC WEND
Did a render test of 10 lines of text containing 50 chars. 500 chars , Frame rate still averages 50 frames a second Example 3 . using the udated myfont.bac , render a button with text , the TEXT returns width of text line. INCLUDE SDC.bac INCLUDE myfont.bac
' *********************************************************** SUB QUIT() DeInit() PRINT "BYE" SLEEP 500 END END SUB
' ***********************************************************
LOCAL text_width TYPE float
win = WINDOW("Text-Demo",600,400) CALLBACK(win,"delete_event",QUIT)
text_width=TEXT("Button_1",10,50) WHILE 1 DO CLS(win) ORTHO TRANSLATE((text_width/2)-4,50,0) INK(255,100,0,200) Gbutton((text_width/2)+2,25,1)
ORTHO INK(255,0,0,200) text_width=TEXT("Button_1",10,50)
' All done : Swap Buffers SYNC WEND
' ***********************************************************
Alex Attachments:myfont.h.bz2 (2.83 KB)
myfont.bac.bz2 (543 B)
|
|
|
Post by vovchik on Jan 29, 2016 23:38:17 GMT 1
Dear Alex, I am PI-less at the moment, so I can't test, but the code looks fine very unbloated. I hope we get some feedback from some PI users soon. With kind regards, vovchik
|
|
|
Post by alexfish on Jan 30, 2016 15:52:16 GMT 1
Hi Vovchik
Plenty of time , now going through some bits. all in the main , Just pleased to get EGL to use glColor and not have to use or program the shaders ..
but as can be see by the data , everything is a Cube and everything is a Triangle , but should be able to replicate in the likes of glut
So how in EGL and a 3d World can we draw a line or a square .
Here using the triangular vertexes ,
first code draws a square as in a line square IE not filled
/* Draw a Square 20 units back 20 units right of center */ WHILE 1 DO DoEvents() ALIGN() glLoadIdentity(); /* move back to see results */ glTranslatef(0.0, 0.f,-20);
glColor4ub(255,0,0,190)
glEnableClientState( GL_VERTEX_ARRAY );
glClear ( GL_COLOR_BUFFER_BIT );
glTranslatef(0.0, 0.f,-80); glTranslatef(20.00, 0.f,0.0); glVertexAttribPointer ( 0, 2, GL_FLOAT, GL_FALSE,0,vVertices )
glEnableVertexAttribArray ( 0 ) glDrawArrays (GL_LINES, 0, 2 )
glRotatef(90,0,0,1) glDrawArrays (GL_LINES, 0, 2 )
glRotatef(90,0,0,1) glDrawArrays (GL_LINES, 0, 2 )
glRotatef(90,0,0,1) glDrawArrays (GL_LINES, 0, 2 ) eglSwapBuffers(Display, Surface) WEND
here draw a filled Square
WHILE 1 DO DoEvents() ALIGN() glLoadIdentity(); glTranslatef(0.0, 0.f,-20); glColor4ub(255,0,0,190)
glEnableClientState( GL_VERTEX_ARRAY ); glClear ( GL_COLOR_BUFFER_BIT );
glTranslatef(0.0, 0.f,-80); glTranslatef(20.80, 0.f,0.0); glVertexAttribPointer ( 0, 3, GL_FLOAT, GL_FALSE,0,vVertices ) glEnableVertexAttribArray ( 0 ) glDrawArrays (GL_TRIANGLES, 0, 3 ) glRotatef(180,0,0,1) glDrawArrays (GL_TRIANGLES, 0, 3 ) eglSwapBuffers(Display, Surface)
WEND
BR Alex
|
|
|
Post by vovchik on Jan 30, 2016 16:23:48 GMT 1
Dear Alex, Thanks...I will study the code. If you have time, have a look at my SVG/TTF button demo. It crashes after a few mouse clicks and I cannot figure out why. You are good at finding all sorts of bugs. http://basic-converter.proboards.com/attachment/download/1505 With kind regards, vovchik
|
|
|
Post by alexfish on Jan 30, 2016 16:31:39 GMT 1
Dear Alex, Thanks...I will study the code. If you have time, have a look at my SVG/TTF button demo. It crashes after a few mouse clicks and I cannot figure out why. You are good at finding all sorts of bugs. http://basic-converter.proboards.com/attachment/download/1505 With kind regards, vovchik Hi Vovchik have not downloaded the demo , yet can see what the problem is , will look at it , then post back BR Alex
|
|
|
Post by alexfish on Jan 30, 2016 16:53:53 GMT 1
Now , what about rotation using 2d
here we go , use same draw routine to init , then here is the WHILE LOOP also combined the two code bits as above, solid sq and a line sq.
LOCAL t TYPE float=0
WHILE 1 DO DoEvents() ALIGN() glLoadIdentity(); glTranslatef(0.0, 0.f,-100);
glColor4ub(255,0,0,190)
glEnableClientState( GL_VERTEX_ARRAY );
glClear ( GL_COLOR_BUFFER_BIT ); glVertexAttribPointer ( 0, 3, GL_FLOAT, GL_FALSE,0,vVertices ) glEnableVertexAttribArray ( 0 ) glDrawArrays (GL_TRIANGLES, 0, 3 ) glRotatef(180,0,0,1) glDrawArrays (GL_TRIANGLES, 0, 3 )
/* rotate sq in 2d coords */ glLoadIdentity();
glTranslatef(0.0, 0.f,-100);
glColor4ub(0,255,0,190)
glEnableClientState( GL_VERTEX_ARRAY );
glTranslatef(30.00, 0.f,0.0);
glRotatef(t,0,0,1) glVertexAttribPointer ( 0, 2, GL_FLOAT, GL_FALSE,0,vVertices )
glEnableVertexAttribArray ( 0 ) glDrawArrays (GL_LINES, 0, 2 )
glRotatef(90,0,0,1) glDrawArrays (GL_LINES, 0, 2 )
glRotatef(90,0,0,1) glDrawArrays (GL_LINES, 0, 2 )
glRotatef(90,0,0,1) glDrawArrays (GL_LINES, 0, 2 ) eglSwapBuffers(Display, Surface) INCR t
WEND
|
|
|
Post by vovchik on Jan 30, 2016 17:27:58 GMT 1
Dear Alex, I commented out all the TTEXT calls in the SVG/TTF button demo, and it does not crash. So, you have a hunch about where the problem is. With kind regards, vovchik
|
|
|
Post by alexfish on Jan 31, 2016 13:49:47 GMT 1
Here , have update the draw function to re-calc the fustrum
this keeps eveyrthing in perspective , can now Resize or Max the window at will .
the bit
/* CALCULATE THE FUSTRUM*/ glGetIntegerv(GL_VIEWPORT, viewport) hht = nearp * (float)tan(45.0 / 2.0 / 180.0 * M_PI); hwd = hht * (float)viewport[2] / (float)viewport[3]; glFrustumf(-hwd, hwd, -hht, hht, nearp, farp);
/***************************************************/
now the draw code // can now place the bits x & y relative and draw in 2d + Rotate , here is Rotating solid square + wire square
SUB draw_square() ESContext esContext; esInitContext ( &esContext ); esCreateWindow ( &esContext, 600, 400,ES_WINDOW_RGB )
glEnable(GL_BLEND) glEnable(GL_CULL_FACE) glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glVertexPointer( 3, GL_BYTE, 0, quadx );
glMatrixMode(GL_PROJECTION)
glLoadIdentity();
glClearColor(1.0f, 1.0f, 1.0f, 0.0f)
GLfloat vVertices[] = { 0.0f, 0.5f, 0.0f, \ -0.5f, -0.5f, 0.0f, \ 0.5f, -0.5f, 0.0f };
glMatrixMode(GL_MODELVIEW);
ALIGN()
/* BeginMode GL_POINTS GL_LINES GL_LINE_LOOP GL_LINE_STRIP GL_TRIANGLES GL_TRIANGLE_STRIP GL_TRIANGLE_FAN
*/ LOCAL nearp = 1.0f TYPE float LOCAL farp = 500.0f TYPE float LOCAL hht = 1.0f TYPE float LOCAL hwd = 1.0f TYPE float LOCAL viewport[4] TYPE int LOCAL t =0 TYPE float
WHILE 1 DO DoEvents() ALIGN()
/* CALCULATE THE FUSTRUM*/ glGetIntegerv(GL_VIEWPORT, viewport) hht = nearp * (float)tan(45.0 / 2.0 / 180.0 * M_PI); hwd = hht * (float)viewport[2] / (float)viewport[3]; /***************************************************/ glFrustumf(-hwd, hwd, -hht, hht, nearp, farp); ' ******************************************************* glLoadIdentity(); glFrustumf(-hwd, hwd, -hht, hht, nearp, farp);
/* move back to see results */ glTranslatef(0.0, 0.f,-100); glRotatef(-t,0,0,1) glColor4ub(255,0,0,255)
glEnableClientState( GL_VERTEX_ARRAY );
glClear ( GL_COLOR_BUFFER_BIT ); glVertexAttribPointer ( 0, 3, GL_FLOAT, GL_FALSE,0,vVertices ) glEnableVertexAttribArray ( 0 ) glDrawArrays (GL_TRIANGLES, 0, 3 ) glRotatef(-180,0,0,1) glDrawArrays (GL_TRIANGLES, 0, 3 )
glLoadIdentity(); glFrustumf(-hwd, hwd, -hht, hht, nearp, farp);
glTranslatef(0.0, 0.f,-100);
glColor4ub(0,255,0,255)
glEnableClientState( GL_VERTEX_ARRAY );
glTranslatef(28.30, 0.f,0.0);
glRotatef(t,0,0,1) glVertexAttribPointer ( 0, 2, GL_FLOAT, GL_FALSE,0,vVertices )
glEnableVertexAttribArray ( 0 ) glDrawArrays (GL_LINES, 0, 2 )
glRotatef(90,0,0,1) glDrawArrays (GL_LINES, 0, 2 )
glRotatef(90,0,0,1) glDrawArrays (GL_LINES, 0, 2 )
glRotatef(90,0,0,1) glDrawArrays (GL_LINES, 0, 2 ) eglSwapBuffers(Display, Surface) INCR t , 2
WEND
END SUB BR Alex
|
|
|
Post by alexfish on Jan 31, 2016 15:09:21 GMT 1
Do the bits stay together
here replace the while loop with the below
here placing the solid Square and wire Square on x & y + rotating one on Y+Z & one on the X+Z , all bits connect and the solid square will cull when behind 'the scene'
BR Alex
WHILE 1 DO DoEvents() ALIGN()
/* CALCULATE THE FUSTRUM*/ glGetIntegerv(GL_VIEWPORT, viewport) hht = nearp * (float)tan(45.0 / 2.0 / 180.0 * M_PI) hwd = hht * (float)viewport[2] / (float)viewport[3] glLineWidth(1) glFrustumf(-hwd, hwd, -hht, hht, nearp, farp);
glLoadIdentity(); glFrustumf(-hwd, hwd, -hht, hht, nearp, farp);
/* move back to see results */ glTranslatef(-20.0,-15.0,-75); glRotatef(-t,0,0,1) glRotatef(t/2,0,1,0) glColor4ub(255,0,0,255)
glEnableClientState( GL_VERTEX_ARRAY ); glLineWidth(3) glClear ( GL_COLOR_BUFFER_BIT ); glVertexAttribPointer ( 0, 3, GL_FLOAT, GL_FALSE,0,vVertices ) glEnableVertexAttribArray ( 0 ) glDrawArrays (GL_TRIANGLES, 0, 3 ) glRotatef(-180,0,0,1) glDrawArrays (GL_TRIANGLES, 0, 3 )
glLoadIdentity(); glFrustumf(-hwd, hwd, -hht, hht, nearp, farp);
glTranslatef(0.0, 0.f,-75);
glColor4ub(0,255,0,255)
glEnableClientState( GL_VERTEX_ARRAY );
glTranslatef(20.0, 15.0,0.0);
glRotatef(t,0,0,1) glRotatef(t/2,1,0,0) glVertexAttribPointer ( 0, 2, GL_FLOAT, GL_FALSE,0,vVertices )
glEnableVertexAttribArray ( 0 ) glDrawArrays (GL_LINES, 0, 2 )
glRotatef(90,0,0,1) glDrawArrays (GL_LINES, 0, 2 )
glRotatef(90,0,0,1) glDrawArrays (GL_LINES, 0, 2 )
glRotatef(90,0,0,1) glDrawArrays (GL_LINES, 0, 2 ) eglSwapBuffers(Display, Surface) INCR t , 2
WEND
|
|
|
Post by vovchik on Jan 31, 2016 15:13:17 GMT 1
Dear Alex, Your code looks very good. I really will have to get a PI soon. With kind regards, vovchik
|
|
|
Post by alexfish on Jan 31, 2016 15:34:29 GMT 1
Hi Vovchik
although the Raspberry is a low power device , programming the EGL , gpu direct is best.
decided to take this route since the likes of Windowed GL surfaces are not good in terms of speed ,
so here , on the raspberry can draw a square at the full size of the screen , and rotate it at 50 frames a second , only then can appreciate .
BR Alex
|
|
|
Post by alexfish on Jan 31, 2016 19:08:48 GMT 1
Circle
Not Ideal under this scheme , yet can work in quad POINTS from the same triangle vertex data
here we go
LOCAL lp TYPE int
glClear ( GL_COLOR_BUFFER_BIT ); /* CALCULATE THE FUSTRUM*/ glGetIntegerv(GL_VIEWPORT, viewport) hht = nearp * (float)tan(45.0 / 2.0 / 180.0 * M_PI) hwd = hht * (float)viewport[2] / (float)viewport[3]
glLoadIdentity(); glFrustumf(-hwd, hwd, -hht, hht, nearp, farp); glEnableClientState( GL_VERTEX_ARRAY );
/* move back to see results */ glTranslatef(0,0,-75);
glColor4ub(255,0,0,255)
glEnableClientState( GL_VERTEX_ARRAY );
glPointSize(1.0) glVertexAttribPointer ( 0,3, GL_FLOAT, GL_TRUE,0,vVertices ) glEnableVertexAttribArray ( 0 ) FOR lp = 0 TO 90 glDrawArrays (GL_POINTS, 0, 4) glRotatef(1,0,0,1) NEXT
ADDED : ortho type layout as high performance canvas can be ahieved like so
Where 0,0 is top left
glFrustumf(0, hwd*2, hht*2, 0, nearp, farp)
+ fill CIRCLE / this can be refined see the two bits of code
FOR lp = 0 TO 91 glDrawArrays (GL_TRIANGLE_STRIP, 0, 4) glRotatef(1,0,0,1) NEXT Note that the glRotate angle Must Match the STEP .. here = ' 0.5 '
FOR lp = 0 TO 91 STEP 0.5 glDrawArrays (GL_TRIANGLE_STRIP, 0, 4) glRotatef(0.5,0,0,1) NEXT
under present scheme .. need to get back to PIXEL size , try different combinations of the draw , to get would be thinking fastest draw method then try , scale factor . this gets pixel size in all directions
can also use scaling 'up from 1' eg scale in the X
scale in Y
scale in Z
happy coding BR Alex
|
|
|
Post by alexfish on Feb 1, 2016 21:17:03 GMT 1
Well
this one was an amazing find , Quick Draw Wire cube using the original triangle vertex data
No maths involved , no coords to update.. this is the Wire Cube rotating data , looking at this then a solid cube about the same.
BR Alex the data
/* draw line Cube */ glLoadIdentity(); glFrustumf(-hwd, hwd, -hht, hht, nearp, farp); glEnableClientState( GL_VERTEX_ARRAY ) /* color green */ glColor4ub(0,255,0,255) /* set back to see */ glTranslatef(0.0, 0.f,-75); /* set to the right and up to get clear pic of the pespective */ glTranslatef(20.0, 15.0,0.0); /* can rotate the cube using increment float 't ' */ glRotatef(t,0,0,1) glRotatef(t/2,1,0,0)
glVertexAttribPointer ( 0, 8, GL_FLOAT, GL_FALSE,0,vVertices )
glEnableVertexAttribArray ( 0 ) glDrawArrays (GL_LINES, 0, 8)
glRotatef(90,0,0,1) glDrawArrays (GL_LINES, 0,8)
glRotatef(90,0,1,0) glDrawArrays (GL_LINES, 0, 8)
glRotatef(180,0,1,0) glDrawArrays (GL_LINES, 0, 8)
If U'r asking does this make sense , No , something tells me I am accessing an out of bounds array, yet there be no errors , worth looking into.
Update : now found the reason , this happens on the init stage of glVertexPointer() the array is defined "static const GLbyte quadx[6*4*3]" , weird Shit this EGL.. Yet now looking here , looks like have Isolated the necessary vertexes & pointers , + arrays , As a side note during this ?? have managed to draw a line from the 0.0 to anywhere on x y.,
YES A LINE , a Single solitary LINE . from 0.0
here is a simple line 0,0 to 1,0 static const GLbyte line[] = {
0, 0, 1,0
};
Looks like can now set up some basic geometric functions much like in Peters Canvases . from these bits can convert to what ever by changing the data in the likes of say the line
Looks like this will be the last update on this post . Now looking to update the lib with the new features
|
|
|
Post by alexfish on Feb 2, 2016 20:38:37 GMT 1
Hi All
Last update , then will the base core lib will be updated ,
Here have completed bounds testing , using the Frustum data as in previous posts
tested here to outer bounds with say Zdepth_ptr = 5 then placement x max is hwd*5 and y max is hht *5
/* back -5 right max & top max */ glTranslatef(hwd*Zdepth_ptr,hht*Zdepth_ptr,-Zdepth_ptr); test bottom left cords would be
glTranslatef(-hwd*Zdepth_ptr,-hht*Zdepth_ptr,-Zdepth_ptr);
ADDED suppose the only diff between the freeglut geometry section is that they be in float, wonder what would happen if re-write into Bytes . mm! food for thought. looking further , some of that data be in bytes..
update : now got the float arrays working with glcolor , never thought I would see the day ::
BR Alex
|
|