• Advertisement
Sign in to follow this  

OpenGL How to tell OpenGL to ignore what's under cursor?

This topic is 2344 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello.

In my editor im drawing selectionboxes with OpenGL, they are drawn using glDrawArrays from pre calculated vertex coords.
From const array.
The box(boxes) are textured from texture loaded from file (PNG) and processed with SDL to make texture for OpenGL out of it.


The drawing and stuff works fine but there is very annoying problem (bug) for me that is really really ugly for me.

Look at the GIF.

[img]http://e36v4.co.cc/fdgfg.GIF[/img]


As you see, first there are just white rectangles on red/black texture and if mouse cursor hit's the WHITE border of selection boxes, then boxes jump around (up and down).


Is it possible to tell OpenGL to ignore the selection boxes texture or the WHITE BORDER "width" in pixels or something like that?
To finally stop this jumping once and for all?

glReadPixels maybe could help, but if the textures have the same color? It will jump again?

I must tell you that it always should ignore selection boxes, but if there is anything else under the mouse cursor it shouldn't ignore it and then it is allowed to jump around.

It just must ignore the white selection boxes. That's all.


Any help, ideas, tips or hints are very very welcome.

Share this post


Link to post
Share on other sites
Advertisement
Um.... I don't understand the problem. It seems to me that the problem has nothing to do with openGL and rendering, but the logic.

Maybe you could show the whole code or you should explain what you want to achieve (the final goal, not the logic to achieve it).

Share this post


Link to post
Share on other sites
How are you actually testing for selection anyway? I mean if you test the point against a rect, you are either inside, or outside, that's it. Edge cases are special and generally require extra checking.

Share this post


Link to post
Share on other sites
[b] szecs[/b]

Well, look at this gif then.

[img]http://e36v4.co.cc/try2.GIF[/img]


There is a mouse dragging and red selection rectangles. In this gif you see that if mouse cursor goes over the red lines, then the selection boxes are not going up like in my first gif. They go up only if there is something else under cursor (not selection boxes itself), in this case there is a little box at the right, as you see.

In first GIF, when the mouse cursor goes over the white line, the boxes will "jump up".
But they shouldn't, it must ignore the white lines as the second GIF shows, the red lines are ignored under mouse cursor.


Basically it same as telling: [b]selection shouldn't select itself![/b]


[quote name='szecs' timestamp='1313760631' post='4851195']
Um.... I don't understand the problem. It seems to me that the problem has nothing to do with openGL and rendering, but the logic.

Maybe you could show the whole code or you should explain what you want to achieve (the final goal, not the logic to achieve it).
[/quote]

Share this post


Link to post
Share on other sites
[quote name='Tachikoma' timestamp='1313761325' post='4851198']
How are you actually testing for selection anyway? I mean if you test the point against a rect, you are either inside, or outside, that's it. Edge cases are special and generally require extra checking.
[/quote]


Basically im not, most of the work is done by OpenGL with gluUnProject.
And im drawing the boxes at the coordinates, which gluUnProject returned me.


Same code as here:
[url="http://nehe.gamedev.net/article/using_gluunproject/16013/"]http://nehe.gamedev....nproject/16013/[/url]


I think that's the glReadPixels that finds the textures. Because i think that if there is empty "world" and i click in this world, it reads: 0,0,0.
So there is nothing under cursor.

In my case it finds anything that's not 0,0,0 and his friend gluUnproject tells me the coordinates where there is something under cursor.
And also it finds the selection boxes texture and that could be reason for jumping around.

Share this post


Link to post
Share on other sites
[s]The images only show the symptom. You still haven't explained [b]how[/b] your algorithm works.

Are you testing cursor intersection against a geometric object? Are you testing against rendered objects in a buffer?
[/s]
edit: Never mind, just read your second response.

I think you should cast a ray through the cursor and explicitly test boxes intersecting against it. So instead of using buffers to perform the test, you are doing it in the geometric domain.

Share this post


Link to post
Share on other sites
I also have a bit difficulty understanding the problem; but perhaps it's because the solutions is too easy... because if
[quote name='BytePtr' timestamp='1313761607' post='4851199']
Basically it same as telling: [b]selection shouldn't select itself![/b]
[/quote]
then the solution is to not draw the selection geometry when selecting. Selection is only performed on what you draw when selection is enabled, so if you don't want the selection to select itself, then you don't draw the selection.

