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 8600481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:37:35+00:00 2026-06-12T01:37:35+00:00

I am using JOGL, but this question applies to OpenGL in general. There seem

  • 0

I am using JOGL, but this question applies to OpenGL in general. There seem to be similar questions lying around, but they are either directed at GLSL code, have to do with copying the contents of a frame buffer, or are a general advice – use frame buffer objects instead of glCopyTexSubImage2D.

Question

I am doing some shadow mapping. How do I render the depth channel directly to a texture using a frame buffer object?

Can you please post a block of code that initializes the texture and the frame buffer object, as well as the code that initializes everything before rendering the scene?

Currently, I use glCopyTexSubImage2D. I initialize the texture like this:

glGenTextures(1, &textureNo)
glBindTexture(GL_TEXTURE_2D, textureNo)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL)
glTexParameterf(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY)
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 2048, 2048, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, null)

and then I render like this:

glBindTexture(GL_TEXTURE_2D, textureNo)
glClear(GL_DEPTH_BUFFER_BIT)
drawScene()
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 2048, 2048)

and this works fine, the texture ends up holding the depth channel of the scene – this means my projection and view matrices are set correctly to view the scene from the light point of view. I’d like to use frame buffer objects instead.

What do I need to change above to render directly to the texture instead using a frame buffer object?

EDIT:

Here is what I tried. I first initialized the frame buffer object:

glGenFramebuffers(1, &fbo)

I then rendered like this:

glBindFramebuffer(GL_FRAMEBUFFER, fbo)
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, textureNo, 0)
glBindTexture(GL_TEXTURE_2D, textureNo)
drawScene()

I have confirmed that the above works for textures of type GL_RGB and GL_COLOR_ATTACHMENT0, but it does not seem to work for GL_DEPTH_COMPONENT type textures and GL_DEPTH_ATTACHMENT – the depth channel does not get rendered into the texture textureNo above.

  • 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-12T01:37:37+00:00Added an answer on June 12, 2026 at 1:37 am

    Assuming that this is all of the FBO setup code, I don’t see the part where you call glCheckFramebufferStatus. You know, the function that would have told you that your Framebuffer Object was incomplete, and thus rendering to it would fail.

    Specifically, it would have given you GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER​, because you didn’t set a valid draw buffer. If you don’t use a color attachment, you need to use glDrawBuffer to set all of the color buffer writes to GL_NONE.

    It’s a common FBO gotcha; you won’t be the first to not have seen it. But that’s why it’s vital to always check glCheckFramebufferStatus after you modify your FBO.

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

Sidebar

Related Questions

I am new to OpenGL. I am using JOGL. I downloaded this model .
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
I'm experimenting with framebuffers to create a glow effect using Java and JOGL, but
I'm using Java OpenGL (JOGL 2.x, built from Git source). I'm rendering my scene
Using this example . Pretend there are date fields in both forms. How would
When using openGL in Java (in bindings like jogl), do you have to worry
Im about to start a small project using OpenGL and Java. Looking through this
Using Rails 3, but I guess doesn't matter. I put this in the template
I'm new to OpenGL. I'm using Java/JOGL. I'm having difficulty with polygon faces. I
I'm new to OpenGL. I'm using JOGL. I would like to create a sky

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.