Advertisement

Simple Newbie Texture Fading

Started by September 25, 2002 05:15 PM
11 comments, last by spud 22 years, 5 months ago
I just started coding with OpenGL a few days ago after watching some demos. I''ve known about demos for a long time, but for some reason I was just now inspired to get into the art myself. I''ve worked my way through most of the NeHe tutorials now, and have learned a great deal about not just OpenGL, but C++ and MSVC. Anyhow, enough with the introductions... I''m using the IPicture code to load jpegs. So now I have several textured objects on the scene that blend well, etc. I''m having trouble getting a textured object to fade in from black or to fade out to black. I realize that jpegs don''t support the alpha channel, but I thought the IPicture code just converted a jpeg on a the disk to a bitmap in the memory. Help?
You don''t need alpha chanel to fade in/out textures. Just enable blending with color blendig mode and slowly fade your color from white ot black to fade out and from black to white to fade in.
You should never let your fears become the boundaries of your dreams.
Advertisement
Cool, but glColor3f() or glColor4f don''t seem to have any effect whatsoever on my texture...
The BMP file doesn''t support alpha chanel.

Why don''t you use TGA file ?

TGA supports alpha channel and on my site, I''ve a example for using that thing.

http://ibelgique.ifrance.com/Slug-Production/

========================
Leyder Dylan
http://ibelgique.ifrance.com/Slug-Production/
========================Leyder Dylan (dylan.leyder@slug-production.be.tf http://users.skynet.be/fa550206/Slug-Production/Index.htm/
Even though bitmaps and jpegs don't support alpha channel, if you enable blending and use an appropriate blending function (can't remember the parameters off the top of my head) you can still use glColor4f Eg(glColor4f(1.0f, 1.0f, 1.0f, fade) where fade is a decreasing/increasing value) to cause alpha changes on a texture.

[edited by - tuita on September 26, 2002 10:19:56 PM]
Make sure you''re using the correct texture environment.

The default should be GL_MODULATE (finalColor = textureColor*vertexColor) and this is what you need to blend the texture using glVertex4f(...).

If you''re using GL_REPLACE as texture environment it won''t work because finalColor = textureColor.


Hope this will be useful.

Previously "Krohm"

Advertisement
Still can''t get it to work. The texture environment is on the default (GL_MODULATE), and blending is enabled. The blending works just fine; looks great. But glColor4f() just doesn''t affect the texture in any way. Here''s some code:
void DrawFirstCredit(GLvoid){ glLoadIdentity(); glBlendFunc(GL_SRC_ALPHA,GL_ONE); glEnable(GL_BLEND); glDisable(GL_DEPTH_TEST); glBindTexture(GL_TEXTURE_2D, texture[3]); glTranslatef(-0.353f, -0.389f, -1.0f); glBegin(GL_QUADS);  glColor4f(1.0f,1.0f,1.0f,0.1f); // In reality, 0.1f would be a changing variable but I just have it constant right now to verify that it is having no effect on this texture at all.  glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.195f, -0.025f, 0.0f);  glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.195f, -0.025f, 0.0f);  glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.195f,  0.025f, 0.0f);  glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.195f,  0.025f, 0.0f); glEnd(); glDisable(GL_BLEND); glEnable(GL_DEPTH_TEST);} 
Not 100% sure, but shouldn''t you set the blend function to something like:

glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
(NOTE: GL_ONE_MINUS_SRC_ALPHA is just a guess at the constant name. But I think its something like this.)

I think the blending function you are using will just set alpha to 1.0 regardless of what you use elsewhere.
Maybe you have to go:
glEnable(GL_COLOR_MATERIAL); 


Firebird Entertainment
“[The clergy] believe that any portion of power confided to me, will be exerted in opposition to their schemes. And they believe rightly: for I have sworn upon the altar of God, eternal hostility against every form of tyranny over the mind of man” - Thomas Jefferson
Okay, enabling GL_COLOR_MATERIAL does work, but causes one undesirable side-effect. You have to disable lighting, turn on GL_COLOR_MATERIAL, draw, then disable GL_COLOR_MATERIAL, and then re-enable lighting. If you don''t, the entire screen goes black as soon as you try to change colors/alphas. No problem, except the lighting won''t come back on, even after I am done drawing the effect and have re-enabled lighting. Any ideas?

This topic is closed to new replies.

Advertisement