Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: How to calculate the X/Y Coords of the Pixel under the cursor?

  1. #1
    Newbie Newbie
    Join Date
    Jan 2015
    Posts
    1

    How to calculate the X/Y Coords of the Pixel under the cursor?

    Hi,

    i build a small 3D modelling tool which build models in Minecraft style. Each part of the model consists out of 6 primitives (Quads), each part is textured from a texture atlas. Currently i open a 2. window to edit the texture bitmap.

    Click image for larger version. 

Name:	panther.jpg 
Views:	145 
Size:	18.8 KB 
ID:	1597

    The idea now is a simple one:
    I want to repaint the texture directly on the primitive, basically pick a block and use a paint like brush to alter the pixels under the cursor, similar to the texture painter tool from blender.

    The question i have is this:

    Is there a way to calculate the X/Y Coords of the Pixel under the cursor when i click on a primitive?

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    3,002
    Quote Originally Posted by Manus1976 View Post
    Is there a way to calculate the X/Y Coords of the Pixel under the cursor when i click on a primitive?
    X/Y coords? Surely you already have those from the mouse event?

    Or do you mean the texture coordinates?

    For the latter, I'd be inclined to render the scene with a 1x1 pixel viewport using a fragment shader which stores the texture ID and texture coordinates in the framebuffer.

    Otherwise, you're looking at doing a fair amount of work in software. You can use transform-feedback mode to capture the transformed vertices; you could use a geometry shader to discard primitives which are back-facing, lie entirely outside of the clip region or which don't overlap the pointer position. But you're still likely to be left with multiple clip-space primitives, for which you'll need to determine the front-most one, then calculate the texture coordinates at the pointer position. Also, if you want to be able to pick through primitives whose texture has an alpha channel, you'll need to handle that yourself.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •