Results 1 to 2 of 2

Thread: Backbuffer as Texture

  1. #1

    Backbuffer as Texture

    hi,

    im trying to draw something on my backbuffer, save it as a texture, and then put the texture in a simple plane. here is the snipplet of my code:

    Code :
    void display() {
     
    	glClearColor(1.0, 1.0, 1.0, 0);
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
    	glPushAttrib(GL_COLOR_BUFFER_BIT | GL_PIXEL_MODE_BIT);
    	glDrawBuffer(GL_BACK);
    	glReadBuffer(GL_BACK);
     
    	drawOrbit();
     
    	glBindTexture(GL_TEXTURE_2D, img);
    	glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, width, height);
    	glBindTexture(GL_TEXTURE_2D, 0);
     
    	glPopAttrib(); 
     
     
    	glClearColor(1.0, 1.0, 1.0, 0);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
     
    	glLoadIdentity();
     
    	//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
     
    	glTranslatef(0, 0, -1.5f);
    	glTranslatef(0, 0, -zoom);
     
    	glBindTexture(GL_TEXTURE_2D, img);
    	glBegin(GL_QUADS);
    	{
    		glNormal3f(0.0, 0.0, 1.0);
    		glTexCoord2f(1, 1);  glVertex3f(1,1,0);
            glTexCoord2f(0, 1);  glVertex3f(-1,1,0);
            glTexCoord2f(0, 0);  glVertex3f(-1,-1,0);
            glTexCoord2f(1, 0);  glVertex3f(1,-1,0);
    	}
    	glEnd();
    	glBindTexture(GL_TEXTURE_2D, 0);
    	//glFlush();
    	glutSwapBuffers();
    }

    the drawOrbit() method is simply drawing to the screen and works properly. however i can see the result on my screen. it simply draw the plane with default color. i use variable img as my texture ide, here is when i set my texture:

    Code :
    glGenTextures(1, &img);
    	glBindTexture(GL_TEXTURE_2D, img);
    	glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
     
        glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST );
        glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    	glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_REPEAT);
        glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_REPEAT);
    	glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
     
    	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, 
    				 GL_UNSIGNED_BYTE, NULL);
    	glBindTexture(GL_TEXTURE_2D, 0);

    did i miss anything? how can i make it works?

    thanks in advance

  2. #2
    Newbie Frequent Contributor
    Join Date
    Mar 2016
    Posts
    896

    Re: Backbuffer as Texture

    Before drawing your textured plane you need to enable texturing:

    Code :
    glEnable(GL_TEXTURE_2D);

Similar Threads

  1. How to copy backbuffer contents into a texture?
    By glSun in forum OpenGL: Basic Coding
    Replies: 16
    Last Post: 08-28-2010, 02:29 AM
  2. OpenGL BackBuffer
    By gelo in forum OpenGL: Windows
    Replies: 3
    Last Post: 07-25-2004, 01:56 PM
  3. Howto create a Texture out of backbuffer?
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-14-2003, 05:30 AM
  4. Can I use backbuffer as a texture? How to do?
    By hedgehog70 in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 03-03-2003, 06:34 AM
  5. Accessing a DC's backbuffer
    By Punchey in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 11-09-2000, 09:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean