Ignoring Pixels on a Image

Hi People!!!

I would like to know, if there is a way in OPENGL to Ignore Pixels in a Image.

For Example:

if I have a Image Like this (it’s only a example):

0, 2, 2, 2, 2, 0
0, 2, 0, 0, 2, 0
0, 2, 0, 0, 2, 0
0, 2, 0, 0, 2, 0
0, 2, 2, 2, 2, 0
0, 2, 0, 0, 2, 0
0, 2, 0, 0, 2, 0
0, 2, 0, 0, 2, 0
0, 2, 0, 0, 2, 0

Let’s think it’s a image of letter ‘A’. The number 2, represent black (0, 0, 0), and the number 0 represent WHITE (255, 255, 255).

If it were the case, is there a way to tell OpenGL that when he encounter the number 0, he dont’t need to paint the color on the screen?

Note that I don’t want to use Alpha Blend.

Thank’s everybody!

Use alpha blending anyway…

Thank you Pat! But i wouldn’t like to use Alpha Blend…

Isnt’ There a way to do that without it?

If you are just wanting to put text on top of you scene.
Maybe look at using GLUT text functions, bitmap or stroke.
They will give you the effect discribe in your message.

If you don’t want to use alpha blending, then use the alpha function. It’s basically the same, but you stop process fragments in an earlier stage. Have a look at glAlphaFunc.

OK! Thanks all of you! I’m going to try using glAlphaFunc, but I still want to know if there is a way to ignore Pixels on Painting in OPENGL.

I’ll be surprised if someone tell that a API like OpenGL doesn’t have a function to ignore Pixels on drawing things.

Thank you again guys!!!

There is and we have told you over and over the Alpha function does this!!!

Using the Alpha function you can map any pixel to be transparent on a image and let you see the background objects.

It may not do it, the way you would like but the function to do this is there.

Maybe your mind set is how you would do it if you where writing a directly to the screen like object sprite type function.
But then you would not have the other advantages of doing the OpenGl way.

Originally posted by Fernando:
[b]OK! Thanks all of you! I’m going to try using glAlphaFunc, but I still want to know if there is a way to ignore Pixels on Painting in OPENGL.

I’ll be surprised if someone tell that a API like OpenGL doesn’t have a function to ignore Pixels on drawing things.

Thank you again guys!!![/b]

OK nexusone…! :slight_smile:

When Bob said
"If you don’t want to use alpha blending, then use the alpha function. It’s basically the same, "

i thought he’s saying that glAlphaFunc does the same work of glBlendFunc!

I took a look in the BLUE BOOK for glAlphaFunc function, and I didn’t understand that…

What I understood is that glAlphaFunc do a test with a Transparent pixel already in the buffer, and depending of the “func” and “ref” parameters, the pixel is plotted on the screen…

Am’I right?

thanks again!

with your image add an alpha channel make the alpha values of the pixels u dont wanna draw 0 and make the other pixels 255
go
glAlphaFunc( GL_NOTEQUAL, 0 );
glEnable( GL_ALPHA_TEST );
only pixels with alpha values not equal to 0 will be drawn

Thank you a lot ZED! this is all I wanted to do!!!

Ok Guys! I tested my code with glAlphaFunc, and everything worked fine for one thing…

The FPS are too slow…
I tried using glAlphaFunc and glBlendFunc, and both two got the same FPS…

I don’t want to be boring, but Isn’t there a way to ignore pixels withouut using glAlphaFunc ou glBlendFunc?

Sorry, and thanks again!

no need for blending (its slower also)
alpha testing is very very fast
comment out glEnable( GL_ALPHA_TEST ) if the fps goes much higher then theres something wrong (eg u have software rendering) because it hardly makes no difference to

image size 256;
texture disabled
depth test disabled
alpha test disabled
backface culling disabled
blend disabled
scissor test disabled
depthwrite mask disabled
colorwrite mask ENABLED
quad: – 341.521 Mpixels/sec

