Using alpha channel to detect inbounds clicks

Posts: 133
Joined: 2008.05
Post: #1
I have a texture that will be put onto a quad, and the texture is alphamasked so that you will only see 'buttons'. Is there a way to detect to see if mouse clicks are inside the buttons?
Quote this message in a reply
Posts: 469
Joined: 2002.10
Post: #2
If your quad is just a simple transformation, then you can unproject your mouse coord into the quad space and then read the pixel alpha value from your texture buffer. This is what I did with CB.

15.4" MacBook Pro revA
Quote this message in a reply
Posts: 5,143
Joined: 2002.04
Post: #3
store the rectangles the buttons occupy and check the click against those rectangles?
Quote this message in a reply
Posts: 177
Joined: 2002.08
Post: #4
Related question: Does the alpha test affect picking, or does that work above the fragment level?
Quote this message in a reply
Posts: 1,563
Joined: 2003.10
Post: #5
I'm pretty sure picking happens above the fragment level. Don't quote me on that, though, as I can hardly call myself an OpenGL expert...

Alex Diener
Quote this message in a reply
Posts: 365
Joined: 2002.04
Post: #6
Picking only takes account of your geometry, not your textures.

Neil Carter
Nether - Mac games and comic art
Quote this message in a reply
Posts: 320
Joined: 2003.06
Post: #7
I'd make a plist containing properties for each of the buttons... including texture coords, clickable rect (or clickable anything else for that matter), whether it is toggle / click, its position on the screen etc etc.

Then your button class can figure everything out, do the drawing, and do simple point in rectangle collision when clicked.... bound to be much faster and easier than screwing with openGL alpha stuff

Chopper, iSight Screensavers, DuckDuckDuck:
Quote this message in a reply
Posts: 1,234
Joined: 2002.10
Post: #8
Depends on your button complexity. Reading back one pixel from the framebuffer is probably faster than testing a thousand rectangles.
Quote this message in a reply
Posts: 133
Joined: 2008.05
Post: #9
Since I want to keep it fairly data-driven without a lot of extra hassle work, I'm going to have to use the image itself. Kelvin, usually when I create a texture I dispose of the buffer the image is stored in. Are you saying I should hold onto this or is there another way to access it? Also, where is the alpha value stored in that buffer? I would assume something like this:

Get the click point in global coordinates.
Convert to local coordinates of the quad.
Retrieve the GLubyte at imageData[x+y*width].
alpha = 0001 & (byte).

Is a GLubyte 4 bits? Because that wouldn't make any sense...
edit: Nevermind, I am ********. I didn't even think of how the image was stored. But the original question still remains about keeping the buffer around or getting it some other way?
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  OpenGL Alpha Channel Problem Moganza 1 5,742 Jan 19, 2013 08:25 AM
Last Post: sealfin
  Trouble writing PNGs with 16 bits per channel using libpng flash 2 5,831 Aug 28, 2006 11:01 AM
Last Post: flash
  Using 8-bit greyscale texture as an alpha channel? TomorrowPlusX 12 8,470 Apr 10, 2006 08:43 AM
Last Post: TomorrowPlusX
  annoying mouse clicks and GLUT problem WhatMeWorry 1 3,313 Nov 6, 2005 01:12 AM
Last Post: OneSadCookie
  Alpha Channel Woes GraySupreme 5 6,415 Jul 26, 2005 01:24 PM
Last Post: NYGhost