Results 1 to 4 of 4

Thread: Rendering texture

  1. #1
    Member Contributor
    Join Date
    Dec 2011
    Posts
    85

    Rendering texture

    Basically I render to texture, (I can see that if I read with ReadPixel from that what appears is correct) but when I try to bind that texture to a quad, I dont see anything

    Code :
    // init
    gl.glEnable(GL2.GL_TEXTURE_2D);
     
            //gl.glGenRenderbuffers(1, textureID, 0);
            gl.glGenTextures(1, textureID, 0);
            gl.glBindTexture(GL2.GL_TEXTURE_2D, textureID[0]);
     
    //        gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_S, GL2.GL_REPEAT);
    //        gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_T, GL2.GL_REPEAT);
    //        gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_NEAREST);
    //        gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_NEAREST);
     
            // null means reserve texture memory, but texels are undefined
            gl.glTexImage2D(GL2.GL_TEXTURE_2D, 0, GL2.GL_RGB, floorWidth, floorHeight,
                    0, GL2.GL_RGB, GL2.GL_FLOAT, null);
     
            gl.glGenFramebuffers(1, frameBufferID, 0);
            gl.glBindFramebuffer(GL2.GL_FRAMEBUFFER, frameBufferID[0]);
     
            //Attach 2D texture to this FBO
            gl.glFramebufferTexture2D(GL2.GL_FRAMEBUFFER, GL2.GL_COLOR_ATTACHMENT0, 
                                            GL2.GL_TEXTURE_2D, textureID[0], 0);
     
            // depth buffer
            int[] depthRenderBufferID = new int[1];
            gl.glGenRenderbuffers(1, depthRenderBufferID, 0);
            gl.glBindRenderbuffer(GL2.GL_RENDERBUFFER, depthRenderBufferID[0]);
            gl.glRenderbufferStorage(GL2.GL_RENDERBUFFER, GL2.GL_DEPTH_COMPONENT24, 
                                                    floorWidth, floorHeight);
            gl.glFramebufferRenderbuffer(GL2.GL_FRAMEBUFFER, GL2.GL_DEPTH_ATTACHMENT,
                                                GL2.GL_RENDERBUFFER, depthRenderBufferID[0]);
     
            if(gl.glCheckFramebufferStatus(GL2.GL_FRAMEBUFFER) == GL2.GL_FRAMEBUFFER_COMPLETE)
                System.out.println("GL_FRAMEBUFFER_COMPLETE!!");
            else
                System.out.println("..[censored] ^^");
     
            gl.glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
            gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
     
    //        gl.glViewport(0, 0, floorWidth, floorHeight);
    //        gl.glMatrixMode(GL2.GL_PROJECTION);
    //        gl.glLoadIdentity();
     
            //gl.glDisable(GL2.GL_TEXTURE_2D);
            //gl.glDisable(GL2.GL_BLEND);
            gl.glEnable(GL2.GL_DEPTH_TEST);
     
            gl.glColor3f(0.0f, 0.0f, 0.0f);
            gl.glBegin(GL2.GL_TRIANGLES);
                gl.glVertex3f(1.0f, 1.0f, 0.0f);
                gl.glVertex3f(1.0f,-0.5f, 0.0f);
                gl.glVertex3f(-1.0f,-1.0f, 0.0f);
            gl.glEnd();
     
            //show the back buffer if double buffering was set
            gl.glFlush();

    Code :
    // display
     
    gl.glDisable(GL2.GL_LIGHTING);
     
            gl.glColor3f(1.0f, 1.0f, 1.0f);
     
            gl.glBindTexture(GL2.GL_TEXTURE_2D, textureID[0]);
     
            gl.glBegin(GL2.GL_QUADS);
                gl.glTexCoord2f(0.0f, 0.0f);
                gl.glVertex3f(-a, -a, 0);
                gl.glTexCoord2f(0.0f, 1.0f);
                gl.glVertex3f(-a, a, 0);
                gl.glTexCoord2f(1.0f, 1.0f);
                gl.glVertex3f(a, a, 0);
                gl.glTexCoord2f(1.0f, 0.0f);
                gl.glVertex3f(a, -a, 0);
            gl.glEnd();

  2. #2
    Senior Member Regular Contributor imported_tksuoran's Avatar
    Join Date
    Mar 2008
    Location
    Cambridge, UK
    Posts
    223

    Re: Rendering texture

    You have commented out glTexParameter calls which set filtering modes to nearest. Default filter modes require mipmaps, so you should either use filter mode without mipmaps or generate mipmaps.

  3. #3
    V-man
    Guest

    Re: Rendering texture

    This is covered in "common mistakes" page
    http://www.opengl.org/wiki/Common_Mi...ting_a_Texture

  4. #4
    Member Contributor
    Join Date
    Dec 2011
    Posts
    85

    Re: Rendering texture

    Quote Originally Posted by tksuoran
    You have commented out glTexParameter calls which set filtering modes to nearest. Default filter modes require mipmaps, so you should either use filter mode without mipmaps or generate mipmaps.
    It worked, thanks

    Quote Originally Posted by V-man
    This is covered in "common mistakes" page
    http://www.opengl.org/wiki/Common_Mi...ting_a_Texture
    Useful link, thanks

Similar Threads

  1. Texture within texture rendering when using transparent textures
    By OneCleverGorilla in forum OpenGL: GLSL
    Replies: 0
    Last Post: 06-11-2017, 02:03 PM
  2. Texture Units and Mixing - Only One Texture Rendering
    By OneCleverGorilla in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 05-24-2017, 07:26 AM
  3. OpenGL texture flickering when rendering only parts of texture
    By wrymnn in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 06-30-2015, 02:01 PM
  4. Replies: 1
    Last Post: 12-26-2014, 04:57 PM
  5. rendering from texture to texture directly
    By Dragon89 in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 02-08-2007, 01:51 PM

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