Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: Screenshot to texture

  1. #1
    Member Contributor
    Join Date
    May 2011
    Location
    Alabama, USA
    Posts
    66

    Screenshot to texture

    I know I've already posted a question about this but I'm still having trouble. What I want to do is capture the screen, dump it into a texture, and then texture a sphere with it. I've tried using glReadPixels, FBOs, glGenerateMipmap, and the glCoprTex* functions. Nothing seems to work properly. Is there anybody who can tell me how I might accomplish doing what I'm trying to do?
    Benjamin Barrett aka vindy
    "Our knowledge is finite, while our ignorance is infinite!"

  2. #2
    Senior Member Regular Contributor
    Join Date
    Nov 2010
    Location
    Brazil, Rio de Janeiro
    Posts
    147

    Re: Screenshot to texture

    Actually you don't need a FBO for this, but it is a fast and practical way. What in this page isn't working?

    http://www.songho.ca/opengl/gl_fbo.html

    Theres also an example of how to texture an object.

  3. #3
    Member Contributor
    Join Date
    May 2011
    Location
    Alabama, USA
    Posts
    66

    Re: Screenshot to texture

    Cool! Its working! Thanks man. However its a little slow. I know how I can speed it up but I need to know where the vertex coordinates stop on the x and y axes. Would anybody out there know how to find out? I know, its lame that I don't already know how to do this.
    Benjamin Barrett aka vindy
    "Our knowledge is finite, while our ignorance is infinite!"

  4. #4
    Member Contributor
    Join Date
    May 2011
    Location
    Alabama, USA
    Posts
    66

    Re: Screenshot to texture

    Nevermind the previous question. I figued it out. Now I have another question. Why can't I take that texture that has my screen shot and slap it back to the screen with one big quad? I don't know where I'm going wrong. It textures the sphere no problem but I can't get it to map to the entire screen. I'm trying to speed things up here.
    Benjamin Barrett aka vindy
    "Our knowledge is finite, while our ignorance is infinite!"

  5. #5
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Posts
    4,654

    Re: Screenshot to texture

    Quote Originally Posted by vindy
    Now I have another question. Why can't I take that texture that has my screen shot and slap it back to the screen with one big quad? I don't know where I'm going wrong. It textures the sphere no problem but I can't get it to map to the entire screen. I'm trying to speed things up here.
    Let's see some code. Show us how you're binding the texture, and building the batch (draw call) for that GL QUAD.

  6. #6
    Member Contributor
    Join Date
    May 2011
    Location
    Alabama, USA
    Posts
    66

    Re: Screenshot to texture

    void genFBOtexture(void)
    {
    glBindTexture(GL_TEXTURE_2D, tex);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); // automatic mipmap
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
    glBindTexture(GL_TEXTURE_2D, 0);

    // create a renderbuffer object to store depth info
    GLuint rboId;
    glGenRenderbuffersEXT(1, &rboId);
    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rboId);
    glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, 512, 512);
    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);

    // create a framebuffer object
    GLuint fboId;
    glGenFramebuffersEXT(1, &fboId);
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboId);

    // attach the texture to FBO color attachment point
    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, tex, 0);

    // attach the renderbuffer to depth attachment point
    glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, rboId);

    /*this is where I draw all of my scene with the exception of the sphere. too much code right here to post*/

    // unbind FBO
    glDeleteRenderbuffersEXT(1, &rboId);
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
    }

    void drawSphere(void)
    {
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glBindTexture(GL_TEXTURE_2D, tex);
    glGenerateMipmapEXT(GL_TEXTURE_2D);

    glEnable(GL_DEPTH_TEST);
    glEnable(GL_LIGHTING);

    glEnable(GL_TEXTURE_2D);

    glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
    glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
    glEnable(GL_TEXTURE_GEN_S);
    glEnable(GL_TEXTURE_GEN_T);

    //glLoadIdentity();
    glTranslatef(0.0f, 5.0f, -25.0f);

    glNormal3f(0.0f, 0.0f, 1.0f);
    glutSolidSphere(5.0f, 25, 25);

    glDisable(GL_TEXTURE_GEN_S);
    glDisable(GL_TEXTURE_GEN_T);

    glDisable(GL_TEXTURE_2D);
    glColor3f(1.0f, 1.0f, 1.0f);

    glDisable(GL_DEPTH_TEST);
    glDisable(GL_LIGHTING);
    }

    void drawScene() {

    genFBOtexture();

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glEnable(GL_DEPTH_TEST);

    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, tex);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

    glBegin(GL_QUADS);

    glNormal3f(0.0f, 0.0f, 1.0f);
    glTexCoord2f(1.0f, 0.0f);
    glVertex3f(2.5f, -2.5f, 0.0f);
    glTexCoord2f(0.0f, 0.0f);
    glVertex3f(-2.5f, -2.5f, 0.0f);
    glTexCoord2f(0.0f, 1.0f);
    glVertex3f(-2.5f, 2.5f, 0.0f);
    glTexCoord2f(1.0f, 1.0f);
    glVertex3f(2.5f, 2.5f, 0.0f);

    glEnd();

    glDisable(GL_DEPTH_TEST);
    glDisable(GL_TEXTURE_2D);

    drawSphere();

    glutSwapBuffers();
    }

    //I hope this is all you need. Thanks for the help.
    Benjamin Barrett aka vindy
    "Our knowledge is finite, while our ignorance is infinite!"

  7. #7
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Posts
    4,654

    Re: Screenshot to texture

    Well I don't see a glGenTextures( 1, &tex ), but I assume you've got it elsewhere.

    First thing that jumps out at me is that, while you are loading an Identity MODELVIEW, you're not loading a projection matrix before drawing that quad. You probably want something like:

    Code :
    glMatrixMode( GL_PROJECTION );
    glOrtho( -2.5, 2.5, -2.5, 2.5, -1, 1 );

    Also, you probably want to disable DEPTH_TEST before you draw it, because the depth buffer will be nonsensical for rendering the quad in a different projection.

  8. #8
    Member Contributor
    Join Date
    May 2011
    Location
    Alabama, USA
    Posts
    66

    Re: Screenshot to texture

    Yeah, I've got the glGenTextures function above everything else in another function; initRendering(). Anyhow, I'll implement the changes you suggest and get back to you guys.
    Benjamin Barrett aka vindy
    "Our knowledge is finite, while our ignorance is infinite!"

  9. #9
    Member Contributor
    Join Date
    May 2011
    Location
    Alabama, USA
    Posts
    66

    Re: Screenshot to texture

    Ok, tried it. Now my screen is just black. Like nothing is getting drawn.
    Benjamin Barrett aka vindy
    "Our knowledge is finite, while our ignorance is infinite!"

  10. #10
    Member Contributor
    Join Date
    May 2011
    Location
    Alabama, USA
    Posts
    66

    Re: Screenshot to texture

    The strange thing is if I take all the code used in between the creation and release of the FBO and replace the code that is drawing that big quad with it then it seems to work. Its just a little slow.
    Benjamin Barrett aka vindy
    "Our knowledge is finite, while our ignorance is infinite!"

Page 1 of 2 12 LastLast

Similar Threads

  1. Texture from pixel buffer has no color, see screenshot.
    By longshotnl in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 02-08-2005, 03:14 PM
  2. Screenshot!
    By KeSh in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 11-25-2004, 06:25 AM
  3. Taking a screenshot of a moving object and antialias the screenshot
    By pmatos in forum OpenGL: Advanced Coding
    Replies: 6
    Last Post: 11-24-2003, 06:43 AM
  4. screenshot, xterm
    By in forum OpenGL: Linux
    Replies: 3
    Last Post: 06-18-2002, 08:17 PM
  5. 8K x 8K screenshot
    By imported_Adrian in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 02-03-2002, 06: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