I have been trying to figure out pbuffers, WGL_ARB_render_texture, etc. in order to avoid doing:
glBindTexture(GL_TEXTURE_2D, texID);
glCopyTexSubImage2D(GL_TEXTURE_2D, …);
in multi-pass rendering.
I have read the WGL_ARB_pbuffer and WGL_ARB_render_texture specifications and found them confusing. Also, some kind person on this board directed me to a RenderTexture class written by Mark Harris (http://www.cs.unc.edu/~harrism/misc/rendertexture.html). I finally got his project going after changing all occurances of “wglew.” to “WGL_” and all “glew.” to “GL_” to reflect changes in the GLEW (needed for his project) interface. However, I have not been able to understand his code as it involves cg and other complexities.
I have tried to use his class in a trivially simple program to understand how to render to a non-frame-buffer buffer, then use that buffer as a texture for a subsequent render to the frame buffer. I have not succeeded.
Can someone show me how to get it up and running? Below is the program that I am trying to use with the RenderTexture class and GLEW. The simple program is just supposed to render a quad offscrean, then bind that offscrean buffer to a texture, then render a quad with that texture on screan. If I get red (from the glColor3f(1.0, 0.0, 0.0) call), it is evidence that it works. Instead I get blah:
#include “RenderTexture.h”
#include <GL/glut.h>
#include <cg/cgGL.h>
#include <stdio.h>
#include <stdlib.h>
#define iWidth 256
#define iHeight 256
RenderTexture *rt = NULL;
void Init()
{
glClearColor( 0.0, 0.0, 0.0, 0.0 );
glShadeModel( GL_FLAT );
rt = new RenderTexture(iWidth, iHeight, true, false);
rt->Initialize();
}
void reshape( int width, int height )
{
glViewport( 0, 0, (GLsizei) width, (GLsizei) height );
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-2.0, 2.0, -2.0, 2.0, 5.0, 10.0);
glMatrixMode( GL_MODELVIEW );
glLoadIdentity( );
gluLookAt(0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0);
}
void display()
{
glClear( GL_COLOR_BUFFER_BIT );
rt->EnableTextureTarget();
rt->BeginCapture();
float z_coord = 7;
glColor3f(1.0, 0.0, 0.0);
glBegin(GL_QUADS);
glVertex3f(-1,-1,z_coord);
glVertex3f(-1,1,z_coord);
glVertex3f(1,1,z_coord);
glVertex3f(1,-1,z_coord);
glEnd();
glFlush();
rt->EndCapture();
glBindTexture(GL_TEXTURE_2D, rt->GetTextureID());
glClear( GL_COLOR_BUFFER_BIT );
glBegin(GL_QUADS);
glTexCoord2f(0,0); glVertex3f(-1,-1,z_coord);
glTexCoord2f(0,1); glVertex3f(-1,1,z_coord);
glTexCoord2f(1,1); glVertex3f(1,1,z_coord);
glTexCoord2f(1,0); glVertex3f(1,-1,z_coord);
glEnd();
glFlush();
}
int main( int argc, char** argv )
{
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_SINGLE | GLUT_RGBA );
glutInitWindowPosition(50, 50);
glutInitWindowSize(iWidth, iHeight);
glutCreateWindow(“TestRenderTexture”);
int err = glewInit();
if (GLEW_OK != err)
{
// problem: glewInit failed, something is seriously wrong
fprintf(stderr, "GLEW Error: %s
", glewGetErrorString(err));
exit(-1);
}
Init();
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
[This message has been edited by sek (edited 09-18-2003).]
[This message has been edited by sek (edited 09-18-2003).]