image size 256;
texture disabled
depth test disabled
alpha test ENABLED
backface culling disabled
blend disabled
scissor test disabled
depthwrite mask disabled
colorwrite mask ENABLED
quad: – 341.304 Mpixels/sec

thus enabling alpha test is 0.0635% slower
ie practically nothing, remember this is also a worst case senario, in a real app the difference is gonna be far far less

Fernando, there are three ways (that I know of) to do this. Alpha blending, alpha function, and glBitmap. That’s it. No other way. In the case you desctribed above, bitmaps will work, since the pixel is either not draw, or one single color. If the visible pixels is supposed to have different colors aswll, then you are left with only two options. glBitmap might be an option for you, if maximum speed is of lesser importance, and you are willing to mess with bytes on bitlevel.

So in practice, you have two options: Alpha blending, which is not really supposed to do things like rejecting individual pixels, and alpha testing, which is doing exactly what you are asking for.

Ok! Thank you guys!

I’ll try to use glBitmap!

Zed! Hou you told me, the diferences using glAlphaFunc or without using it is to small…

I made some tests here too… And when I activate this, the FPS continued almost the same… But when I putted a lot of images on the screen, the difference appeared…

My fps went down +/- 70%…

Thats why I don’t want tto Use Alpha Blend and AlphaFunc.!

Thank you again guys! I really apreciated your help!

Hááaaa

I’m very tired…
I don’t know what to do!

I’ve tryied a lot of things, but nothing worked fine…

Now, I thing it’s the end of this post…
I thing noone have more good sugestions for my problem…

I dont know why the command glAlphaFunc ran slowly…

Here, when I use glAlphaFunc, it spends the same FPS spended by glBlendFunc…

I thought it was normal, but Zed told it isnt…

So… I dont know what to do…

the most likely case is youre not fill limited (make the window very small 100x100 what happens to the fps)

People… sorry for this answer, but I have to exprees what I’m feeling now…

I’m very disappointed with OpenGL…

I know that I have a old computer (Duron 950, 128MB and 4MB video card), but I thought OpenGL could do more than only run application in newer 3D video-cards…

I done my father spend mutch money with OpenGL Programming Book and OpenGL Reference Guide. Maybe In the US it’s cheapper… But I live in Brazil… Here, a book costs R$ 160, and the Minimun Wage is R$ 180. For most people, a book costs a 1 month work.

I had to bag many times for my father…
I fight with a lot of peoples to be here today, trying to Learn OpenGL…

I’m seventeen, I have five years of experience in Software Development, and I always dream, and always worked to one day, construct a good game. A good game seems that it will have good graphics, good history, good playability, etc and a good engine, that allow people to run in any PC, indeppendent if it have or don’t have a 3D recent video-card.

I remember my Pentium 200, 40MB and 2MB video-memory, it used to run Quake2 in 640x480 in a very high speed… I know it’s a 256 color game based, but, today, with a PC fourt times more faster than my old PC, I can’t run just a OpenGL Example, that put on the screen just some images…

I’m very sad with this kind of thing…

I don’t know what I’m going to do…
When I started to Learn OpenGL, i thought that I could make a good game on it…

But today I see that OpenGL don’t have a good support to SOFTWARE mode.

Does it seems that I spended money, I fighted with my father, with my mother, I left my work, left my life and friends for nothing???

Sorry for this guys…

I’ll take a rest now, think about my life, and what I’m going to do with OpenGL.

sorry and thank you for hearing me

Ummm… Just thought you should know that Quake 2 used opengl, or at least a subset of their drivers. So it’s not OpenGL that’s slow, it’s your code. But that’s something you can work on

Hi, Fernando

If OpenGl can’t even solve your such a little problem, it will not become the stand.

Believe me, OpenGL is powerful. you need time to learn.

Suggest you to www.kitware.com to see what OpenGL can do for you.

I will write a example and send to you.|-)

[This message has been edited by Zw (edited 01-28-2002).]

Thank you a lot Zw!!!

my e-mail is fernandohu@bol.com.br!

THank you very mutch for this!