Selecting 3D Objects With The Mouse Using OpenGL // OpenGL Tutorial #31

Поделиться
HTML-код
  • Опубликовано: 25 ноя 2024

Комментарии • 49

  • @TiramisuCorleone
    @TiramisuCorleone Год назад +6

    It was not easy for me to follow you, but ultimately you have helped me. So thank you!

    • @OGLDEV
      @OGLDEV  Год назад

      Glad I could help!

  • @arthurmoyer2657
    @arthurmoyer2657 2 года назад +5

    Hey, Thanks for this! This is one of the other problems I was having with my RTS code picking the ground. I am(was?) using a pure mathematical technique that failed far too often. I look forward to seeing how well this works. Thanks!

    • @jw200
      @jw200 2 года назад

      glReadPixels is very slow

    • @arthurmoyer2657
      @arthurmoyer2657 2 года назад

      @@jw200 Do you have a suggestion for an alternative then?

    • @OGLDEV
      @OGLDEV  2 года назад

      You're welcome!

    • @OGLDEV
      @OGLDEV  2 года назад +1

      As always, it should be weighed against the alternatives. This solution is very simple to implement which is an advantage. I haven't measured the performance of glReadPixels but I hope that the drivers have some way to optimize it since we are accessing a single pixel.

    • @arthurmoyer2657
      @arthurmoyer2657 2 года назад

      @@OGLDEV I would agree I would hope that it wouldn't hurt the performance. I think the issue is it mainly grinds things to a halt while CPU and GPU sync up, so they aren't running async anymore, so glReadPixel will wait until the render is done before continuing, which means the CPU stalls out while waiting. So it would more be about when in the code the glReadPixel is called from what I've read (and even using a different thread to do the glReadPixel call so the main CPU thread doesn't stall). I've also read someone changing the viewport to something very small and then doing the render to get the requested ID position (I assume they offset the projection/view etc. so the mouse position is the center of the viewport and the scene is "shifted" like looking through a spy glass. I've seen others talking about other async buffers, but it was too late at night for me to understand all of it. One way or another, it's a useful direction that you have in your video. :)

  • @fudgeracoon2529
    @fudgeracoon2529 2 года назад +1

    Great tutorial !!!

  • @MrFacciolone
    @MrFacciolone 2 года назад +4

    this was really great!
    Just one question though, in the glReadPixels() call I see you specified as format GL_RGB_INTEGER, but in the glReadPixels documentation it says only some format are accepted, and GL_RGB_INTEGER is NOT on the list. GL_RGB is though, and I would have thought that specifying the type as GL_UNSIGNED_INT would have been enough, but it turns out that it won't work that way. The correct format for ReadPixels is the one present in your code, GL_RGB_INTEGER. The question is: how did you figure out you had to pass GL_RGB_INTEGER as argument if even the Khronos documentation doesn't list it as accepted?
    Again thank you for the great series there is much stuff in here I would never have figured out by myself

    • @OGLDEV
      @OGLDEV  2 года назад +6

      Thanks!
      GL_RGB_INTEGER is indeed not part of the man page of glReadPixels but in the PDF of OpenGL it's not entirely clear. I guess I just played with it until I got it working...

  • @codingexpress4950
    @codingexpress4950 Год назад

    Thank you so much! It helped me a lot. keep up the good work +1👍

    • @OGLDEV
      @OGLDEV  Год назад

      You're welcome!

  • @francescobrischetto5023
    @francescobrischetto5023 2 года назад +1

    Hi, I start following your tutorials of websites and youtube because I'll need to use tessellation shader for my master thesis. Could you please update git solutions for tutorials with tessellation shader for Windows? (tutorials 30/31). I tried to setup a VM with Ubuntu but I had some problems in let it recognize the right videocard

    • @OGLDEV
      @OGLDEV  2 года назад +4

      I've just added projects for the two tutorials. I've named them 'Tessellation1' and 'Tessellation2' to avoid confusion with the current series. The first one works ok on my Windows machine with GT710. The second one fails initialization because for some reason it cannot find the uniform gTessellationLevel in the CS even though it is used. On the Linux machine with GTX1650 the same code works so it could be something specific on the Windows machine. Please let me know if this is working for you.

  • @MaxMustermann-ey5sc
    @MaxMustermann-ey5sc 7 месяцев назад

    This is great! I implemented a simple version of this (no triangle picking just entire objects). I am trying to get drag selection to work now. The big problem is that even if I decide to only read every 5th pixel and x and y, it's still taking a considerable amount of time (way too long even for in editor selection) despite the decreased accuracy. Assuming that the glReadPixel is actually the slow part, is this still a viable solution for drag selections. Is there potentially a better solution than checking the pixels in a loop? Or would you recommend something like a volume intersection?

    • @OGLDEV
      @OGLDEV  7 месяцев назад

      Check out my Ray Casting tutorial for a math-only version: ruclips.net/video/lj5hx6pa_jE/видео.html

    • @MaxMustermann-ey5sc
      @MaxMustermann-ey5sc 7 месяцев назад

      ​@@OGLDEV thank you!! I was actualling looking for 'box selection' when dragging the mouse. That explains that I did not find many resources online lol. I've since implemented this using stencils. But now I need to implement manipulation so I'll habe a closer look at your recommendation again ;D
      Thanks again!!

    • @OGLDEV
      @OGLDEV  7 месяцев назад

      You're welcome :-)

  • @killereks
    @killereks 10 месяцев назад

    5:44 after adding that filter parameter my texture just becomes transparent and nothing is ever rendered. When i remove it shows up as black (my glClearColor)

    • @OGLDEV
      @OGLDEV  10 месяцев назад

      You mean the entire model disappears? This is the picking texture so it should not affect the model texture. Make sure you bind zero to GL_TEXTURE_2D when you finish initializing it. Is my code working correctly? It actually seem to work ok for me without the filter params but I think the texture might be incomplete in this case so it's best to set it.

  • @diamond32tutoriales49
    @diamond32tutoriales49 Год назад

    I don't understand what you mean by WorldTrans, is there no code where I can see it? or some repository

    • @OGLDEV
      @OGLDEV  Год назад

      The code is located here: github.com/emeiri/ogldev/blob/master/tutorial31_youtube/
      The WorldTrans object is used to maintain the local-to-world transformation of a single entity/instance. You can find the declaration here: github.com/emeiri/ogldev/blob/master/Include/ogldev_world_transform.h and the implementation:
      github.com/emeiri/ogldev/blob/master/Common/ogldev_world_transform.cpp

  • @nerijusvilcinskas7851
    @nerijusvilcinskas7851 Год назад

    Can I ask why are you not using renderbuffer to render pixel information about objects and chose to render to texture instead? I have a framebuffer class in my engine which supports renderbuffer attachment and gl_depth_component attachment rendering depth buffer to texture. So why would I want to use render to texture vs render to renderbuffer? I heard rendering to them is faster than render to texture

    • @OGLDEV
      @OGLDEV  Год назад +1

      Laziness. I need to switch at some point.

    • @nerijusvilcinskas7851
      @nerijusvilcinskas7851 Год назад

      @@OGLDEV Thanks for such a quick reply! I guess I will try to make this work using renderbuffer maybe, dealing with framebuffers in general is a bit frustrating so thank you for these amazing tutorials once again!

  • @Hiraghm
    @Hiraghm 7 месяцев назад

    I wish there was a version of this tutorial in C

    • @OGLDEV
      @OGLDEV  7 месяцев назад

      I'm using a very basic version of C++ so changing it to C should not be a problem.

  • @quentinquadrat9389
    @quentinquadrat9389 2 года назад

    How many objects can we pick ? 16 millions (color id) or 256 (limited by Z-buffer accuracy) ? Not sure to understand in what the Z-buffer helps, since with shaders you can pass directly the ID of your object. I have to experiment by myself.

    • @OGLDEV
      @OGLDEV  2 года назад +2

      You need the zbuffer in order to store the info of only the closest pixels. The actual info is stored in the GL_RGBUI32 texture so you have three int32 to specify the draw call, object index and primitive id.

    • @quentinquadrat9389
      @quentinquadrat9389 2 года назад +1

      @@OGLDEV thanks

  • @op-vw8sd
    @op-vw8sd 2 года назад

    👍

  • @ducroit
    @ducroit 6 месяцев назад

    Hi,
    I encountered some run errors with tutorials 31 to 32 (piking), 34 to 38 (shadow) and 40(Skeletal animation).
    The tutorial 33(sprite) is run fine.
    First I had the error of the texture2D function at line 319 and 513 in lighting_new.fs, I saw that the function is deprecated, so I put the texture function instead.
    "Error compiling '../Common/Shaders/lighting_new.fs': '0:319(21): error: no function with name 'texture2D'
    0:319(21): error: type mismatch
    0:319(21): error: operands to arithmetic operators must be numeric
    0:513(19): error: no function with name 'texture2D'
    0:513(19): error: operands to arithmetic operators must be numeric
    0:518(40): warning: `TempColor' used uninitialized"
    As a result, I had the error with EdgeDistance0 in lighting_new.fs:
    "Error linking shader program: 'error: vertex shader output `EdgeDistance0' specifies no interpolation qualifier, but fragment shader input specifies noperspective interpolation qualifier"
    While trying to remove the noperspective qualification, I had the following error :
    "!!! Debug callback !!!
    Debug message: id 1, GL_INVALID_OPERATION in glDrawElements
    Message source: API
    Error type: Error
    Severity: High"
    I don’t know if the error is from my opengl (4.6) and glfw(3.3.6) versions.
    Could you please try to check out on your side?

    • @OGLDEV
      @OGLDEV  6 месяцев назад

      I added the missing 'noperspective' to all the vertex shaders where it was missing and replaced texture2D with texture. Please let me know if you still have problems with any of these tutorials. Thanks for the feedback!

    • @ducroit
      @ducroit 6 месяцев назад

      @@OGLDEV
      Thank you for responding so quickly!
      But I still have problems when I try to run these tutorials after pull your update :
      "Invalid shader program: 'active samplers with a different type refer to the same texture image unit'
      Warning! Unable to get the location of uniform 'gWireframeColor'
      !!! Debug callback !!!
      Debug message: id 1, GL_INVALID_OPERATION in glDrawElements
      Message source: API
      Error type: Error
      Severity: High"

    • @OGLDEV
      @OGLDEV  6 месяцев назад

      I pushed a fix to the 'active samplers...' error. Let's see if it improves something.

    • @ducroit
      @ducroit 6 месяцев назад

      @@OGLDEV
      Everything works now!
      Thank you very much, I learned a lot with your tutorials.

    • @OGLDEV
      @OGLDEV  6 месяцев назад

      Glad to hear!