OpenGL - rendering to texture

I want to be able to visualize something in a texture, on OpenGL, so I can use it whenever I want, without displaying everything again. This site here gave me recommendations for this without using FrameBuffer. I do not want to do this with the FrameBuffer object due to compatibility issues, as this old machine does not support it. I made some code that creates my texture, displays my scene, and then I create a Quad to render the texture on it. The only problem is that the texture is rendered as an "Alpha Mask", which means that it only takes into account the Alpha Value, keeping my rectangle always the same color, but just changing the transparency of the pixels. Here is the code I've done so far:

void CreateTexture ()
{
    xSize = 512;
    ySize = 512; //size of texture
//new array
    char* colorBits = new char[ xSize * ySize * 3 ];
//texture creation..
    glGenTextures(1,&texture);
    glBindTexture(GL_TEXTURE_2D,texture);
    glTexImage2D(GL_TEXTURE_2D,0 ,3 , xSize,
                 ySize, 0 , GL_RGB,
                 GL_UNSIGNED_BYTE, colorBits);
//you can set other texture parameters if you want
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
//clean up
    delete[] colorBits;
}

Then:

int viewport[4];
    glGetIntegerv(GL_VIEWPORT,(int*)viewport);
    glViewport(0,0,xSize,ySize);


    DrawScene(hDC);

    //save data to texture using glCopyTexImage2D
    glBindTexture(GL_TEXTURE_2D,texture);

    glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
                     0,0, xSize, ySize, 0);
    glClearColor(.0f, 0.5f, 0.5f, 1.0f);                // Set The Clear Color To Medium Blue
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glViewport(viewport[0],viewport[1],viewport[2],viewport[3]);
    // glBindTexture(GL_TEXTURE_2D,texture);

And finally:

glEnable(GL_TEXTURE_2D);                    // Enable 2D Texture Mapping
        glBlendFunc(GL_DST_COLOR,GL_ONE);               // Set Blending Mode
        glEnable(GL_BLEND);

        glClear(GL_COLOR_BUFFER_BIT);
        glBindTexture(GL_TEXTURE_2D,texture);

        glRotatef(theta, 0.0f, 0.0f, 0.01f);
        glBegin(GL_QUADS);
         //Front Face
        glTexCoord2f(0.0f, 0.0f);
        glVertex3f(-0.5, -0.5f,  0.5f);
        glTexCoord2f(1.0f, 0.0f);
        glVertex3f( 0.5f, -0.5f,  0.5f);
        glTexCoord2f(1.0f, 1.0f);
        glVertex3f( 0.5f,  0.5f,  0.5f);
        glTexCoord2f(0.0f, 1.0f);
        glVertex3f(-0.5f,  0.5f,  0.5f);
        glEnd();
        SwapBuffers(hDC);

DrawScene() , .. .

glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT );//| GL_DEPTH_BUFFER_BIT);

glPushMatrix();
//    glRotatef(theta, 0.0f, 0.0f, 1.0f);

glBegin(GL_QUADS);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(-1.0f, -1.0f,  1.0f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f( 1.0f, -1.0f,  1.0f);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex3f( 1.0f,  1.0f,  1.0f);
glColor3f(1.0f, 1.0f, 1.0f);
glVertex3f(-1.0f,  1.0f,  1.0f);
glEnd();

glBegin(GL_TRIANGLES);

glColor3f(1.0f, 0.0f, 0.0f);
glVertex2f(0.0f,   1.0f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex2f(0.87f,  -0.5f);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex2f(-0.87f, -0.5f);
glEnd();
glPopMatrix();
+5
2

- - nVidia, , , FBO:

http://developer.download.nvidia.com/SDK/9.5/Samples/samples.html

- "Simple P-Buffer", P-. , pBuffer, , . glReadPixels pBuffer (GLubyte). , , glReadPixels .

+4

All Articles