# PBuffer render-to-texture problem...

**URL:** https://forums.imgtec.com/t/pbuffer-render-to-texture-problem/296
**Category:** PowerVR Insider
**Created:** [March 26, 2009, 7:32pm UTC](https://forums.imgtec.com/t/pbuffer-render-to-texture-problem/296 "2009-03-26T19:32:18Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![genpfaultgmail-com](https://avatars.discourse-cdn.com/v4/letter/g/53a042/32.png) [@genpfaultgmail-com](https://forums.imgtec.com/u/genpfaultgmail-com)
#### Post date: [March 26, 2009, 7:32pm UTC](https://forums.imgtec.com/t/pbuffer-render-to-texture-problem/296/1 "2009-03-26T19:32:18Z")

</div>

Using the win32 headers/binaries in OGLES-1.1\_WINDOWS\_PCEMULATION\_2.04.24.0811.msi, on a Radeon X1300:  
  
  
  
  
  
I’m trying to figure out render-to-texture using pbuffers and ran into a problem.  
  
  
  
  
  
With the code below pbw = pbh = 128 results in expected behavior:  
  
  
 ![](http://fsrv.dyndns.org/~genpfault/opengl_es/correct.png)  
  
  
  
  
  
Anything larger than the main window (pbw = pbh = 256 and up for a 320x240 window) seems to clip/clamp the texture to the main window dimensions:  
  
  
 ![](http://fsrv.dyndns.org/~genpfault/opengl_es/incorrect.png)  
  
  
  
  
  
Is there a problem with the code or is the SDK doing something odd? Or can pbuffers only be smaller than your main window/surface?  
  
  
  
  
  
  
  
#include \<iostream\>  
  
#include \<SDL/SDL.h\>  
  
#include \<SDL/SDL\_syswm.h\>  
  
  
  
#include \<GLES/egl.h\>  
  
#include \<GLES/gl.h\>  
  
  
  
using namespace std;  
  
  
  
int main(int argc, char\* argv[])  
  
{  
  
SDL\_Init(SDL\_INIT\_EVERYTHING);  
  
const int winw = 320;  
  
const int winh = 240;  
  
SDL\_SetVideoMode(winw, winh, 32, 0);  
  
  
  
// grab the window’s HWND  
  
static SDL\_SysWMinfo wmInfo;  
  
SDL\_VERSION( &wmInfo.version );  
  
SDL\_GetWMInfo( &wmInfo );  
  
  
  
NativeDisplayType nativeDisplay = (NativeDisplayType)GetDC(wmInfo.window);  
  
NativeWindowType nativeWindow = (NativeWindowType)wmInfo.window;  
  
  
  
const int pbw = 512;  
  
const int pbh = 512;  
  
  
  
EGLDisplay eglDisplay;  
  
EGLConfig eglConfig;  
  
EGLSurface eglSurface;  
  
EGLContext eglContext;  
  
  
  
eglDisplay = eglGetDisplay( nativeDisplay );  
  
eglInitialize(eglDisplay, NULL, NULL);  
  
EGLint attribs[] = {  
  
&nbsp;&nbsp;&nbsp;&nbsp;EGL\_RED\_SIZE,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5,  
  
&nbsp;&nbsp;&nbsp;&nbsp;EGL\_GREEN\_SIZE,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5,  
  
&nbsp;&nbsp;&nbsp;&nbsp;EGL\_BLUE\_SIZE,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5,  
  
&nbsp;&nbsp;&nbsp;&nbsp;EGL\_ALPHA\_SIZE,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0,  
  
&nbsp;&nbsp;&nbsp;&nbsp;EGL\_DEPTH\_SIZE,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;16,  
  
&nbsp;&nbsp;&nbsp;&nbsp;EGL\_MAX\_PBUFFER\_WIDTH,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pbw,  
  
&nbsp;&nbsp;&nbsp;&nbsp;EGL\_MAX\_PBUFFER\_HEIGHT,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pbh,  
  
&nbsp;&nbsp;&nbsp;&nbsp;EGL\_BIND\_TO\_TEXTURE\_RGBA,&nbsp;&nbsp;&nbsp;EGL\_TRUE,  
  
&nbsp;&nbsp;&nbsp;&nbsp;EGL\_SURFACE\_TYPE,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EGL\_WINDOW\_BIT | EGL\_PBUFFER\_BIT,  
  
&nbsp;&nbsp;&nbsp;&nbsp;EGL\_NONE,  
  
};  
  
int iConfigs = 0;  
  
eglChooseConfig(eglDisplay, attribs, &eglConfig, 1, &iConfigs);  
  
eglSurface = eglCreateWindowSurface(eglDisplay, eglConfig, nativeWindow, NULL);  
  
eglContext = eglCreateContext(eglDisplay, eglConfig, NULL, NULL);  
  
  
  
eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext);  
  
  
  
EGLint pbuffer\_attribs[] = {  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EGL\_WIDTH,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pbw,  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EGL\_HEIGHT,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pbh,  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EGL\_TEXTURE\_TARGET,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EGL\_TEXTURE\_2D,  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EGL\_TEXTURE\_FORMAT,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EGL\_TEXTURE\_RGBA,  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EGL\_NONE  
  
};  
  
EGLSurface pbuffer = eglCreatePbufferSurface(eglDisplay, eglConfig, pbuffer\_attribs);  
  
  
  
GLuint pbuffer\_texobj;  
  
glEnable(GL\_TEXTURE\_2D);  
  
glGenTextures(1, &pbuffer\_texobj);  
  
glBindTexture(GL\_TEXTURE\_2D, pbuffer\_texobj);  
  
glTexParameteri(GL\_TEXTURE\_2D, GL\_TEXTURE\_MIN\_FILTER, GL\_NEAREST);  
  
glTexParameteri(GL\_TEXTURE\_2D, GL\_TEXTURE\_MAG\_FILTER, GL\_NEAREST);  
  
glTexParameteri(GL\_TEXTURE\_2D, GL\_TEXTURE\_WRAP\_S, GL\_CLAMP\_TO\_EDGE);  
  
glTexParameteri(GL\_TEXTURE\_2D, GL\_TEXTURE\_WRAP\_T, GL\_CLAMP\_TO\_EDGE);  
  
  
  
  
  
// ES1.1 only allows 4-component colors  
  
GLfloat verts[] = {  
  
&nbsp;&nbsp;&nbsp;&nbsp;0.0f, 0.0f, 0.0f,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// pos  
  
&nbsp;&nbsp;&nbsp;&nbsp;1.0f, 0.0f, 0.0f, 1.0f,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// color  
  
&nbsp;&nbsp;&nbsp;&nbsp;1.0f, 0.0f, 0.0f,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// pos  
  
&nbsp;&nbsp;&nbsp;&nbsp;0.0f, 1.0f, 0.0f, 1.0f,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// color  
  
&nbsp;&nbsp;&nbsp;&nbsp;1.0f, 1.0f, 0.0f,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// pos  
  
&nbsp;&nbsp;&nbsp;&nbsp;0.0f, 0.0f, 1.0f, 1.0f,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// color  
  
&nbsp;&nbsp;&nbsp;&nbsp;};  
  
GLubyte index[] = {0, 1, 2};  
  
  
  
// textured quad  
  
GLfloat verts2[] = {  
  
&nbsp;&nbsp;&nbsp;&nbsp;0, 0, 0,  
  
&nbsp;&nbsp;&nbsp;&nbsp;0, 0,  
  
&nbsp;&nbsp;&nbsp;&nbsp;1, 0, 0,  
  
&nbsp;&nbsp;&nbsp;&nbsp;1, 0,  
  
&nbsp;&nbsp;&nbsp;&nbsp;1, 1, 0,  
  
&nbsp;&nbsp;&nbsp;&nbsp;1, 1,  
  
&nbsp;&nbsp;&nbsp;&nbsp;0, 1, 0,  
  
&nbsp;&nbsp;&nbsp;&nbsp;0, 1,  
  
&nbsp;&nbsp;&nbsp;&nbsp;};  
  
GLubyte index2[] = {0, 1, 3, 3, 1, 2};  
  
  
  
float size;  
  
  
  
bool running = true;  
  
SDL\_Event event;  
  
while( running )  
  
&nbsp;&nbsp;&nbsp;&nbsp;{  
  
&nbsp;&nbsp;&nbsp;&nbsp;// handle all pending events  
  
&nbsp;&nbsp;&nbsp;&nbsp;while( SDL\_PollEvent(&event) ) {  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; switch (event.type) {  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case SDL\_KEYDOWN: switch(event.key.keysym.sym) {  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case SDLK\_ESCAPE: running = false; break;  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default: break;  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} break;  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case SDL\_QUIT: running = false; break;  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default: break;  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }  
  
&nbsp;&nbsp;&nbsp;&nbsp;}  
  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;// render to texture bound to our pbuffer  
  
&nbsp;&nbsp;&nbsp;&nbsp;eglMakeCurrent(eglDisplay, pbuffer, pbuffer, eglContext);  
  
&nbsp;&nbsp;&nbsp;&nbsp;glViewport(0, 0, pbw, pbh);  
  
&nbsp;&nbsp;&nbsp;&nbsp;glClearColor(1,0,1,1);  
  
&nbsp;&nbsp;&nbsp;&nbsp;glClear(GL\_COLOR\_BUFFER\_BIT);  
  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;glMatrixMode(GL\_PROJECTION); glLoadIdentity();  
  
&nbsp;&nbsp;&nbsp;&nbsp;size = 0.6f;  
  
&nbsp;&nbsp;&nbsp;&nbsp;glOrthof(-size, size, -size, size, -1.0f, 1.0f);  
  
&nbsp;&nbsp;&nbsp;&nbsp;glMatrixMode(GL\_MODELVIEW); glLoadIdentity();  
  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;glEnableClientState(GL\_VERTEX\_ARRAY);  
  
&nbsp;&nbsp;&nbsp;&nbsp;glEnableClientState(GL\_COLOR\_ARRAY);  
  
&nbsp;&nbsp;&nbsp;&nbsp;glVertexPointer(3, GL\_FLOAT, sizeof(GLfloat)\*7, &verts[0]);  
  
&nbsp;&nbsp;&nbsp;&nbsp;glColorPointer(4, GL\_FLOAT, sizeof(GLfloat)\*7, &verts[3]);  
  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;glDisable(GL\_TEXTURE\_2D);  
  
&nbsp;&nbsp;&nbsp;&nbsp;glPushMatrix();  
  
&nbsp;&nbsp;&nbsp;&nbsp;glRotatef(SDL\_GetTicks() / 10.0f, 0, 0, 1);  
  
&nbsp;&nbsp;&nbsp;&nbsp;glTranslatef(-0.5f, -0.5f, 0);  
  
&nbsp;&nbsp;&nbsp;&nbsp;glDrawArrays(GL\_TRIANGLES, 0, 3);  
  
&nbsp;&nbsp;&nbsp;&nbsp;glPopMatrix();  
  
  
  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;// render textured quad using pbuffer texture  
  
&nbsp;&nbsp;&nbsp;&nbsp;eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext);  
  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;glBindTexture(GL\_TEXTURE\_2D, pbuffer\_texobj);  
  
&nbsp;&nbsp;&nbsp;&nbsp;eglBindTexImage(eglDisplay, pbuffer, EGL\_BACK\_BUFFER);  
  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;glViewport(0, 0, winw, winh);  
  
&nbsp;&nbsp;&nbsp;&nbsp;glClearColor(0,0,0,1);  
  
&nbsp;&nbsp;&nbsp;&nbsp;glClear(GL\_COLOR\_BUFFER\_BIT);  
  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;glMatrixMode(GL\_PROJECTION); glLoadIdentity();  
  
&nbsp;&nbsp;&nbsp;&nbsp;size = 0.8f;  
  
&nbsp;&nbsp;&nbsp;&nbsp;glOrthof(-size, size, -size, size, -1.0f, 1.0f);  
  
&nbsp;&nbsp;&nbsp;&nbsp;glMatrixMode(GL\_MODELVIEW); glLoadIdentity();  
  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;glDisableClientState(GL\_COLOR\_ARRAY);  
  
&nbsp;&nbsp;&nbsp;&nbsp;glEnableClientState(GL\_VERTEX\_ARRAY);  
  
&nbsp;&nbsp;&nbsp;&nbsp;glEnableClientState(GL\_TEXTURE\_COORD\_ARRAY);  
  
&nbsp;&nbsp;&nbsp;&nbsp;glVertexPointer(3, GL\_FLOAT, sizeof(GLfloat)\*5, &verts2[0]);  
  
&nbsp;&nbsp;&nbsp;&nbsp;glTexCoordPointer(2, GL\_FLOAT, sizeof(GLfloat)\*5, &verts2[3]);  
  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;glEnable(GL\_TEXTURE\_2D);  
  
&nbsp;&nbsp;&nbsp;&nbsp;glColor4f(1,1,1,1);  
  
&nbsp;&nbsp;&nbsp;&nbsp;glBindTexture(GL\_TEXTURE\_2D, pbuffer\_texobj);  
  
&nbsp;&nbsp;&nbsp;&nbsp;glPushMatrix();  
  
&nbsp;&nbsp;&nbsp;&nbsp;//glRotatef(-(float)SDL\_GetTicks() / 100.0f, 0, 0, 1);  
  
&nbsp;&nbsp;&nbsp;&nbsp;glTranslatef(-0.5f, -0.5f, 0);  
  
&nbsp;&nbsp;&nbsp;&nbsp;glDrawElements(GL\_TRIANGLES, 6, GL\_UNSIGNED\_BYTE, index2);  
  
&nbsp;&nbsp;&nbsp;&nbsp;glPopMatrix();  
  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;eglReleaseTexImage(eglDisplay, pbuffer, EGL\_BACK\_BUFFER);  
  
  
  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;glFlush();  
  
&nbsp;&nbsp;&nbsp;&nbsp;eglSwapBuffers(eglDisplay, eglSurface);  
  
&nbsp;&nbsp;&nbsp;&nbsp;SDL\_Delay(1);  
  
&nbsp;&nbsp;&nbsp;&nbsp;}  
  
  
  
eglReleaseTexImage(eglDisplay, pbuffer, EGL\_BACK\_BUFFER);  
  
eglDestroySurface(eglDisplay, pbuffer);  
  
glDeleteTextures(1, &pbuffer\_texobj);  
  
  
  
eglMakeCurrent(eglDisplay, EGL\_NO\_SURFACE, EGL\_NO\_SURFACE, EGL\_NO\_CONTEXT);  
  
eglTerminate(eglDisplay);  
  
  
  
SDL\_Quit();  
  
return 0;  
  
}  
  
[/CODE]`<br />
<br />#include &lt;iostream&gt;<br />
<br />#include &lt;SDL/SDL.h&gt;<br />
<br />#include &lt;SDL/SDL_syswm.h&gt;<br />
<br /><br />
<br />#include &lt;GLES/egl.h&gt;<br />
<br />#include &lt;GLES/gl.h&gt;<br />
<br /><br />
<br />using namespace std;<br />
<br /><br />
<br />int main(int argc, char* argv[])<br />
<br />{<br />
<br />SDL_Init(SDL_INIT_EVERYTHING);<br />
<br />const int winw = 320;<br />
<br />const int winh = 240;<br />
<br />SDL_SetVideoMode(winw, winh, 32, 0);<br />
<br /><br />
<br />// grab the window's HWND<br />
<br />static SDL_SysWMinfo wmInfo;<br />
<br />SDL_VERSION( &wmInfo.version );<br />
<br />SDL_GetWMInfo( &wmInfo );<br />
<br /><br />
<br />NativeDisplayType nativeDisplay = (NativeDisplayType)GetDC(wmInfo.window);<br />
<br />NativeWindowType nativeWindow = (NativeWindowType)wmInfo.window;<br />
<br /><br />
<br />const int pbw = 512;<br />
<br />const int pbh = 512;<br />
<br /><br />
<br />EGLDisplay eglDisplay;<br />
<br />EGLConfig eglConfig;<br />
<br />EGLSurface eglSurface;<br />
<br />EGLContext eglContext;<br />
<br /><br />
<br />eglDisplay = eglGetDisplay( nativeDisplay );<br />
<br />eglInitialize(eglDisplay, NULL, NULL);<br />
<br />EGLint attribs[] = {<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;EGL_RED_SIZE,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5,<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;EGL_GREEN_SIZE,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5,<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;EGL_BLUE_SIZE,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5,<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;EGL_ALPHA_SIZE,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0,<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;EGL_DEPTH_SIZE,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;16,<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;EGL_MAX_PBUFFER_WIDTH,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pbw,<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;EGL_MAX_PBUFFER_HEIGHT,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pbh,<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;EGL_BIND_TO_TEXTURE_RGBA,&nbsp;&nbsp;&nbsp;EGL_TRUE,<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;EGL_SURFACE_TYPE,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EGL_WINDOW_BIT | EGL_PBUFFER_BIT,<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;EGL_NONE,<br />
<br />};<br />
<br />int iConfigs = 0;<br />
<br />eglChooseConfig(eglDisplay, attribs, &eglConfig, 1, &iConfigs);<br />
<br />eglSurface = eglCreateWindowSurface(eglDisplay, eglConfig, nativeWindow, NULL);<br />
<br />eglContext = eglCreateContext(eglDisplay, eglConfig, NULL, NULL);<br />
<br /><br />
<br />eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext);<br />
<br /><br />
<br />EGLint pbuffer_attribs[] = {<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EGL_WIDTH,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pbw,<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EGL_HEIGHT,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pbh,<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EGL_TEXTURE_TARGET,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EGL_TEXTURE_2D,<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EGL_TEXTURE_FORMAT,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EGL_TEXTURE_RGBA,<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EGL_NONE<br />
<br />};<br />
<br />EGLSurface pbuffer = eglCreatePbufferSurface(eglDisplay, eglConfig, pbuffer_attribs);<br />
<br /><br />
<br />GLuint pbuffer_texobj;<br />
<br />glEnable(GL_TEXTURE_2D);<br />
<br />glGenTextures(1, &pbuffer_texobj);<br />
<br />glBindTexture(GL_TEXTURE_2D, pbuffer_texobj);<br />
<br />glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);<br />
<br />glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);<br />
<br />glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);<br />
<br />glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);<br />
<br /><br />
<br /><br />
<br />// ES1.1 only allows 4-component colors<br />
<br />GLfloat verts[] = {<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;0.0f, 0.0f, 0.0f,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// pos<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;1.0f, 0.0f, 0.0f, 1.0f,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// color<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;1.0f, 0.0f, 0.0f,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// pos<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;0.0f, 1.0f, 0.0f, 1.0f,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// color<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;1.0f, 1.0f, 0.0f,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// pos<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;0.0f, 0.0f, 1.0f, 1.0f,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// color<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;};<br />
<br />GLubyte index[] = {0, 1, 2};<br />
<br /><br />
<br />// textured quad<br />
<br />GLfloat verts2[] = {<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;0, 0, 0,<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;0, 0,<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;1, 0, 0,<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;1, 0,<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;1, 1, 0,<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;1, 1,<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;0, 1, 0,<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;0, 1,<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;};<br />
<br />GLubyte index2[] = {0, 1, 3, 3, 1, 2};<br />
<br /><br />
<br />float size;<br />
<br /><br />
<br />bool running = true;<br />
<br />SDL_Event event;<br />
<br />while( running )<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;// handle all pending events<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;while( SDL_PollEvent(&event) ) {<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; switch (event.type) {<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case SDL_KEYDOWN: switch(event.key.keysym.sym) {<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case SDLK_ESCAPE: running = false; break;<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default: break;<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} break;<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case SDL_QUIT: running = false; break;<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default: break;<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br /><br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;// render to texture bound to our pbuffer<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;eglMakeCurrent(eglDisplay, pbuffer, pbuffer, eglContext);<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;glViewport(0, 0, pbw, pbh);<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;glClearColor(1,0,1,1);<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;glClear(GL_COLOR_BUFFER_BIT);<br />
<br /><br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;glMatrixMode(GL_PROJECTION); glLoadIdentity();<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;size = 0.6f;<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;glOrthof(-size, size, -size, size, -1.0f, 1.0f);<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;glMatrixMode(GL_MODELVIEW); glLoadIdentity();<br />
<br /><br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;glEnableClientState(GL_VERTEX_ARRAY);<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;glEnableClientState(GL_COLOR_ARRAY);<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;glVertexPointer(3, GL_FLOAT, sizeof(GLfloat)*7, &verts[0]);<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;glColorPointer(4, GL_FLOAT, sizeof(GLfloat)*7, &verts[3]);<br />
<br /><br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;glDisable(GL_TEXTURE_2D);<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;glPushMatrix();<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;glRotatef(SDL_GetTicks() / 10.0f, 0, 0, 1);<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;glTranslatef(-0.5f, -0.5f, 0);<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;glDrawArrays(GL_TRIANGLES, 0, 3);<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;glPopMatrix();<br />
<br /><br />
<br /><br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;// render textured quad using pbuffer texture<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext);<br />
<br /><br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;glBindTexture(GL_TEXTURE_2D, pbuffer_texobj);<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;eglBindTexImage(eglDisplay, pbuffer, EGL_BACK_BUFFER);<br />
<br /><br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;glViewport(0, 0, winw, winh);<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;glClearColor(0,0,0,1);<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;glClear(GL_COLOR_BUFFER_BIT);<br />
<br /><br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;glMatrixMode(GL_PROJECTION); glLoadIdentity();<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;size = 0.8f;<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;glOrthof(-size, size, -size, size, -1.0f, 1.0f);<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;glMatrixMode(GL_MODELVIEW); glLoadIdentity();<br />
<br /><br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;glDisableClientState(GL_COLOR_ARRAY);<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;glEnableClientState(GL_VERTEX_ARRAY);<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;glEnableClientState(GL_TEXTURE_COORD_ARRAY);<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;glVertexPointer(3, GL_FLOAT, sizeof(GLfloat)*5, &verts2[0]);<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;glTexCoordPointer(2, GL_FLOAT, sizeof(GLfloat)*5, &verts2[3]);<br />
<br /><br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;glEnable(GL_TEXTURE_2D);<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;glColor4f(1,1,1,1);<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;glBindTexture(GL_TEXTURE_2D, pbuffer_texobj);<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;glPushMatrix();<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;//glRotatef(-(float)SDL_GetTicks() / 100.0f, 0, 0, 1);<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;glTranslatef(-0.5f, -0.5f, 0);<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, index2);<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;glPopMatrix();<br />
<br /><br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;eglReleaseTexImage(eglDisplay, pbuffer, EGL_BACK_BUFFER);<br />
<br /><br />
<br /><br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;glFlush();<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;eglSwapBuffers(eglDisplay, eglSurface);<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;SDL_Delay(1);<br />
<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br /><br />
<br />eglReleaseTexImage(eglDisplay, pbuffer, EGL_BACK_BUFFER);<br />
<br />eglDestroySurface(eglDisplay, pbuffer);<br />
<br />glDeleteTextures(1, &pbuffer_texobj);<br />
<br /><br />
<br />eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);<br />
<br />eglTerminate(eglDisplay);<br />
<br /><br />
<br />SDL_Quit();<br />
<br />return 0;<br />
<br />}<br />
<br />`
