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:
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:
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[] = {
EGL_RED_SIZE, 5,
EGL_GREEN_SIZE, 5,
EGL_BLUE_SIZE, 5,
EGL_ALPHA_SIZE, 0,
EGL_DEPTH_SIZE, 16,
EGL_MAX_PBUFFER_WIDTH, pbw,
EGL_MAX_PBUFFER_HEIGHT, pbh,
EGL_BIND_TO_TEXTURE_RGBA, EGL_TRUE,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT,
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[] = {
EGL_WIDTH, pbw,
EGL_HEIGHT, pbh,
EGL_TEXTURE_TARGET, EGL_TEXTURE_2D,
EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGBA,
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[] = {
0.0f, 0.0f, 0.0f, // pos
1.0f, 0.0f, 0.0f, 1.0f, // color
1.0f, 0.0f, 0.0f, // pos
0.0f, 1.0f, 0.0f, 1.0f, // color
1.0f, 1.0f, 0.0f, // pos
0.0f, 0.0f, 1.0f, 1.0f, // color
};
GLubyte index[] = {0, 1, 2};
// textured quad
GLfloat verts2[] = {
0, 0, 0,
0, 0,
1, 0, 0,
1, 0,
1, 1, 0,
1, 1,
0, 1, 0,
0, 1,
};
GLubyte index2[] = {0, 1, 3, 3, 1, 2};
float size;
bool running = true;
SDL_Event event;
while( running )
{
// handle all pending events
while( SDL_PollEvent(&event) ) {
switch (event.type) {
case SDL_KEYDOWN: switch(event.key.keysym.sym) {
case SDLK_ESCAPE: running = false; break;
default: break;
} break;
case SDL_QUIT: running = false; break;
default: break;
}
}
// render to texture bound to our pbuffer
eglMakeCurrent(eglDisplay, pbuffer, pbuffer, eglContext);
glViewport(0, 0, pbw, pbh);
glClearColor(1,0,1,1);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION); glLoadIdentity();
size = 0.6f;
glOrthof(-size, size, -size, size, -1.0f, 1.0f);
glMatrixMode(GL_MODELVIEW); glLoadIdentity();
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(GLfloat)*7, &verts[0]);
glColorPointer(4, GL_FLOAT, sizeof(GLfloat)*7, &verts[3]);
glDisable(GL_TEXTURE_2D);
glPushMatrix();
glRotatef(SDL_GetTicks() / 10.0f, 0, 0, 1);
glTranslatef(-0.5f, -0.5f, 0);
glDrawArrays(GL_TRIANGLES, 0, 3);
glPopMatrix();
// render textured quad using pbuffer texture
eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext);
glBindTexture(GL_TEXTURE_2D, pbuffer_texobj);
eglBindTexImage(eglDisplay, pbuffer, EGL_BACK_BUFFER);
glViewport(0, 0, winw, winh);
glClearColor(0,0,0,1);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION); glLoadIdentity();
size = 0.8f;
glOrthof(-size, size, -size, size, -1.0f, 1.0f);
glMatrixMode(GL_MODELVIEW); glLoadIdentity();
glDisableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(GLfloat)*5, &verts2[0]);
glTexCoordPointer(2, GL_FLOAT, sizeof(GLfloat)*5, &verts2[3]);
glEnable(GL_TEXTURE_2D);
glColor4f(1,1,1,1);
glBindTexture(GL_TEXTURE_2D, pbuffer_texobj);
glPushMatrix();
//glRotatef(-(float)SDL_GetTicks() / 100.0f, 0, 0, 1);
glTranslatef(-0.5f, -0.5f, 0);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, index2);
glPopMatrix();
eglReleaseTexImage(eglDisplay, pbuffer, EGL_BACK_BUFFER);
glFlush();
eglSwapBuffers(eglDisplay, eglSurface);
SDL_Delay(1);
}
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 <iostream><br />
<br />#include <SDL/SDL.h><br />
<br />#include <SDL/SDL_syswm.h><br />
<br /><br />
<br />#include <GLES/egl.h><br />
<br />#include <GLES/gl.h><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 /> EGL_RED_SIZE, 5,<br />
<br /> EGL_GREEN_SIZE, 5,<br />
<br /> EGL_BLUE_SIZE, 5,<br />
<br /> EGL_ALPHA_SIZE, 0,<br />
<br /> EGL_DEPTH_SIZE, 16,<br />
<br /> EGL_MAX_PBUFFER_WIDTH, pbw,<br />
<br /> EGL_MAX_PBUFFER_HEIGHT, pbh,<br />
<br /> EGL_BIND_TO_TEXTURE_RGBA, EGL_TRUE,<br />
<br /> EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT,<br />
<br /> 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 /> EGL_WIDTH, pbw,<br />
<br /> EGL_HEIGHT, pbh,<br />
<br /> EGL_TEXTURE_TARGET, EGL_TEXTURE_2D,<br />
<br /> EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGBA,<br />
<br /> 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 /> 0.0f, 0.0f, 0.0f, // pos<br />
<br /> 1.0f, 0.0f, 0.0f, 1.0f, // color<br />
<br /> 1.0f, 0.0f, 0.0f, // pos<br />
<br /> 0.0f, 1.0f, 0.0f, 1.0f, // color<br />
<br /> 1.0f, 1.0f, 0.0f, // pos<br />
<br /> 0.0f, 0.0f, 1.0f, 1.0f, // color<br />
<br /> };<br />
<br />GLubyte index[] = {0, 1, 2};<br />
<br /><br />
<br />// textured quad<br />
<br />GLfloat verts2[] = {<br />
<br /> 0, 0, 0,<br />
<br /> 0, 0,<br />
<br /> 1, 0, 0,<br />
<br /> 1, 0,<br />
<br /> 1, 1, 0,<br />
<br /> 1, 1,<br />
<br /> 0, 1, 0,<br />
<br /> 0, 1,<br />
<br /> };<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 /> {<br />
<br /> // handle all pending events<br />
<br /> while( SDL_PollEvent(&event) ) {<br />
<br /> switch (event.type) {<br />
<br /> case SDL_KEYDOWN: switch(event.key.keysym.sym) {<br />
<br /> case SDLK_ESCAPE: running = false; break;<br />
<br /> default: break;<br />
<br /> } break;<br />
<br /> case SDL_QUIT: running = false; break;<br />
<br /> default: break;<br />
<br /> }<br />
<br /> }<br />
<br /><br />
<br /> // render to texture bound to our pbuffer<br />
<br /> eglMakeCurrent(eglDisplay, pbuffer, pbuffer, eglContext);<br />
<br /> glViewport(0, 0, pbw, pbh);<br />
<br /> glClearColor(1,0,1,1);<br />
<br /> glClear(GL_COLOR_BUFFER_BIT);<br />
<br /><br />
<br /> glMatrixMode(GL_PROJECTION); glLoadIdentity();<br />
<br /> size = 0.6f;<br />
<br /> glOrthof(-size, size, -size, size, -1.0f, 1.0f);<br />
<br /> glMatrixMode(GL_MODELVIEW); glLoadIdentity();<br />
<br /><br />
<br /> glEnableClientState(GL_VERTEX_ARRAY);<br />
<br /> glEnableClientState(GL_COLOR_ARRAY);<br />
<br /> glVertexPointer(3, GL_FLOAT, sizeof(GLfloat)*7, &verts[0]);<br />
<br /> glColorPointer(4, GL_FLOAT, sizeof(GLfloat)*7, &verts[3]);<br />
<br /><br />
<br /> glDisable(GL_TEXTURE_2D);<br />
<br /> glPushMatrix();<br />
<br /> glRotatef(SDL_GetTicks() / 10.0f, 0, 0, 1);<br />
<br /> glTranslatef(-0.5f, -0.5f, 0);<br />
<br /> glDrawArrays(GL_TRIANGLES, 0, 3);<br />
<br /> glPopMatrix();<br />
<br /><br />
<br /><br />
<br /> // render textured quad using pbuffer texture<br />
<br /> eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext);<br />
<br /><br />
<br /> glBindTexture(GL_TEXTURE_2D, pbuffer_texobj);<br />
<br /> eglBindTexImage(eglDisplay, pbuffer, EGL_BACK_BUFFER);<br />
<br /><br />
<br /> glViewport(0, 0, winw, winh);<br />
<br /> glClearColor(0,0,0,1);<br />
<br /> glClear(GL_COLOR_BUFFER_BIT);<br />
<br /><br />
<br /> glMatrixMode(GL_PROJECTION); glLoadIdentity();<br />
<br /> size = 0.8f;<br />
<br /> glOrthof(-size, size, -size, size, -1.0f, 1.0f);<br />
<br /> glMatrixMode(GL_MODELVIEW); glLoadIdentity();<br />
<br /><br />
<br /> glDisableClientState(GL_COLOR_ARRAY);<br />
<br /> glEnableClientState(GL_VERTEX_ARRAY);<br />
<br /> glEnableClientState(GL_TEXTURE_COORD_ARRAY);<br />
<br /> glVertexPointer(3, GL_FLOAT, sizeof(GLfloat)*5, &verts2[0]);<br />
<br /> glTexCoordPointer(2, GL_FLOAT, sizeof(GLfloat)*5, &verts2[3]);<br />
<br /><br />
<br /> glEnable(GL_TEXTURE_2D);<br />
<br /> glColor4f(1,1,1,1);<br />
<br /> glBindTexture(GL_TEXTURE_2D, pbuffer_texobj);<br />
<br /> glPushMatrix();<br />
<br /> //glRotatef(-(float)SDL_GetTicks() / 100.0f, 0, 0, 1);<br />
<br /> glTranslatef(-0.5f, -0.5f, 0);<br />
<br /> glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, index2);<br />
<br /> glPopMatrix();<br />
<br /><br />
<br /> eglReleaseTexImage(eglDisplay, pbuffer, EGL_BACK_BUFFER);<br />
<br /><br />
<br /><br />
<br /> glFlush();<br />
<br /> eglSwapBuffers(eglDisplay, eglSurface);<br />
<br /> SDL_Delay(1);<br />
<br /> }<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 />