Using alpha channel to detect inbounds clicks

Moderator
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
Member
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.

---Kelvin--
15.4" MacBook Pro revA
1.83GHz/2GB/250GB
Quote this message in a reply
Luminary
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
Member
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
Moderator
Posts: 1,560
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
Moderator
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
Member
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: http://majicjungle.com
Quote this message in a reply
Sage
Posts: 1,232
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
Moderator
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 3,241 Jan 19, 2013 08:25 AM
Last Post: sealfin
  Trouble writing PNGs with 16 bits per channel using libpng flash 2 3,913 Aug 28, 2006 11:01 AM
Last Post: flash
  Using 8-bit greyscale texture as an alpha channel? TomorrowPlusX 12 5,085 Apr 10, 2006 08:43 AM
Last Post: TomorrowPlusX
  annoying mouse clicks and GLUT problem WhatMeWorry 1 2,518 Nov 6, 2005 01:12 AM
Last Post: OneSadCookie
  Alpha Channel Woes GraySupreme 5 4,320 Jul 26, 2005 01:24 PM
Last Post: NYGhost