PDA

View Full Version : Ignoring Pixels on a Image



Fernando
01-25-2002, 07:10 AM
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!

Pat
01-25-2002, 07:35 AM
Use alpha blending anyway...

Fernando
01-25-2002, 07:42 AM
Thank you Pat! But i wouldn't like to use Alpha Blend...

Isnt' There a way to do that without it?

nexusone
01-25-2002, 08:02 AM
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.

Bob
01-25-2002, 10:20 AM
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.

Fernando
01-25-2002, 10:39 AM
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!!!!

nexusone
01-25-2002, 11:28 AM
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:
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!!!!

Fernando
01-25-2002, 04:27 PM
OK nexusone..! :-)

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!

zed
01-25-2002, 08:37 PM
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

Fernando
01-26-2002, 04:16 AM
Thank you a lot ZED! this is all I wanted to do!!!

Fernando
01-26-2002, 09:26 AM
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!

zed
01-26-2002, 11:14 AM
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

Bob
01-26-2002, 12:05 PM
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.

Fernando
01-27-2002, 12:56 AM
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!

Fernando
01-27-2002, 02:52 AM
Haaa

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

zed
01-27-2002, 03:50 PM
the most likely case is youre not fill limited (make the window very small 100x100 what happens to the fps)

Fernando
01-27-2002, 07:13 PM
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

01-27-2002, 08:11 PM
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 http://www.opengl.org/discussion_boards/ubb/smile.gif

Zw
01-27-2002, 11:02 PM
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 (http://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).]

Fernando
01-28-2002, 03:42 AM
Thank you a lot Zw!!!!!!!

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

THank you very mutch for this!

Furrage
01-28-2002, 05:10 AM
Hey Fernando, I'm Jamaican and do my development on a Cyrix PR/300 (its really a P/233). So I know the headaches of trying to get a good framerate and not having enough money to invest in a good machine. Also, like you, I want to design games and programs which will work on low end machines (a lot of people I know don't have OpenGL compliant cards). There's only one way to do this. Optimise your code. Remember, Wolfenstein ran on a 386 and Doom on a 486, which by today's standard is a miracle. But it can be done. Pre render some of your images to bitmaps and blit them to screen. Precompute some of your calculations if possible and play around with some states to see what speeds things up and what does not.

Things may be harder for you than most persons, but I've never seen a challenge that people can't work around (trust me, Jamaicans are famouse for that). It means your going to have to put in a little more effort, do a little more research and have a little more patience. Also, make a nice marketing plan for your game when it's ready and let us know where we can download the demo from http://www.opengl.org/discussion_boards/ubb/smile.gif

nexusone
01-28-2002, 06:13 AM
I can see your point about those who cannot afford the high-end 3D graphics cards seem to be left out. But OpenGL or Direct X also was created with 3D graphics in mind, not with the low-end user in mind. Most games created in the past few years require some hardware acceleration to perform well.

I have thought that some sort of OpenGL lite for support of older machines, so that people in poor countries could have some access to better games.

I myself have to stick to a budget on how much I can spend on my hobby of programming. After twos years of using an old video card, which at the time did very well for me, I found that all the new OpenGL demos would ether run too slow or not at all on it. I purchased a low end ATI Radeon card for $44.00 US dollars, which was in my budget. And now all the demos and games run well.

One drawback to being in computer programming is you always need to get better hardware to keep up with the market.

Sorry that you spent so much money and feel like it is all for nothing. I myself have been using all the free on-line tutor's to learn OpenGL. I also purchased an OpenGL programmers book, but I found one used for only $10.00 US dollars.

When I was your age growing up I also came from a poor family, but I loved computers. So I found any neighbor or people in my town that needed odd jobs to be done and saved up money to buy my computer stuff as not to burden my parents.

I have also found that if you need help finding hardware or books, the people on the internet will help you find things within your budget. So before you spend a lot of money ask around to see if you can get it used or at a discount.

Also you could post your program, and let us look at it. Maybe we could give you tip's as to what you can do to speed it up.



Originally posted by Fernando:
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

Miguel_dup1
01-28-2002, 07:30 AM
Originally posted by Fernando:
Thank you a lot Zw!!!!!!!

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

THank you very mutch for this!

I have a few web servers you can post your code on if you need space on the net...
Let me know!

And if you (or a few fellows from this board) are willing to pay for shipping, I could send you an old video card that supports OpenGL. It is an ATI xpert 128, 16 megs of memory. Not the greatest, but it supports OpenGL and it is not a bad board.

Books? You can find some books such as the red book in PDF format, and the super bible book in HTML format for free. It is a good option. I need a host to send it to.... Let me know!!

Cheers.

p.s. I am from Venezuela, and I know first hand what it feels like to want tools to educate yourself with and not have access to it because of a budget. IT SUCKS!!!!

zed
01-28-2002, 05:01 PM
>>I know that I have a old computer (Duron 950, 128MB and 4MB video card)<<

old computer?
what make of video card do u have, is it an onboard one, try to find the chipset (perhaps it doesnt support opengl hardware acceleration)

01-28-2002, 06:25 PM
If it does turn out your card doesn't support OpenGL, it will probably still support directx. So you can get a OpenGL wrapper (from SGI I think). THen it should work fine.