# Demo using eglCreatePbufferSurface()

**URL:** <https://forums.imgtec.com/t/demo-using-eglcreatepbuffersurface/447>\
**Category:** PowerVR Insider\
**Created:** [August 17, 2009, 8:55am UTC](https://forums.imgtec.com/t/demo-using-eglcreatepbuffersurface/447 "2009-08-17T08:55:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bujji00](https://avatars.discourse-cdn.com/v4/letter/b/d78d45/32.png) [@bujji00](https://forums.imgtec.com/u/bujji00)\
**Post date:** [August 17, 2009, 8:55am UTC](https://forums.imgtec.com/t/demo-using-eglcreatepbuffersurface/447/1 "2009-08-17T08:55:11Z")

</div>

HiÂ

I am a newbie trying to modify the trainign course demo "02\_HelloTriangle" to use the eglCreatePbufferSurface() instead of eglCreateWindowSurface()

The modifications done are as follows

Â EGLint s\_surfaceAttribs[] =  
Â { EGL\_WIDTH, 240,  
Â EGL\_HEIGHT, 320,  
Â EGL\_NONE  
Â };

Â //eglSurface = eglCreateWindowSurface(eglDisplay, eglConfig,(void\*) m\_glutWindow, NULL);  
Â eglSurface = eglCreatePbufferSurface(eglDisplay,eglConfig,s\_surfaceAttribs);

After teh above changes i am not able to see the traingle. The output is scattered.

What changes are to be done for displaying the frame to the screen? will the eglSwapBuffers() work with pBuffer?

i am using the Imagination Technologies PowerVR SDK OVG-1.0\_WINDOWS\_PCEMULATION\_2.04.24.0811.

thnks

RK

---

<div class="post-metadata">

**Author:** ![bujji00](https://avatars.discourse-cdn.com/v4/letter/b/d78d45/32.png) [@bujji00](https://forums.imgtec.com/u/bujji00)\
**Post date:** [August 17, 2009, 9:04am UTC](https://forums.imgtec.com/t/demo-using-eglcreatepbuffersurface/447/2 "2009-08-17T09:04:40Z")

</div>

missed out in earlier post

i hve modified the following also to be compatible for Pbuffer (addedÂ EGL\_PBUFFER\_BIT)

Â static const int ai32ConfigAttribs[] =  
Â {  
Â EGL\_RED\_SIZE, 5,  
Â EGL\_GREEN\_SIZE, 6,  
Â EGL\_BLUE\_SIZE, 5,  
Â EGL\_ALPHA\_SIZE, 0,  
Â EGL\_SURFACE\_TYPE, EGL\_WINDOW\_BIT|EGL\_PBUFFER\_BIT,  
Â EGL\_RENDERABLE\_TYPE, EGL\_OPENVG\_BIT,  
Â EGL\_NONE  
Â };

---

<div class="post-metadata">

**Author:** ![bujji00](https://avatars.discourse-cdn.com/v4/letter/b/d78d45/32.png) [@bujji00](https://forums.imgtec.com/u/bujji00)\
**Post date:** [August 17, 2009, 12:16pm UTC](https://forums.imgtec.com/t/demo-using-eglcreatepbuffersurface/447/3 "2009-08-17T12:16:47Z")

</div>

I am attaching the file after my changes

Thic works good if the macro Â DRAWABLES\_SIM\_USING\_2PBUFFER is disabled. If i enable this macro , Pbuffer is used.

If i change teh values of afClearColor,fillColor it is not refledcted in the app.

Please help me with this

Thnks

RK

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
  
Â @File OVGHelloTriangle\_Glut.cpp  
  
Â @Title OpenVG Intitalization Tutorial  
  
Â @Copyright Copyright (C) Imagination Technologies Limited.  
  
Â @Platform .  
  
Â @Description Basic Tutorial that shows step-by-step how to initialize OpenVG,  
Â use it for drawing a line, and terminate it.  
  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/  
#include "vg/openvg.h"  
#include "EGL/egl.h"  
#include \<gl/glut.h\>  
  
// No C++ Standard Library or exception handling on Symbian platform  
#include \<stdio.h\>  
#define DRAWABLES\_SIM\_USING\_2PBUFFER  
/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
\*\* Constants  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/  
const char pszAppName[] = "OpenVG Intialization Tutorial";  
int i32Frame = 0;  
EGLDisplay eglDisplay = 0;  
EGLSurface eglSurface = 0;  
#ifdef DRAWABLES\_SIM\_USING\_2PBUFFER  
EGLSurface eglSurface1 = 0;  
EGLContext eglContext = 0;  
#endif  
int i32WindowWidth = 240;  
int i32WindowHeight= 320;  
  
VGfloat afClearColor[4]={1.0f,0.0f,0.0f,1.0f};  
VGuint fillColor= 0x00FF00FF;  
  
VGPath vgTriangle;  
VGPaint vgFillPaint;  
/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
\*\* Declarations  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/  
  
void GlutDisplayHandler()  
{  
#ifdef DRAWABLES\_SIM\_USING\_2PBUFFER  
Â VGint imageWidth=0;  
Â VGint imageHeight=0;  
Â VGImage image;  
Â int i32NumConfigs1=0;  
Â EGLConfig eglConfig1 = 0;  
#endif  
Â if(i32Frame \> 1000)  
Â exit(0);  
  
Â // Set the clear color  
Â vgSetfv(VG\_CLEAR\_COLOR, 4, afClearColor);  
Â // Clear the whole surface with the clear color  
Â vgClear(0, 0, i32WindowWidth, i32WindowHeight);  
#ifdef DRAWABLES\_SIM\_USING\_2PBUFFER  
Â vgFinish();  
  
  
Â // create a VGImage  
Â imageWidth = 120;  
Â imageHeight= 160;  
Â image = vgCreateImage(VG\_sARGB\_8888\_PRE, imageWidth, imageHeight, VG\_IMAGE\_QUALITY\_BETTER );  
  
Â static const int ai32ConfigAttribs1[] =  
Â {  
Â EGL\_RED\_SIZE, 5,  
Â EGL\_GREEN\_SIZE, 6,  
Â EGL\_BLUE\_SIZE, 5,  
Â EGL\_ALPHA\_SIZE, 0,  
Â EGL\_SURFACE\_TYPE, EGL\_WINDOW\_BIT|EGL\_PBUFFER\_BIT,  
Â EGL\_RENDERABLE\_TYPE, EGL\_OPENVG\_BIT,  
Â EGL\_NONE  
Â };  
Â EGLint s\_surfaceAttribs1[] =  
Â { EGL\_WIDTH, 120,  
Â EGL\_HEIGHT, 160,  
Â EGL\_NONE  
Â };  
  
  
Â if(!eglChooseConfig(eglDisplay, ai32ConfigAttribs1, &eglConfig1, 1, &i32NumConfigs1) || (i32NumConfigs1 != 1))  
Â {  
Â printf("Error: eglChooseConfig() failed.n");  
Â exit(0);  
Â }  
  
Â eglSurface1 = eglCreatePbufferSurface(eglDisplay,eglConfig1,s\_surfaceAttribs1);  
  
Â if((eglGetError() != EGL\_SUCCESS) || (eglSurface1 == EGL\_NO\_SURFACE))  
Â {  
Â printf("Error: eglCreateWindowSurface() failed.n");  
Â exit(0);  
Â }  
  
Â eglMakeCurrent(eglDisplay, eglSurface1, eglSurface1, eglContext);  
Â if(eglGetError() != EGL\_SUCCESS)  
Â {  
Â printf("Error: eglMakeCurrent() failed.n");  
Â exit(0);  
Â }  
  
Â vgSeti(VG\_MATRIX\_MODE, VG\_MATRIX\_PATH\_USER\_TO\_SURFACE);  
Â vgLoadIdentity();  
Â vgScale((float)imageWidth, (float)imageHeight);  
  
Â vgTriangle = vgCreatePath(  
Â VG\_PATH\_FORMAT\_STANDARD,  
Â VG\_PATH\_DATATYPE\_F,  
Â 1.0f, 0.0f, 4, 3,  
Â (unsigned int)VG\_PATH\_CAPABILITY\_APPEND\_TO);  
  
Â VGubyte aui8PathSegments[4];  
Â aui8PathSegments[0] = VG\_MOVE\_TO\_ABS;  
Â aui8PathSegments[1] = VG\_LINE\_TO\_ABS;  
Â aui8PathSegments[2] = VG\_LINE\_TO\_ABS;  
Â aui8PathSegments[3] = VG\_CLOSE\_PATH;  
  
  
Â VGfloat afPoints[6];  
Â afPoints[0] = 0.3f;  
Â afPoints[1] = 0.3f;  
Â afPoints[2] = 0.7f;  
Â afPoints[3] = 0.3f;  
Â afPoints[4] = 0.5f;  
Â afPoints[5] = 0.7f;  
  
Â vgAppendPathData(vgTriangle, 4, aui8PathSegments, afPoints);  
  
  
Â vgRemovePathCapabilities(vgTriangle, VG\_PATH\_CAPABILITY\_APPEND\_TO);  
  
  
Â vgFillPaint = vgCreatePaint();  
Â vgSetParameteri(vgFillPaint, VG\_PAINT\_TYPE, VG\_PAINT\_TYPE\_COLOR);  
Â vgSetColor(vgFillPaint, fillColor);  
  
  
Â vgSetfv(VG\_CLEAR\_COLOR, 4, afClearColor);  
  
  
Â // Clear the whole surface with the clear color  
Â vgClear(0, 0, imageWidth, imageHeight);  
#endif  
Â // Set the current fill paint...  
Â vgSetPaint(vgFillPaint, VG\_FILL\_PATH);  
  
Â // Draw the triangle!  
Â vgDrawPath(vgTriangle, VG\_FILL\_PATH);  
#ifdef DRAWABLES\_SIM\_USING\_2PBUFFER  
Â vgFinish();  
  
Â vgGetPixels(image,0,0,0,0,imageWidth,imageHeight);  
  
Â vgFinish();  
  
Â vgDestroyPath(vgTriangle);  
  
Â eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext);  
Â if(eglGetError() != EGL\_SUCCESS)  
Â {  
Â printf("Error: eglMakeCurrent() failed.n");  
Â exit(0);  
Â }  
  
Â eglDestroySurface(eglDisplay,eglSurface1);  
Â if(eglGetError() != EGL\_SUCCESS)  
Â {  
Â printf("Error: eglMakeCurrent() failed.n");  
Â exit(0);  
Â }  
  
  
Â vgDrawImage(image);  
  
Â vgFinish();  
#endif  
  
Â /\*  
Â Drawing is double buffered, so you never see any intermediate  
Â results of the drawing. When you have finished drawing  
Â you have to call eglSwapBuffers to make the results appear on  
Â screen.  
Â \*/  
#ifndef DRAWABLES\_SIM\_USING\_2PBUFFER  
Â eglSwapBuffers(eglDisplay, eglSurface);  
#endif  
Â glutSwapBuffers();  
  
Â ++i32Frame;  
Â glutPostRedisplay();  
}  
  
void CleanupOnExit()  
{  
Â /\*  
Â Step 6 - Destroy resources  
Â

* * *
  
  
Â OpenVG resources like paths and paints need to be destroyed  
Â when they are no longer needed.  
Â \*/  
Â vgDestroyPath(vgTriangle);  
Â vgDestroyPaint(vgFillPaint);  
  
Â // Terminate OpenVG  
Â eglMakeCurrent(eglDisplay, EGL\_NO\_SURFACE, EGL\_NO\_SURFACE, EGL\_NO\_CONTEXT);  
Â eglTerminate(eglDisplay);  
}  
/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
\*\* Application entry point  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/  
int main(int argc, char \*argv[])  
{  
Â EGLConfig eglConfig = 0;  
#ifndef DRAWABLES\_SIM\_USING\_2PBUFFER  
Â EGLContext eglContext = 0;  
#endif  
Â int i32NumConfigs, i32MajorVersion, i32MinorVersion;  
  
Â /\*  
Â Step 0 - Create a window that we can use for OpenVG output  
  
Â Window creation is platform specific so it should be done by  
Â a separate function.  
Â \*/  
  
Â glutInit(&argc, argv);  
Â glutInitDisplayMode(GLUT\_DOUBLE | GLUT\_RGB);  
Â glutInitWindowSize(240, 320);  
Â glutInitWindowPosition(100, 100);  
  
Â int m\_glutWindow = glutCreateWindow("");  
  
Â if(!m\_glutWindow)  
Â {  
Â return 1;  
Â }  
  
Â glutDisplayFunc(GlutDisplayHandler);  
Â atexit(CleanupOnExit);  
  
Â /\*  
Â Step 1 - Get the default display  
  
Â EGL uses the concept of a "display" which in most environments  
Â corresponds to a single physical screen. Since we usually want  
Â to draw to the main screen or only have a single screen to begin  
Â with, we let EGL pick the default display.  
  
Â Querying other displays is platform specific.  
Â \*/  
Â eglDisplay = (NativeDisplayType)eglGetDisplay(EGL\_DEFAULT\_DISPLAY);  
  
Â /\*  
Â Step 2 - Initialize EGL  
  
Â EGL has to be initialized with the display obtained in the  
Â previous step. We cannot use other EGL functions except  
Â eglGetDisplay and eglGetError before eglInitialize has been  
Â called.  
Â If we're not interested in the EGL version number we can just  
Â pass NULL for the second and third parameters.  
Â \*/  
Â if(!eglInitialize(eglDisplay, &i32MajorVersion, &i32MinorVersion))  
Â {  
Â printf("Error: eglInitialize() failed.n");  
Â return 1;  
Â }  
  
Â /\*  
Â Step 3 - Make OpenVG the current API  
  
Â EGL provides ways to set up OpenGL ES and OpenVG contexts  
Â (and possibly other graphics APIs in the future), so we need  
Â to specify the "current API".  
Â \*/  
Â eglBindAPI(EGL\_OPENVG\_API);  
  
Â /\*  
Â Step 4 - Specify the required configuration attributes  
  
Â An EGL "configuration" describes the pixel format and type of  
Â surfaces that can be used for drawing.  
Â For now we just want to use a 16 bit RGB surface that is a  
Â window surface, i.e. it will be visible on screen. The list  
Â has to contain key/value pairs, terminated with EGL\_NONE.  
Â \*/  
Â static const int ai32ConfigAttribs[] =  
Â {  
Â EGL\_RED\_SIZE, 5,  
Â EGL\_GREEN\_SIZE, 6,  
Â EGL\_BLUE\_SIZE, 5,  
Â EGL\_ALPHA\_SIZE, 0,  
#ifndef DRAWABLES\_SIM\_USING\_2PBUFFER  
Â EGL\_SURFACE\_TYPE, EGL\_WINDOW\_BIT,  
#else  
Â EGL\_SURFACE\_TYPE, EGL\_WINDOW\_BIT|EGL\_PBUFFER\_BIT,  
#endif  
Â EGL\_RENDERABLE\_TYPE, EGL\_OPENVG\_BIT,  
Â EGL\_NONE  
Â };  
#ifdef DRAWABLES\_SIM\_USING\_2PBUFFER  
Â EGLint s\_surfaceAttribs[] =  
Â { EGL\_WIDTH, 240,  
Â EGL\_HEIGHT, 320,  
Â EGL\_NONE  
Â };  
#endif  
Â /\*  
Â Step 5 - Find a config that matches all requirements  
  
Â eglChooseConfig provides a list of all available configurations  
Â that meet or exceed the requirements given as the second  
Â argument. In most cases we just want the first config that meets  
Â all criteria, so we can limit the number of configs returned to 1.  
Â \*/  
Â if(!eglChooseConfig(eglDisplay, ai32ConfigAttribs, &eglConfig, 1, &i32NumConfigs) || (i32NumConfigs != 1))  
Â {  
Â printf("Error: eglChooseConfig() failed.n");  
Â exit(0);  
Â }  
  
Â /\*  
Â Step 6 - Create a window surface to draw to  
  
Â Use the config picked in the previous step and the native window  
Â handle to create a window surface. A window surface is one that  
Â will be visible on screen inside the native window (or  
Â fullscreen if there is no window system).  
  
Â Pixmaps and pbuffers are surfaces which only exist in off-screen  
Â memory.  
Â \*/  
#ifdef DRAWABLES\_SIM\_USING\_2PBUFFER  
Â eglSurface = eglCreatePbufferSurface(eglDisplay,eglConfig,s\_surfaceAttribs);  
#else  
Â eglSurface = eglCreateWindowSurface(eglDisplay, eglConfig,(void\*) m\_glutWindow, NULL);  
#endif  
Â if((eglGetError() != EGL\_SUCCESS) || (eglSurface == EGL\_NO\_SURFACE))  
Â {  
Â printf("Error: eglCreateWindowSurface() failed.n");  
Â exit(0);  
Â }  
  
Â /\*  
Â Step 7 - Create a context  
  
Â EGL has to create a context for OpenVG. Our OpenVG resources  
Â like paths and images will only be valid inside this context  
Â (or shared contexts)  
Â \*/  
Â eglContext = eglCreateContext(eglDisplay, eglConfig, NULL, NULL);  
Â if((eglGetError() != EGL\_SUCCESS) || (eglContext == EGL\_NO\_CONTEXT))  
Â {  
Â printf("Error: eglCreateContext() failed.n");  
Â exit(0);  
Â }  
  
Â /\*  
Â Step 8 - Bind the context to the current thread and use our  
Â window surface for drawing and reading  
  
Â Contexts are bound to a thread. This means you don't have to  
Â worry about other threads and processes interfering with your  
Â OpenVG application.  
Â We need to specify a surface that will be the target of all  
Â subsequent drawing operations, and one that will be the source  
Â of read operations. They can be the same surface.  
Â \*/  
Â eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext);  
Â if(eglGetError() != EGL\_SUCCESS)  
Â {  
Â printf("Error: eglMakeCurrent() failed.n");  
Â exit(0);  
Â }  
  
/\*  
Â Steps 1 to 4 - Prepare OpenVG to draw a triangle  
Â 
* * *
  
  
Â At this point we could theoretically start drawing with OpenVG. But  
Â we have to specify what to draw and how to draw it first.  
Â \*/  
  
Â /\*  
Â Step 1 - Set up a device independent coordinate system  
Â 
* * *
  
  
Â Initially, the OpenVG coordinate system is based on the output resolution.  
Â To get a device independent coordinate system, we need to apply a  
Â transformation: Scaling by the output resolution means that coordinates  
Â between (0, 0) and (1, 1) will be visible on screen, with the origin  
Â in the lower left corner.  
  
Â Transformations are described more in-depth in the Transforms tutorial.  
  
Â It should be noted that different aspect ratios often require  
Â special attention regarding the layout of elements on screen.  
Â \*/  
  
Â eglQuerySurface(eglDisplay, eglSurface, EGL\_WIDTH, &i32WindowWidth);  
Â eglQuerySurface(eglDisplay, eglSurface, EGL\_HEIGHT, &i32WindowHeight);  
#ifndef DRAWABLES\_SIM\_USING\_2PBUFFER  
Â vgSeti(VG\_MATRIX\_MODE, VG\_MATRIX\_PATH\_USER\_TO\_SURFACE);  
Â vgLoadIdentity();  
Â vgScale((float)i32WindowWidth, (float)i32WindowHeight);  
  
  
Â /\*  
Â Step 2 - Create a path  
Â 
* * *
  
Â Drawing shapes with OpenVG requires a path which represents a series of  
Â line and curve segments describing the outline of the shape. The shape  
Â does not need to be closed, but for now we will start with a simple  
Â triangle.  
Â First we create a path handle, then we append segment and point data.  
  
Â Creating a path involves choosing a datatype used for point data (we use  
Â float here, indicated by VG\_PATH\_DATATYPE\_F) and capabilities that we want  
Â to use. Picking the right capabilities is important as the OpenVG driver  
Â can use a more efficient and compact internal representation for paths  
Â with limited capabilities. We only need two capabilities for this tutorial:  
Â adding data to the path and drawing it, with the latter being implicitly  
Â enabled for all paths.  
Â \*/  
  
Â vgTriangle = vgCreatePath(  
Â VG\_PATH\_FORMAT\_STANDARD,  
Â VG\_PATH\_DATATYPE\_F,  
Â 1.0f, 0.0f, 4, 3,  
Â (unsigned int)VG\_PATH\_CAPABILITY\_APPEND\_TO);  
  
Â /\*  
Â The segments of a path are described as a series of commands, represented as  
Â an array of bytes. You can imagine the commands being performed by a pen:  
Â First the pen moves to a starting location without drawing, from there it  
Â draws a line to a second point. Then another line to a third point. After  
Â that, it closes the shape by drawing a line from the last point to the  
Â starting location: triangle finished!  
  
Â The suffixes \_ABS and \_REL attached to the commands indicate whether the  
Â coordinates are to be interpreted as absolute locations (seen from the  
Â origin)or as being relative to the location of the current point.  
Â \*/  
Â VGubyte aui8PathSegments[4];  
Â aui8PathSegments[0] = VG\_MOVE\_TO\_ABS;  
Â aui8PathSegments[1] = VG\_LINE\_TO\_ABS;  
Â aui8PathSegments[2] = VG\_LINE\_TO\_ABS;  
Â aui8PathSegments[3] = VG\_CLOSE\_PATH;  
  
Â /\*  
Â In addition to the array of commands, the path needs a list of points. A  
Â command can "consume" from 0 to 6 values, depending on its type. MOVE\_TO  
Â and LINE\_TO each take two values, CLOSE\_PATH takes none.  
Â A triangle requires 3 2D vertices.  
Â \*/  
Â VGfloat afPoints[6];  
Â afPoints[0] = 0.3f;  
Â afPoints[1] = 0.3f;  
Â afPoints[2] = 0.7f;  
Â afPoints[3] = 0.3f;  
Â afPoints[4] = 0.5f;  
Â afPoints[5] = 0.7f;  
  
Â /\*  
Â When appending data to the path, only the number of segments needs to be  
Â specified since the number of points used depends on the actual commands.  
Â \*/  
Â vgAppendPathData(vgTriangle, 4, aui8PathSegments, afPoints);  
  
Â /\*  
Â Path capabilities should be removed as soon as they are no longer needed.  
Â The OpenVG implementation might work more efficiently if it knows that  
Â path data will not change since it can use an optimized internal  
Â representation.  
Â \*/  
Â vgRemovePathCapabilities(vgTriangle, VG\_PATH\_CAPABILITY\_APPEND\_TO);  
  
  
Â /\*  
Â Step 3 - Create a paint  
Â 
* * *
  
Â To fill a shape, we need a paint that describes how to fill it: a gradient,  
Â pattern, or single color. Here we choose a paint with type COLOR that  
Â is a simple opaque red. vgSetColor is a shortcut function that takes a  
Â non-premultiplied sRGBA color encoded as a 32bit integer in RGBA\_8888 form.  
Â \*/  
Â vgFillPaint = vgCreatePaint();  
Â vgSetParameteri(vgFillPaint, VG\_PAINT\_TYPE, VG\_PAINT\_TYPE\_COLOR);  
Â vgSetColor(vgFillPaint, fillColor);  
  
Â /\*  
Â Step 4 - Prepare the render loop  
Â 
* * *
  
  
Â The clear color will be used whenever calling vgClear(). The color is given  
Â as non-premultiplied sRGBA, represented by four float values.  
Â \*/  
#endif  
Â // Set the clear color  
Â vgSetfv(VG\_CLEAR\_COLOR, 4, afClearColor);  
  
Â /\* Enter the main glut loop to render it.\*/  
Â glutMainLoop();  
  
Â // Say goodbye  
Â printf("%s finished.", pszAppName);  
Â return 0;  
}  
  
/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
Â End of file (Initialization.cpp)  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

---

<div class="post-metadata">

**Author:** ![hieuletrung](https://avatars.discourse-cdn.com/v4/letter/h/f05b48/32.png) [@hieuletrung](https://forums.imgtec.com/u/hieuletrung)\
**Post date:** [September 6, 2009, 2:55pm UTC](https://forums.imgtec.com/t/demo-using-eglcreatepbuffersurface/447/4 "2009-09-06T14:55:20Z")

</div>

You can’t use pbuffer to display on-screen since it is off-screen buffer. If you need to use pbuffer, you must bind it into a texture so that it can be displayed on-screen.  
  
Please see the EGL manual for more details  
  
-Hieu
