|
Post by alexfish on Jul 16, 2015 11:52:40 GMT 1
Hi All Configuring Bacon for Raspbian on Raspberry Pi 2 Possible easy route for Beginners, 1. install synaptic , this also brings in quite a few of the neccessities for developement work and not just for bacon from the terminal sudo apt-get install synaptic using synaptic:: 1.2 update the system using synaptic Note :: did a test of mobile internet 3g/4g. You may find the dongle will not register + the mouse will freeze as a work around , plug a usb memory stick in first , unplug the memory stick , plug the mobile dongle . after updating the system reboot . the dongle should now hot plug. esp if have usb_modeswitch + ppp + wvdial Installed 2. install build-essentials 3. install gtk sourceview3 devs if wanting to use gtk3 or can just try gtk sourceview2 devs this also brings in some neccesities for development work. + the neccessary libs for hug.bac 4. install xterm download Autoconf source package BaCon 3.1 from HEREExtract the tar file from the terminal cd to the bacon folder ./configure make sudo make install also need latest hug.bac make folder in home/pi/ named bacon cd /home/pi/bacon/ wget http://www.basic-converter.org/hug.bac for html helpfileswget http://www.basic-converter.org/documentation.html Reboot one should be able to find Bacongui in Menu/Programming . the sytaxfile file should auto download. reboot the gui. to read documentation :: use the file browser , go to the bacon folder and Click on hopeful on system there is a web browser call Dillo . this will show the documentation.. a quick demo. testhug.bac .. save as '/home/pi/bacon/testhug.bac INCLUDE hug.bac
SUB Click()
PRINT "Button Clicked"
END SUB
win = WINDOW("test", 600,400) but = BUTTON("test-but",100,25) ATTACH(win,but,10,10) CALLBACK(but,Click) Note :: canvas gl and gl area will not work .. Rasberry pi 2 is configured for GL ES . ie gl is implemented direct on the GPU . best beginners option will be to install goocanvas . then see " thread goo canvas." have posted blow a link to the gl es book examples:: further to this there should be a folder call " vc " in the /opt/ IE path /opt/vc Copy this to the bacon folder. cd to the folder cd /baco/vc/src/hello_pi then enter command ./rebuild.sh Ok. check the execs.. and esp this one "hello_triangle" & for display of speed rendering "hello_triangle2" triangle2 is a combination of mandelbrot/julia sets . amazing. down to hard nuts:: one will need to use some communication with X11 , to safely exit the demo code . at present one has to use ctrl + c to get out of the loop. Bacon can do this . make a window full size of the screen.. now can convert the c code to bacon using the useh for the header files + Usec for the c defs that U not be sure of . main objective here :: in the sources there is a method to free the bits : us the KEY() command .. on KEY() = <x> : >> call a sub that contains the Free's now U be in control .. Hint:: make a sub that builds the GL ES window , place a Button with callback to the SUB which makes the GL ES window etc etc., Same for button to exit.. "END" or "QUIT" also set the main gles window alpha value to 0 IE:: glClearColor(0.15f, 0.25f, 0.35f, 0.0f)
|
|
|
Post by vovchik on Jul 16, 2015 16:11:03 GMT 1
Dear Alex, I see what you have been up to. Wish I had a raspberry PI to test. One of these days.... With kind regards, vovchik
|
|
|
Post by alexfish on Jul 16, 2015 16:12:00 GMT 1
Hi All & @ 1 for Peter here is a how to compile tcc from source package download tcc from HEREextract the file then cd to the folder from the terminal ./configure --with-libgcc make sudo make install now a one for @ Peter :: using latest beta . ? BaCon err = can not find lib bacon yet if compile with the -a :: make ar then it will compile. but need to do so on every compile . have the bacon ar in usr/local/lib + usr/lib ?? however have tested terminal mode + the hug.bac demo as above + tested GooCanvas + the list which uses scrolled win This is looking good .if can resolve the archive rebuild. BR Alex PS: the hug demo above :: tcc 6 to 7 seconds | gcc 16 seconds
|
|
|
Post by Pjot on Jul 16, 2015 20:59:41 GMT 1
Hi Alex,
It seems you have to add the location of 'libbacon.a' explicitly. For example:
Here, the '-l' flag has "-L/usr/local/lib" as argument, which points to the directory where 'libbacon.a' resides on my system.
BR Peter
|
|
|
Post by alexfish on Jul 16, 2015 21:24:46 GMT 1
Hi Peter
The code above works,
+ one can enter this is the bacongui options at compile time
enter this code in Libraries
-lbacon -L/usr/local/lib
BR Alex
|
|
|
Post by alexfish on Jul 17, 2015 21:01:27 GMT 1
Hi Al
For those interest the fb and gles side of things, there is an easy api to gain access to gles Should make life easier to convert to Bacon ?
If system up to date can ignore the Fix in the readme . Raspbian only
in Raspbian the main bits should be configured :: RE :: if followed the above posts.
will find via synaptic. libraspberrypi-dev EGL/GLES/OpenVG/etc. libraries for the Raspberry Pi's VideoCore IV (headers)
the master is in c. but will give a taste of what can be done . and will see Raspberry Pi 2 is no slow coach
make a folder in downloads called opengles
then from the terminal
cd /home/pi/Downloads/opengles
wget --no-check-certificate https://github.com/benosteen/opengles-book-samples/tarball/master
tar -xvzf master
cd /home/pi/Downloads/opengles/benosteen-opengles-book-samples-5ff2dc9/Raspi
make
Note :do not try achiver on the master:: You have been warned
can also have a look at Linux volume if on standard desktop IE Intel, Amd etc , there is also an Anroid version
boot the Task Manager in the Accessories
go to each folder and click on the exec's , to stop the app look in the task manager . click on the app and kill it.
BR Alex
|
|
|
Post by alexfish on Oct 11, 2015 1:08:13 GMT 1
Just a quote
? is convergence a reality
I have seen a Yes....
EGL...
BR Alex
|
|
|
Post by alexfish on Oct 21, 2015 21:18:03 GMT 1
Hi All
have been going through the book examples + the demo's in the VC folder
As for the VC folder , reference to the Open-gles + the Egl , these libs should be common to most devices like the Raspberry Pi + pads and phones etc
have found that there are some bugs in the shader + the texture examples , where by Gcc will not compile some of the demo's due to incompatible pointer types..
not exactly sure what they are , as a brief look indicates they of of the correct type , need to dig deeper.
Tcc will compile them , if have the compiled version as per earlier Post. tcc will only post a warning on the 'CUBE_STATE_T' + nothing shows up as regards the 'incompatible pointer' ..
tcc has proved the best compiler as regards speed , up to 20* if have mix of gtk + gles.. + the obvious as regards the pointers above.
hope to be back on track soon . still very occupied on the work front. .. but have managed to get to grips with gles , as indicator 0 is bottom , most things on Linux 0 is top.. load a picture as a texture and the thing is upside down..
drawing a line or a triangle is easy draw a square or something more complex requires fiddling with the arrays + the method
the basics are these not the api does not have glbegin nor glend, to draw a square need the correct size array then tell it to draw the four bits within the draw arrays() so tho get a SQUARE one would use the GL_TRIANGLE_FAN :: glDrawArrays(GL_TRIANGLE_FAN, 0, 4)
/* BeginMode GL_POINTS GL_LINES GL_LINE_LOOP GL_LINE_STRIP GL_TRIANGLES GL_TRIANGLE_STRIP GL_TRIANGLE_FAN */
anyway ..
here is the linker and libs options for Bacon using tcc
-O2 -g -lm -ldl -pipe -L. -I/usr/lib/arm-linux-gnueabihf/ -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux -lGLESv2 -lEGL -lm -lbcm_host -L/opt/vc/lib -lbacon -L /usr/local/lib
BR Alex
|
|
|
Post by alexfish on Oct 27, 2015 18:09:53 GMT 1
Hi Peter
not sure of the actual problem ,.. well possible a Bacon parsing one.. re globals and locals + using USEC statements
here the first code is working the second code block produces err message from bacon Line 218: LOCAL esContext TYPE ESContext
code working so far
' ' Book: OpenGL(R) ES 2.0 Programming Guide ' Authors: Aaftab Munshi, Dan Ginsburg, Dave Shreiner ' ISBN-10: 0321502795 ' ISBN-13: 9780321502797 ' Publisher: Addison-Wesley Professional ' URLs: http://safari.informit.com/9780321563835 ' http://www.opengles-book.com '
' Hello_Triangle.c ' ' This is a simple example that draws a single triangle with ' a minimal vertex/fragment shader. The purpose of this ' example is to demonstrate the basic concepts of ' OpenGL ES 2.0 rendering.
OPTION PARSE FALSE
PRAGMA INCLUDE esUtil.h PRAGMA INCLUDE esUtil.c PRAGMA INCLUDE esTransform.c PRAGMA INCLUDE esShader.c PRAGMA INCLUDE esShapes.c
PRAGMA OPTIONS -DRPI_NO_X -I/usr/lib/arm-linux-gnueabihf/ -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux -lGLESv2 -lEGL -lm -lbcm_host -L/opt/vc/lib -lbacon -L /usr/local/lib -ldl -lm
REM TODO resolve bacon casting struts to pointer USEC typedef struct { // Handle to a program object GLuint programObject;
} UserData;
END USEC
REM Create a shader object, load the shader source, and REM compile the shader.
FUNCTION LoadShader ( GLenum type, const char *shaderSrc ) TYPE GLuint
LOCAL shader TYPE GLuint LOCAL compiled TYPE GLint REM Create the shader object shader = glCreateShader ( type )
IF ( shader == 0 ) THEN RETURN 0 END IF REM Load the shader source CALL glShaderSource ( shader, 1, &shaderSrc, NULL ) REM Compile the shader CALL glCompileShader ( shader )
REM Check the compile status CALL glGetShaderiv ( shader, GL_COMPILE_STATUS, &compiled )
IF NOT(compiled ) THEN LOCAL infoLen = 0 TYPE GLint
CALL glGetShaderiv ( shader, GL_INFO_LOG_LENGTH, &infoLen ); IF ( infoLen > 1 ) THEN USEC char* infoLog = malloc (sizeof(char) * infoLen ); END USEC CALL glGetShaderInfoLog ( shader, infoLen, NULL, infoLog ) CALL esLogMessage ( "Error compiling shader:\n%s\n", infoLog ) FREE infoLog ENDIF
CALL glDeleteShader ( shader ) RETURN 0 ENDIF
RETURN shader
ENDFUNCTION
FUNCTION Init ( ESContext *esContext ) TYPE int
USEC typedef struct { // Handle to a program object GLuint programObject;
} UserData; END USEC LET esContext->userData = malloc(sizeof(UserData));
LOCAL *userData TYPE UserData userData = esContext->userData
USEC GLbyte vShaderStr[] = "attribute vec4 vPosition; \n" "void main() \n" "{ \n" " gl_Position = vPosition; \n" "} \n"; GLbyte fShaderStr[] = "precision mediump float;\n"\ "void main() \n" "{ \n" " gl_FragColor = vec4 ( 1.0, 0.0, 0.0, 1.0 );\n" "} \n"; END USEC
LOCAL vertexShader TYPE GLuint LOCAL fragmentShader TYPE GLuint LOCAL programObject TYPE GLuint LOCAL linked TYPE GLint
REM Load the vertex/fragment shaders vertexShader = LoadShader ( GL_VERTEX_SHADER, vShaderStr ) fragmentShader = LoadShader ( GL_FRAGMENT_SHADER, fShaderStr )
REM Create the program object programObject = glCreateProgram ( ) IF programObject == 0 THEN RETURN 0 END IF
glAttachShader ( programObject, vertexShader ) glAttachShader ( programObject, fragmentShader )
REM Bind vPosition to attribute 0 glBindAttribLocation ( programObject, 0, "vPosition" )
REM Link the program glLinkProgram ( programObject )
REM Check the link status glGetProgramiv ( programObject, GL_LINK_STATUS, &linked )
IF NOT(linked) THEN LOCAL infoLen = 0 TYPE GLint
glGetProgramiv ( programObject, GL_INFO_LOG_LENGTH, &infoLen ) IF infoLen > 1 THEN LOCAL infoLog TYPE char* infoLog = malloc (sizeof(char) * infoLen );
glGetProgramInfoLog ( programObject, infoLen, NULL, infoLog ); esLogMessage ( "Error linking program:\n%s\n", infoLog ); FREE infoLog END IF
glDeleteProgram ( programObject ) RETURN GL_FALSE END IF
REM Store the program object userData->programObject = programObject;
glClearColor ( 0.0f, 0.0f, 0.0f, 1.0f );
RETURN GL_TRUE END FUNCTION
USEC
// Draw a triangle using the shader pair created in Init() // void Draw ( ESContext *esContext ) { UserData *userData = esContext->userData; GLfloat vVertices[] = { 0.0f, 0.5f, 0.0f, -0.5f, -0.5f, 0.0f, 0.5f, -0.5f, 0.0f }; // Set the viewport glViewport ( 0, 0, esContext->width, esContext->height ); // Clear the color buffer glClear ( GL_COLOR_BUFFER_BIT );
// Use the program object glUseProgram ( userData->programObject );
// Load the vertex data glVertexAttribPointer ( 0, 3, GL_FLOAT, GL_FALSE, 0, vVertices ); glEnableVertexAttribArray ( 0 );
glDrawArrays ( GL_TRIANGLES, 0, 3 ); }
ENDUSEC
LOCAL esContext TYPE ESContext LOCAL userData TYPE UserData
esInitContext ( &esContext ) esContext.userData = &userData
esCreateWindow ( &esContext, "Hello Triangle", 320, 240, ES_WINDOW_RGB )
Init( &esContext )
esRegisterDrawFunc ( &esContext, Draw )
esMainLoop ( &esContext )
Now the here, at that last conversion of the sub before main ' ' Book: OpenGL(R) ES 2.0 Programming Guide ' Authors: Aaftab Munshi, Dan Ginsburg, Dave Shreiner ' ISBN-10: 0321502795 ' ISBN-13: 9780321502797 ' Publisher: Addison-Wesley Professional ' URLs: http://safari.informit.com/9780321563835 ' http://www.opengles-book.com '
' Hello_Triangle.c ' ' This is a simple example that draws a single triangle with ' a minimal vertex/fragment shader. The purpose of this ' example is to demonstrate the basic concepts of ' OpenGL ES 2.0 rendering.
OPTION PARSE FALSE
PRAGMA INCLUDE esUtil.h PRAGMA INCLUDE esUtil.c PRAGMA INCLUDE esTransform.c PRAGMA INCLUDE esShader.c PRAGMA INCLUDE esShapes.c
PRAGMA OPTIONS -DRPI_NO_X -I/usr/lib/arm-linux-gnueabihf/ -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux -lGLESv2 -lEGL -lm -lbcm_host -L/opt/vc/lib -lbacon -L /usr/local/lib -ldl -lm
REM TODO resolve bacon casting struts to pointer USEC typedef struct { // Handle to a program object GLuint programObject;
} UserData;
END USEC
REM Create a shader object, load the shader source, and REM compile the shader.
FUNCTION LoadShader ( GLenum type, const char *shaderSrc ) TYPE GLuint
LOCAL shader TYPE GLuint LOCAL compiled TYPE GLint REM Create the shader object shader = glCreateShader ( type )
IF ( shader == 0 ) THEN RETURN 0 END IF REM Load the shader source CALL glShaderSource ( shader, 1, &shaderSrc, NULL ) REM Compile the shader CALL glCompileShader ( shader )
REM Check the compile status CALL glGetShaderiv ( shader, GL_COMPILE_STATUS, &compiled )
IF NOT(compiled ) THEN LOCAL infoLen = 0 TYPE GLint
CALL glGetShaderiv ( shader, GL_INFO_LOG_LENGTH, &infoLen ); IF ( infoLen > 1 ) THEN USEC char* infoLog = malloc (sizeof(char) * infoLen ); END USEC CALL glGetShaderInfoLog ( shader, infoLen, NULL, infoLog ) CALL esLogMessage ( "Error compiling shader:\n%s\n", infoLog ) FREE infoLog ENDIF
CALL glDeleteShader ( shader ) RETURN 0 ENDIF
RETURN shader
ENDFUNCTION
FUNCTION Init ( ESContext *esContext ) TYPE int
USEC typedef struct { // Handle to a program object GLuint programObject;
} UserData; END USEC LET esContext->userData = malloc(sizeof(UserData));
LOCAL *userData TYPE UserData userData = esContext->userData
USEC GLbyte vShaderStr[] = "attribute vec4 vPosition; \n" "void main() \n" "{ \n" " gl_Position = vPosition; \n" "} \n"; GLbyte fShaderStr[] = "precision mediump float;\n"\ "void main() \n" "{ \n" " gl_FragColor = vec4 ( 1.0, 0.0, 0.0, 1.0 );\n" "} \n"; END USEC
LOCAL vertexShader TYPE GLuint LOCAL fragmentShader TYPE GLuint LOCAL programObject TYPE GLuint LOCAL linked TYPE GLint
REM Load the vertex/fragment shaders vertexShader = LoadShader ( GL_VERTEX_SHADER, vShaderStr ) fragmentShader = LoadShader ( GL_FRAGMENT_SHADER, fShaderStr )
REM Create the program object programObject = glCreateProgram ( ) IF programObject == 0 THEN RETURN 0 END IF
glAttachShader ( programObject, vertexShader ) glAttachShader ( programObject, fragmentShader )
REM Bind vPosition to attribute 0 glBindAttribLocation ( programObject, 0, "vPosition" )
REM Link the program glLinkProgram ( programObject )
REM Check the link status glGetProgramiv ( programObject, GL_LINK_STATUS, &linked )
IF NOT(linked) THEN LOCAL infoLen = 0 TYPE GLint
glGetProgramiv ( programObject, GL_INFO_LOG_LENGTH, &infoLen ) IF infoLen > 1 THEN LOCAL infoLog TYPE char* infoLog = malloc (sizeof(char) * infoLen );
glGetProgramInfoLog ( programObject, infoLen, NULL, infoLog ); esLogMessage ( "Error linking program:\n%s\n", infoLog ); FREE infoLog END IF
glDeleteProgram ( programObject ) RETURN GL_FALSE END IF
REM Store the program object userData->programObject = programObject;
glClearColor ( 0.0f, 0.0f, 0.0f, 1.0f );
RETURN GL_TRUE END FUNCTION
USEC
REM Draw a triangle using the shader pair created in Init()
SUB Draw ( ESContext *esContext )
USEC typedef struct { // Handle to a program object GLuint programObject;
} UserData; END USEC
UserData *userData = esContext->userData; GLfloat vVertices[] = { 0.0f, 0.5f, 0.0f, -0.5f, -0.5f, 0.0f,0.5f, -0.5f, 0.0f }; REM Set the viewport glViewport ( 0, 0, esContext->width, esContext->height ) REM Clear the color buffer glClear ( GL_COLOR_BUFFER_BIT )
REM Use the program object glUseProgram ( userData->programObject )
REM Load the vertex data glVertexAttribPointer ( 0, 3, GL_FLOAT, GL_FALSE, 0, vVertices ) glEnableVertexAttribArray ( 0 );
glDrawArrays ( GL_TRIANGLES, 0, 3 )
END SUB
LOCAL esContext TYPE ESContext LOCAL userData TYPE UserData
esInitContext ( &esContext ) esContext.userData = &userData
esCreateWindow ( &esContext, "Hello Triangle", 320, 240, ES_WINDOW_RGB )
Init( &esContext )
esRegisterDrawFunc ( &esContext, Draw )
esMainLoop ( &esContext )
Also Note that the Code requires the ' UserData' struct within each sub ;;
other than that .. almost there with EGL and GLES
BR Alex
|
|
|
Post by alexfish on Oct 27, 2015 18:17:16 GMT 1
Hi Peter
Scratch the above .. Had a Stray USEC in the code
This works ,, So now looking at a Global type def struct ;; IE where having to cast the struct to pointer in every sub or function
also not that the code still has some CALL syntax this will not be required when using statement
OPTION PARSE FALSE
BR Alex
The code working so far ;; Pity can not post a picture since screen shot can not pick up on frame buffer or the EGL
' ' Book: OpenGL(R) ES 2.0 Programming Guide ' Authors: Aaftab Munshi, Dan Ginsburg, Dave Shreiner ' ISBN-10: 0321502795 ' ISBN-13: 9780321502797 ' Publisher: Addison-Wesley Professional ' URLs: http://safari.informit.com/9780321563835 ' http://www.opengles-book.com '
' Hello_Triangle.c ' ' This is a simple example that draws a single triangle with ' a minimal vertex/fragment shader. The purpose of this ' example is to demonstrate the basic concepts of ' OpenGL ES 2.0 rendering.
OPTION PARSE FALSE
PRAGMA INCLUDE esUtil.h PRAGMA INCLUDE esUtil.c PRAGMA INCLUDE esTransform.c PRAGMA INCLUDE esShader.c PRAGMA INCLUDE esShapes.c
PRAGMA OPTIONS -DRPI_NO_X -I/usr/lib/arm-linux-gnueabihf/ -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux -lGLESv2 -lEGL -lm -lbcm_host -L/opt/vc/lib -lbacon -L /usr/local/lib -ldl -lm
REM TODO resolve bacon casting struts to pointer USEC typedef struct { // Handle to a program object GLuint programObject;
} UserData;
END USEC
REM Create a shader object, load the shader source, and REM compile the shader.
FUNCTION LoadShader ( GLenum type, const char *shaderSrc ) TYPE GLuint
LOCAL shader TYPE GLuint LOCAL compiled TYPE GLint REM Create the shader object shader = glCreateShader ( type )
IF ( shader == 0 ) THEN RETURN 0 END IF REM Load the shader source CALL glShaderSource ( shader, 1, &shaderSrc, NULL ) REM Compile the shader CALL glCompileShader ( shader )
REM Check the compile status CALL glGetShaderiv ( shader, GL_COMPILE_STATUS, &compiled )
IF NOT(compiled ) THEN LOCAL infoLen = 0 TYPE GLint
CALL glGetShaderiv ( shader, GL_INFO_LOG_LENGTH, &infoLen ); IF ( infoLen > 1 ) THEN USEC char* infoLog = malloc (sizeof(char) * infoLen ); END USEC CALL glGetShaderInfoLog ( shader, infoLen, NULL, infoLog ) CALL esLogMessage ( "Error compiling shader:\n%s\n", infoLog ) FREE infoLog ENDIF
CALL glDeleteShader ( shader ) RETURN 0 ENDIF
RETURN shader
ENDFUNCTION
FUNCTION Init ( ESContext *esContext ) TYPE int
USEC typedef struct { // Handle to a program object GLuint programObject;
} UserData; END USEC LET esContext->userData = malloc(sizeof(UserData));
LOCAL *userData TYPE UserData userData = esContext->userData
USEC GLbyte vShaderStr[] = "attribute vec4 vPosition; \n" "void main() \n" "{ \n" " gl_Position = vPosition; \n" "} \n"; GLbyte fShaderStr[] = "precision mediump float;\n"\ "void main() \n" "{ \n" " gl_FragColor = vec4 ( 1.0, 0.0, 0.0, 1.0 );\n" "} \n"; END USEC
LOCAL vertexShader TYPE GLuint LOCAL fragmentShader TYPE GLuint LOCAL programObject TYPE GLuint LOCAL linked TYPE GLint
REM Load the vertex/fragment shaders vertexShader = LoadShader ( GL_VERTEX_SHADER, vShaderStr ) fragmentShader = LoadShader ( GL_FRAGMENT_SHADER, fShaderStr )
REM Create the program object programObject = glCreateProgram ( ) IF programObject == 0 THEN RETURN 0 END IF
glAttachShader ( programObject, vertexShader ) glAttachShader ( programObject, fragmentShader )
REM Bind vPosition to attribute 0 glBindAttribLocation ( programObject, 0, "vPosition" )
REM Link the program glLinkProgram ( programObject )
REM Check the link status glGetProgramiv ( programObject, GL_LINK_STATUS, &linked )
IF NOT(linked) THEN LOCAL infoLen = 0 TYPE GLint
glGetProgramiv ( programObject, GL_INFO_LOG_LENGTH, &infoLen ) IF infoLen > 1 THEN LOCAL infoLog TYPE char* infoLog = malloc (sizeof(char) * infoLen );
glGetProgramInfoLog ( programObject, infoLen, NULL, infoLog ); esLogMessage ( "Error linking program:\n%s\n", infoLog ); FREE infoLog END IF
glDeleteProgram ( programObject ) RETURN GL_FALSE END IF
REM Store the program object userData->programObject = programObject;
glClearColor ( 0.0f, 0.0f, 0.0f, 1.0f );
RETURN GL_TRUE END FUNCTION
REM Draw a triangle using the shader pair created in Init()
SUB Draw ( ESContext *esContext )
USEC typedef struct { // Handle to a program object GLuint programObject;
} UserData; END USEC LOCAL *userData TYPE UserData userData = esContext->userData; GLfloat vVertices[] = { 0.0f, 0.5f, 0.0f, -0.5f, -0.5f, 0.0f,0.5f, -0.5f, 0.0f }; REM Set the viewport glViewport ( 0, 0, esContext->width, esContext->height ) REM Clear the color buffer glClear ( GL_COLOR_BUFFER_BIT )
REM Use the program object glUseProgram ( userData->programObject )
REM Load the vertex data glVertexAttribPointer ( 0, 3, GL_FLOAT, GL_FALSE, 0, vVertices ) glEnableVertexAttribArray ( 0 );
glDrawArrays ( GL_TRIANGLES, 0, 3 )
END SUB
LOCAL esContext TYPE ESContext LOCAL userData TYPE UserData
esInitContext ( &esContext ) esContext.userData = &userData
esCreateWindow ( &esContext, "Hello Triangle", 320, 240, ES_WINDOW_RGB )
Init( &esContext )
esRegisterDrawFunc ( &esContext, Draw )
esMainLoop ( &esContext )
Edit :: forgot to mention, U need to paste the line of code shown below in the BaCon GUI "Library" box upon compile , it is the same as in the PRAGMA OPTIONS
-DRPI_NO_X -I/usr/lib/arm-linux-gnueabihf/ -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux -lGLESv2 -lEGL -lm -lbcm_host -L/opt/vc/lib -lbacon -L /usr/local/lib -ldl -lm
|
|
|
Post by alexfish on Oct 27, 2015 18:45:01 GMT 1
Hi All
as a reminder , the Book Examples also includes code examples for the Following devices/OS & or Desktop
Android BlackBerry iPhone LinuxX11 WebGL Windows
BR Alex
|
|
|
Post by alexfish on Oct 31, 2015 23:42:31 GMT 1
GL colours
Gles colors values are 0.0f to 1.0f
as an aproximation ,if want to convert decimal rgb to GLfloat value one can look at these
GLfloat R = (r/7.96875)/32 : GLfloat G = (g/7.96875)/32 : GLfloat B = (b/7.96875)/32 Where r,g,b values are 0 to 255
GLfloat R = (0/7.96875)/32 : GLfloat G = (0/7.96875)/32 : GLfloat B = (0/7.96875)/32 = Black
GLfloat R = (255/7.96875)/32 : GLfloat G = (255/7.96875)/32 : GLfloat B = (255/7.96875)/32 = White
can then use the BaCon Colour Chooser to get the decimal rgb values
suppose can use the same algo for the alpha
BR Alex
|
|
|
Post by alexfish on Jan 27, 2016 23:09:58 GMT 1
just a couple of recommends , before I be starting a bacon lib for using the open-gl es egles.
here are what can be done to ensure compat with c and c++ OR other compilers . but def for gcc & g++ and tcc
if c++ add these to the program header
extern "C" { extern void bcm_host_init(); extern void bcm_host_deinit(); extern int graphics_get_display_size(int,void*,void*); }
then for all
In The Book Examples :: Common
in the esUtil.c at lines 171 to 173
dispman_element = vc_dispmanx_element_add ( dispman_update, dispman_display, 0/*layer*/, &dst_rect, 0/*src*/, &src_rect, DISPMANX_PROTECTION_NONE, 0 /*alpha*/, 0/*clamp*/, 0/*transform*/);
change to
// added (DISPMANX_TRANSFORM_T) dispman_element = vc_dispmanx_element_add ( dispman_update, dispman_display, 0/*layer*/, &dst_rect, 0/*src*/, &src_rect, DISPMANX_PROTECTION_NONE, 0 /*alpha*/, 0/*clamp*/,(DISPMANX_TRANSFORM_T) 0/*transform*/);
compiler flags
these should work
-I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux -lGLESv2 -lEGL -lm -lbcm_host -lvcos -lvchiq_arm -lpthread -lrt -L/opt/vc/lib -lm
also can test the vc demos triangle one and two . need a change here
the line that is required is in CreateEGLContext
change these line 107
context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttribs );
to // Create a GL context // TODO testing by swapping // context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttribs ); context = eglCreateContext(display, config, EGL_NO_CONTEXT, NULL );
Edit Added :: missed a one , actually an important bit for the Rasby also think this could be a bug , in least all the Flashy flickers disapear
in sub routine ' CreateEGLContext lines 67 to 79 , note that looks like egl x server display when a request is for a egl display period 'RPI_NO_X ' means no X and get
//CreateEGLContext // Get Display #ifndef RPI_NO_X display = eglGetDisplay((EGLNativeDisplayType)x_display); if ( display == EGL_NO_DISPLAY ) { return EGL_FALSE; } #else display = eglGetDisplay(EGL_DEFAULT_DISPLAY); if ( display == EGL_NO_DISPLAY ) { return EGL_FALSE; } #endif
replace all with
// Get Display EGL_DEFAULT_DISPLAY //TODO // display = eglGetDisplay((EGLNativeDisplayType)x_display); display = eglGetDisplay(EGL_DEFAULT_DISPLAY); if ( display == EGL_NO_DISPLAY ) { return EGL_FALSE; } with all changes , there should be no conflict of egl apps + can make multiple context/surfaces , have not fully tested , yet but they should come out as layers make the surface context , the clear and swap the buffers using the alpha 0.0
for each layer above the base layer test first with
glClearColor(1.0f, 1.0f, 1.0f, 0.5f); then
glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
also change the init stages 'esCreateWindow' of the esUtil.c
full code here
// TODO // THE ENTRY POINT
int esCreateWindow ( ESContext *esContext, GLint width, GLint height, GLuint flags ){
EGLint attribList[] = {
EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8, EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_NONE
// EGL_RED_SIZE, 5, // EGL_GREEN_SIZE, 6, // EGL_BLUE_SIZE, 5, // EGL_ALPHA_SIZE, 8, // EGL_DEPTH_SIZE, 8 , // EGL_STENCIL_SIZE, 8, // EGL_SAMPLE_BUFFERS, 8 // EGL_NONE }; if ( esContext == NULL ) { return GL_FALSE; }
esContext->width = width; esContext->height = height;
if ( !WinCreate ( esContext) ) { return GL_FALSE; }
if ( !CreateEGLContext ( esContext->hWnd, &esContext->eglDisplay,&esContext->eglContext,&esContext->eglSurface,attribList) ) { return GL_FALSE; }
return GL_TRUE; } BR Alex
|
|