Share this post


Link to post
Share on other sites
AFAICT, the linked NeHe code uses the depth value to perform the reverse projection, so you could try disabling depth write via [b]glDepthMask(GL_FALSE)[/b] when you draw the selection box so that the box wireframes don't pollute the depth buffer.

Share this post


Link to post
Share on other sites
[quote name='JTippetts' timestamp='1313762668' post='4851208']
AFAICT, the linked NeHe code uses the depth value to perform the reverse projection, so you could try disabling depth write via [b]glDepthMask(GL_FALSE)[/b] when you draw the selection box so that the box wireframes don't pollute the depth buffer.
[/quote]

Wow, this is excellent. It really works.

Basically i did this:

[code]glDepthMask(false);
DrawSelector;
glDepthMask(true);
[/code]

Looks so smooth and much nicer now.
Can you explain a bit more why it helps and works?
Or could post some link where i could read about it? I want to learn also from it.


Thanks alot for you and the others here who replied.

You guys got your +

Share this post


Link to post
Share on other sites
The [url="http://en.wikipedia.org/wiki/Z_buffer"]Z-buffer[/url] is used by the renderer to determine which fragments to keep and which to discard, based on their Z-depth, or distance from the camera. A side-effect of this is that when rendering is done, the Z-buffer contains a depth "map" of the scene. Since any given point on-screen reverse-projects to a line-segment in world space bounded by the near and far planes, the only way to determine the exact point in world space that a screen point reverse-projects to is to read the Z-depth from the buffer and use that as the Z component of the coordinate to reverse-project. This is what the NeHe example is doing by calling [b]glReadPixels[/b] to assign the value of [b]winZ[/b].

