Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8343163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:58:31+00:00 2026-06-09T05:58:31+00:00

I want to render n texture in my program and store them for later

  • 0

I want to render n texture in my program and store them for later usage. Therefore I use the OpenGL FramebufferObject.

At first I create an array with 128 textures like this

self.textures = glGenTexture(128)

The second step is a loop with 128 iterations in which I bind the texture at position i and render into it.

    glBindTexture(GL_TEXTURE_2D, self.texture[i])
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_NEAREST)
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_NEAREST)
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8,  width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, None);
    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,  GL_TEXTURE_2D, self.texture[i], 0);
    renderScene()

The last step is another loop, the MainGameLoop in which I render a plane with one texture from the texture array.

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    glMatrixMode(GL_MODELVIEW)
    glLoadIdentity()
    gluLookAt(0,0,1,0,0,0,0,1,0)
    glEnable(GL_TEXTURE_2D)

    glBindTexture(GL_TEXTURE_2D, self.texture[i])

    glBegin(GL_QUADS)

    glNormal3f(0.0, 1.0, 0.0)
    glTexCoord2f(0.0, 0.0)
    glVertex3f(-1, 1, -1)
    glTexCoord2f(1.0, 0.0)
    glVertex3f(1, 1, -1)
    glTexCoord2f(1.0, 1.0)
    glVertex3f(1, -1, -1)
    glTexCoord2f(0.0, 1.0)
    glVertex3f(-1, -1, -1)

    glEnd();

    glDisable(GL_TEXTURE_2D)

But something went wrong, the screen stays black.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T05:58:32+00:00Added an answer on June 9, 2026 at 5:58 am

    A texture must not be bound when used as a color attachment to a framebuffer object. You however are binding it before attaching which of course breaks the whole thing.

    The correct code would iterate through all multitexturing units and make sure the texture is not bound in any of them.

    Update due to comment:

    In your code you bind a texture name and set parameters for it

    glBindTexture(GL_TEXTURE_2D, self.texture[i])
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_NEAREST)
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_NEAREST)
    

    Then you initialize the texture object with null data

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8,  width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, None);
    

    and finally attach it as a framebuffer attachment.

    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,  GL_TEXTURE_2D, self.texture[i], 0);
    

    The problem is, that now the texture is still selected as a data source, because it is bound. The texture must not be bound to any texturing unit, to work as a framebuffer color attachment. Also the FBO must be bound as render target somewhere.

    renderScene()
    

    Here’s a small helper function that makes sure, a given texture object is not bound in any texturing unit:

    def glhelperUnbindTexture(target, name):
        max_units = max(glGetInteger(GL_MAX_TEXTURE_UNITS),
                        glGetInteger(GL_MAX_TEXTURE_IMAGE_UNITS),
                        glGetInteger(GL_MAX_TEXTURE_COORDS))
        current_unit = glGetInteger(GL_ACTIVE_TEXTURE)
    
        for i in range(max_units):
            glActiveTexture(GL_TEXTURE0 + i)
            binding = glGetInteger( {GL_TEXTURE_1D: GL_TEXTURE_BINDING_1D,
                                     GL_TEXTURE_2D: GL_TEXTURE_BINDING_2D,
                                     GL_TEXTURE_3D: GL_TEXTURE_BINDING_3D,
                                     GL_TEXTURE_CUBE_MAP: GL_TEXTURE_BINDING_CUBE_MAP}[target])
            if binding == name:
                 glBindTexture(target, 0) # this unbinds the texture from the texturing unit
    
        glActiveTexture(current_unit)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my OpenGL program I want to render everything in memory. I don't want
I'm learning about how to use JOGL and OpenGL to render texture-mapped quads. I
I want to be able to render something into a texture, on OpenGL, so
I want to render equations to PNG files and embed them in the HTML
I want to create a blur effect using a fragment shader in OpenGL ES
I'm making a 2D game. I want to be able to render a texture
I need to initialize an OpenGL 2D texture with zeroes. Why? I render to
I would like to render image in OpenGL ES, pixel by pixel. I want
I currently have a R8G8B8 floating point render target and want to use it
I want to render the partial view using ajax. When I submit the button,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.