Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem . This will help others answer the question.

Closed 5 days ago .

I've a code in Delphi and OpenGL. OpenGL context is initialized and it is working. But here is my problem.

I draw background image to the frame buffer screenFrameBuffer (size of a screen) and connect texture tempTexture to that frame buffer. After that I draw part of five other textures to that frame buffer (column from r = 1 to 5). Now that is starting screen.

Later, I want to update columns. First I draw background again to the same buffer and draw changed columns. In the code below for testing, I draw first column to the place of the fourth column. After I draw tempTexture to the screen all columns except column four are clear and have a background image (that is planned and it is OK) but column four has old content from column four and column one content drawn over. Like somehow frame buffer content from starting screen is preserved.

procedure TForm1.Button4Click(Sender: TObject);
  r : integer;
begin
  glBindTexture(GL_TEXTURE_2D, 0);
  glBindFramebuffer(GL_FRAMEBUFFER, 0);
  // bck to bck
  // Set up temporary framebuffer and texture
  glBindFramebuffer(GL_FRAMEBUFFER, screenFrameBuffer);
  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, bckTex, 0);
  glBindTexture(GL_TEXTURE_2D, tempTexture);
  glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, Form1.Width, Form1.Height);
  // reel1 to reel4
  // Unbind the temporary texture and framebuffer
  glBindTexture(GL_TEXTURE_2D, 0);
  glBindFramebuffer(GL_FRAMEBUFFER, 0);
  // Set up temporary framebuffer and texture
  glBindFramebuffer(GL_FRAMEBUFFER, screenFrameBuffer);
  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, signsTex[1], 0);
  glBindTexture(GL_TEXTURE_2D, tempTexture);
  glCopyTexSubImage2D(GL_TEXTURE_2D, 0, offset[4], topOffset, 0, startPos[1], signWidth, 3 * signHeight);
  // Unbind the temporary texture and framebuffer
  glBindTexture(GL_TEXTURE_2D, 0);
  glBindFramebuffer(GL_FRAMEBUFFER, 0);
  /////////////////
  glBindTexture(GL_TEXTURE_2D, tempTexture);
  glPushMatrix();
  glTranslatef(0.0, 0.0, 0.0);
  DrawTexture(Form1.Width, Form1.Height, Form1.Width, Form1.Height, Form1.Width, Form1.Height, 0, 0, 0, 0);
  glPopMatrix();
  glFlush;
  SwapBuffers(Canvas.Handle);

When i update same column in different way, also using frame buffer, it is OK. Looks like problem is with a command:

glCopyTexSubImage2D(GL_TEXTURE_2D, 0, offset[4], topOffset, 0, startPos[1], signWidth, 3 * signHeight);

It must be something with alpha values. I've tried many options but no luck.