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

  • Home
  • SEARCH
  • 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 6371737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:07:24+00:00 2026-05-25T01:07:24+00:00

I have an OpenGL program in which I am doing some augmented reality work.

  • 0

I have an OpenGL program in which I am doing some augmented reality work. It works in 2 passes.

First, it renders a frame using standard OpenGL calls. Next, it compares a frame from the camera to the rendered frame using a shader.

In the first pass, I render to a texture bound to my framebuffer objects, and I also upload camera frames to other textures bound to that object.

In my second pass, my shader has no trouble accessing the uploaded textures (that is, the camera frames) however it cannot access the texture rendered to by the first pass.

If I make a debug shader that simply sets the vertex colours to be the colour of the texture at that point, then when I use the texture uploaded from the camera I see this:

Successfully accessing texture

However, if I change the shader to instead use the texture rendered to in the first pass, I see this:

Not accessing texture successfully

I’ll try to give enough background below to make this clear, but any help is greatly appreciated!


Background

I know it was rendering properly in the first pass, as I have a debug window showing me the rendering results, and in addition am using Apple’s OpenGL Profiler, and can see all of the textures.

I’m basically doing the rendering to textures like this site does

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

a difference is that I never switch framebuffer objects. That is, I never call

// switch back to window-system-provided framebuffer
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

Do I need to use different FBOs when I do my initial rendering, and when I use my shader to compare them?


The one other hint I have towards what might be going on is that if in the OpenGL profiler I look at my State, it only claims that GL_TEXTURE0 and GL_TEXTURE4 have changed from their default state. Those are both textures that I explicitly load pixel data into. The other 3 textures are rendered to in my first pass.
Screenshot of OpenGL state


Relevant code

// First I create the textures
glGenTextures(1, &renderTexture);
glGenTextures(1, &cameraTexture);
glGenTextures(1, &correlationTexture);

gllActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, cameraTexture);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img->width, img->height, 0,GL_BGR, GL_UNSIGNED_BYTE, img->imageData); 

glActiveTexture(GL_TEXTURE0+1);
glBindTexture(GL_TEXTURE_2D, renderTexture);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.width, size.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
glBindTexture(GL_TEXTURE_2D, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, renderTexture, 0);

glActiveTexture(GL_TEXTURE0+2);
glBindTexture(GL_TEXTURE_2D, correlationTexture);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.width, size.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
glBindTexture(GL_TEXTURE_2D, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, correlationTexture, 0);

// Now I render to the renderTexture. This works fine, I can verify
// it using glReadPixels.

// However, later on when I'm ready to do the shader, I do this
// First I switch the bound texture
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,      GL_TEXTURE_2D,correlationTexture, 0); // (this has been set up earlier)
glClear(GL_COLOR_BUFFER_BIT);
glUseProgram(theProgram);
glUniform1i(renderTexLoc, 1); // This should tell it to look at the rendered texture from earlier, it does not.
  • 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-05-25T01:07:25+00:00Added an answer on May 25, 2026 at 1:07 am

    Ah, looks like I solved it. I had to bind the first-pass rendered texture before I rendered with the shader thus:

      glActiveTexture(GL_TEXTURE0+1);
      glBindTexture(GL_TEXTURE_2D,renderTexture);
    

    I guess I’m still a bit fuzzy on what exactly the difference between bound textures vs. active textures is, but for now this works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a beginner at using openGL. I have used a program which I
I have a program (NWShader) which hooks into a second program's OpenGL calls (NWN)
I have an OpenGL program that works on all of my computers but one.
I have a program which draws some terrain and simulates water flowing over it
I am trying to write an OpenGL visualization program for some scientific data using
I have a simple openGL ES program which basically sets up two triangles which
I have an opengl scene rendering on an EAGLView layer and some other elements
So I have some openGL code (such code for example) /* FUNCTION: YCamera ::
I have a program that uses GLUT for its OpenGL rendering. Now I need
I have a program which simulates a physical system that changes over time. I

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.