Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

uncutno

use texture as alpha, not vertex colors!

This topic is 5630 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello! I have big problem... i have searched gamedev many times, searched google, done everything exspected before throwing this question at you! (getting realy frustrated) problem: i have a texture (loaded from RGB/.bmp) witch is a black and white alpha picture (no alpha channel, dont want it!) i want to use this as the alpha channel when i draw my particles/text ... everything... (more presisely: i want the texture to be used as alpha, while the colors is defined by th vertexes (glColor4f())) This is no problem with blending: glBlendFunc(GL_SRC_ALPHA,GL_ONE); and everything works fine... i kan make my particles red, white, grenn and all other colors but one! black! the blending uses the vertex color as blending factor as well!!! how can i avoid this??? color 1,1,1,0 turns out transparent as it should, but also 0,0,0,1 witch in my opinion should be black! please help! from my research i got the following ansvers, but i dont want any of these... "use the alpha chanel in the picture..." "create a .tga loader instead of .bmp loader" "calculate the alphachannel from the rgb before creating the picture" and so on... my simple question: is it imposible, to only use texture color, and vertex alpha as blending factors, while the vertex colors is rendered as it is??? (with .bmp and only rgb texture, not rgba texture) if not posible, a simple ''no'' is also aprechiated!

Share this post


Link to post
Share on other sites
Advertisement
well, it does :-) it turns the black part of the texture transparent... dont use any extension.
if i turn it off, the black part of the texture is also rendered!

found it at NeHes lesson 17 "2D texture fonts"...
i have a nvida gf4, but the lesson should work on any hardware... (i think NeHe would change it, if it did not work generaly)...

have also played with aloth of other glBlendFunc settings, but none gave the right result...

i guess many others had the same problem, after playing with the NeHe code, and tried to render black text..

have also searched lesson 17, but found nothing!

Share this post


Link to post
Share on other sites
It is possible but I belive only with use of some extensions (NV register combiners, ATI texture shaders, ARB_FP). But consider one thing first. Why do you even wnat RGB part of texture if you only use it for alpha? Just load it as alpha texture and you will have a lot less trouble + a small speed increase + lower video memory usage. What eles could you wish for?

You should never let your fears become the boundaries of your dreams.

Share this post


Link to post
Share on other sites
:-) thanks!
i must say, that many of the Nehe toturials use this func, and it worked on my old ATI rage fury pro card... (old simple card, with litle extensions, no need to argu about it anyway...

i think i am getting closer:

_DarkWIng_:
"Just load it as alpha texture"

do you mean calculate the alpha channel from the rgb, or is there something called "A alpha texture"... witch creates itselfe from a .bmp file, just by changing a flag in my gluBuild2DMipmaps func??? (hope so!!!)
can you change the format variable in the func, whitout changingn the picture file type???

:-) thanks again!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
If you look in the OpenGL specification (available in PDF off the opengl.org front page) you''ll see what color value comes out of a texture in different formats, and you''ll see how different texture environment modes apply to the incoming color value.

I think you''re confused, because there are two problems:

1) How to take a b/w image and upload it as GL_ALPHA texture

2) How to combine incoming fragment color with output of GL_ALPHA texture to generate the fragment you want to blend


The answer to 1) is, most easily, to re-pack your texture to a one-byte-per-pixel texture after you''ve loaded it, and upload that as GL_ALPHA, ..., GL_ALPHA, GL_UNSIGNED_BYTE, dataPtr. I''m assuming you loaded it as a 32-bit BMP image here. If you loaded it as an 8 bit grayscale BMP, then you probably already have the right data (but create an image with the pixel values 0, 255, 128 and 3, load it, and look at the data in memory to make sure).

The answer to 2) is found on page 154 of the 1.4 version of the OpenGL specification. When the underlying texture mode is GL_ALPHA, and the texture environment mode is GL_REPLACE, then the RGB part will be passed through from vertex colors, but the alpha portion will be replaced by the data that comes in from the GL_ALPHA texture.


Share this post


Link to post
Share on other sites
thanks AP for you time!
actualy did not know about the OpenGL specification file... surfed the MSDN for ages... but now i know better! :-)

i think the outcome will be that i create a simple texture creation tool, witch make it posible to mix one or two RGB bmp pictures into one any way i want... (1 as color 2 as alpha/alpha from rgb/rgb to only alpha and so on...)

thanks!

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!