Now, when you draw your selection boxes with depth-writing enabled, then the Z value in the depth buffer that is used to reverse-project with will be equal to the depth of the wireframe of the selection box at that location, rather than the depth of the level geometry behind it that you are trying to select. This apparently fools whatever code you use to calculate the selection boxes into thinking the level geometry depth is higher than it really is. In effect, the algorithm doesn't discriminate between the "real" stuff (level geometry) and the "fake" stuff (the selection box). By disabling depth-write when you draw the selection boxes, you are making those boxes a visual effect only; they have no presence in the depth buffer, and thus don't over-write the depth values from the level geometry. In effect, they now "don't count" for the purposes of reverse-projecting.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
  • Advertisement
  • Popular Now

  • Advertisement
  • Similar Content

    • By Balma Alparisi
      i got error 1282 in my code.
      sf::ContextSettings settings; settings.majorVersion = 4; settings.minorVersion = 5; settings.attributeFlags = settings.Core; sf::Window window; window.create(sf::VideoMode(1600, 900), "Texture Unit Rectangle", sf::Style::Close, settings); window.setActive(true); window.setVerticalSyncEnabled(true); glewInit(); GLuint shaderProgram = createShaderProgram("FX/Rectangle.vss", "FX/Rectangle.fss"); float vertex[] = { -0.5f,0.5f,0.0f, 0.0f,0.0f, -0.5f,-0.5f,0.0f, 0.0f,1.0f, 0.5f,0.5f,0.0f, 1.0f,0.0f, 0.5,-0.5f,0.0f, 1.0f,1.0f, }; GLuint indices[] = { 0,1,2, 1,2,3, }; GLuint vao; glGenVertexArrays(1, &vao); glBindVertexArray(vao); GLuint vbo; glGenBuffers(1, &vbo); glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData(GL_ARRAY_BUFFER, sizeof(vertex), vertex, GL_STATIC_DRAW); GLuint ebo; glGenBuffers(1, &ebo); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices,GL_STATIC_DRAW); glVertexAttribPointer(0, 3, GL_FLOAT, false, sizeof(float) * 5, (void*)0); glEnableVertexAttribArray(0); glVertexAttribPointer(1, 2, GL_FLOAT, false, sizeof(float) * 5, (void*)(sizeof(float) * 3)); glEnableVertexAttribArray(1); GLuint texture[2]; glGenTextures(2, texture); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); sf::Image* imageOne = new sf::Image; bool isImageOneLoaded = imageOne->loadFromFile("Texture/container.jpg"); if (isImageOneLoaded) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, imageOne->getSize().x, imageOne->getSize().y, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageOne->getPixelsPtr()); glGenerateMipmap(GL_TEXTURE_2D); } delete imageOne; glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, texture[1]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); sf::Image* imageTwo = new sf::Image; bool isImageTwoLoaded = imageTwo->loadFromFile("Texture/awesomeface.png"); if (isImageTwoLoaded) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, imageTwo->getSize().x, imageTwo->getSize().y, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageTwo->getPixelsPtr()); glGenerateMipmap(GL_TEXTURE_2D); } delete imageTwo; glUniform1i(glGetUniformLocation(shaderProgram, "inTextureOne"), 0); glUniform1i(glGetUniformLocation(shaderProgram, "inTextureTwo"), 1); GLenum error = glGetError(); std::cout << error << std::endl; sf::Event event; bool isRunning = true; while (isRunning) { while (window.pollEvent(event)) { if (event.type == event.Closed) { isRunning = false; } } glClear(GL_COLOR_BUFFER_BIT); if (isImageOneLoaded && isImageTwoLoaded) { glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture[0]); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, texture[1]); glUseProgram(shaderProgram); } glBindVertexArray(vao); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, nullptr); glBindVertexArray(0); window.display(); } glDeleteVertexArrays(1, &vao); glDeleteBuffers(1, &vbo); glDeleteBuffers(1, &ebo); glDeleteProgram(shaderProgram); glDeleteTextures(2,texture); return 0; } and this is the vertex shader
      #version 450 core layout(location=0) in vec3 inPos; layout(location=1) in vec2 inTexCoord; out vec2 TexCoord; void main() { gl_Position=vec4(inPos,1.0); TexCoord=inTexCoord; } and the fragment shader
      #version 450 core in vec2 TexCoord; uniform sampler2D inTextureOne; uniform sampler2D inTextureTwo; out vec4 FragmentColor; void main() { FragmentColor=mix(texture(inTextureOne,TexCoord),texture(inTextureTwo,TexCoord),0.2); } I was expecting awesomeface.png on top of container.jpg

    • By khawk
      We've just released all of the source code for the NeHe OpenGL lessons on our Github page at https://github.com/gamedev-net/nehe-opengl. code - 43 total platforms, configurations, and languages are included.
      Now operated by GameDev.net, NeHe is located at http://nehe.gamedev.net where it has been a valuable resource for developers wanting to learn OpenGL and graphics programming.

      View full story
    • By TheChubu
      The Khronos™ Group, an open consortium of leading hardware and software companies, announces from the SIGGRAPH 2017 Conference the immediate public availability of the OpenGL® 4.6 specification. OpenGL 4.6 integrates the functionality of numerous ARB and EXT extensions created by Khronos members AMD, Intel, and NVIDIA into core, including the capability to ingest SPIR-V™ shaders.
      SPIR-V is a Khronos-defined standard intermediate language for parallel compute and graphics, which enables content creators to simplify their shader authoring and management pipelines while providing significant source shading language flexibility. OpenGL 4.6 adds support for ingesting SPIR-V shaders to the core specification, guaranteeing that SPIR-V shaders will be widely supported by OpenGL implementations.
      OpenGL 4.6 adds the functionality of these ARB extensions to OpenGL’s core specification:
      GL_ARB_gl_spirv and GL_ARB_spirv_extensions to standardize SPIR-V support for OpenGL GL_ARB_indirect_parameters and GL_ARB_shader_draw_parameters for reducing the CPU overhead associated with rendering batches of geometry GL_ARB_pipeline_statistics_query and GL_ARB_transform_feedback_overflow_querystandardize OpenGL support for features available in Direct3D GL_ARB_texture_filter_anisotropic (based on GL_EXT_texture_filter_anisotropic) brings previously IP encumbered functionality into OpenGL to improve the visual quality of textured scenes GL_ARB_polygon_offset_clamp (based on GL_EXT_polygon_offset_clamp) suppresses a common visual artifact known as a “light leak” associated with rendering shadows GL_ARB_shader_atomic_counter_ops and GL_ARB_shader_group_vote add shader intrinsics supported by all desktop vendors to improve functionality and performance GL_KHR_no_error reduces driver overhead by allowing the application to indicate that it expects error-free operation so errors need not be generated In addition to the above features being added to OpenGL 4.6, the following are being released as extensions:
      GL_KHR_parallel_shader_compile allows applications to launch multiple shader compile threads to improve shader compile throughput WGL_ARB_create_context_no_error and GXL_ARB_create_context_no_error allow no error contexts to be created with WGL or GLX that support the GL_KHR_no_error extension “I’m proud to announce OpenGL 4.6 as the most feature-rich version of OpenGL yet. We've brought together the most popular, widely-supported extensions into a new core specification to give OpenGL developers and end users an improved baseline feature set. This includes resolving previous intellectual property roadblocks to bringing anisotropic texture filtering and polygon offset clamping into the core specification to enable widespread implementation and usage,” said Piers Daniell, chair of the OpenGL Working Group at Khronos. “The OpenGL working group will continue to respond to market needs and work with GPU vendors to ensure OpenGL remains a viable and evolving graphics API for all its customers and users across many vital industries.“
      The OpenGL 4.6 specification can be found at https://khronos.org/registry/OpenGL/index_gl.php. The GLSL to SPIR-V compiler glslang has been updated with GLSL 4.60 support, and can be found at https://github.com/KhronosGroup/glslang.
      Sophisticated graphics applications will also benefit from a set of newly released extensions for both OpenGL and OpenGL ES to enable interoperability with Vulkan and Direct3D. These extensions are named:
      GL_EXT_memory_object GL_EXT_memory_object_fd GL_EXT_memory_object_win32 GL_EXT_semaphore GL_EXT_semaphore_fd GL_EXT_semaphore_win32 GL_EXT_win32_keyed_mutex They can be found at: https://khronos.org/registry/OpenGL/index_gl.php
      Industry Support for OpenGL 4.6
      “With OpenGL 4.6 our customers have an improved set of core features available on our full range of OpenGL 4.x capable GPUs. These features provide improved rendering quality, performance and functionality. As the graphics industry’s most popular API, we fully support OpenGL and will continue to work closely with the Khronos Group on the development of new OpenGL specifications and extensions for our customers. NVIDIA has released beta OpenGL 4.6 drivers today at https://developer.nvidia.com/opengl-driver so developers can use these new features right away,” said Bob Pette, vice president, Professional Graphics at NVIDIA.
      "OpenGL 4.6 will be the first OpenGL release where conformant open source implementations based on the Mesa project will be deliverable in a reasonable timeframe after release. The open sourcing of the OpenGL conformance test suite and ongoing work between Khronos and X.org will also allow for non-vendor led open source implementations to achieve conformance in the near future," said David Airlie, senior principal engineer at Red Hat, and developer on Mesa/X.org projects.

      View full story
    • By _OskaR
      Hi,
      I have an OpenGL application but without possibility to wite own shaders.
      I need to perform small VS modification - is possible to do it in an alternative way? Do we have apps or driver modifictions which will catch the shader sent to GPU and override it?
    • By xhcao
      Does sync be needed to read texture content after access texture image in compute shader?
      My simple code is as below,
      glUseProgram(program.get());
      glBindImageTexture(0, texture[0], 0, GL_FALSE, 3, GL_READ_ONLY, GL_R32UI);
      glBindImageTexture(1, texture[1], 0, GL_FALSE, 4, GL_WRITE_ONLY, GL_R32UI);
      glDispatchCompute(1, 1, 1);
      // Does sync be needed here?
      glUseProgram(0);
      glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer);
      glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                                     GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, texture[1], 0);
      glReadPixels(0, 0, kWidth, kHeight, GL_RED_INTEGER, GL_UNSIGNED_INT, outputValues);
       
      Compute shader is very simple, imageLoad content from texture[0], and imageStore content to texture[1]. Does need to sync after dispatchCompute?
  • Advertisement