tutorail 19

Started by
10 comments, last by jouley 17 years, 1 month ago
Hello, I need help :) in this tutorial, http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=19 can someone explain how the color infulence here, when we are using a mapping? // Draw The Particle Using Our RGB Values, Fade The Particle Based On It's Life glColor4f(particle[loop].r,particle[loop].g,particle[loop].b,particle[loop].life); glBegin(GL_TRIANGLE_STRIP); // Build Quad From A Triangle Strip glTexCoord2d(1,1); glVertex3f(x+0.5f,y+0.5f,z); // Top Right glTexCoord2d(0,1); glVertex3f(x-0.5f,y+0.5f,z); // Top Left glTexCoord2d(1,0); glVertex3f(x+0.5f,y-0.5f,z); // Bottom Right glTexCoord2d(0,0); glVertex3f(x-0.5f,y-0.5f,z); // Bottom Left glEnd(); Thanks a lot. Maya
Advertisement
It multiplies that color with whatever color it gets from the texture. And I guess the texture is black and white(grayscale). And if you multiply a color with a gray color you get different intensities of that color. For example multiplying a medium gray color(0.5,0.5,0.5)(RGB) with bright red(1.0,0.0,0.0)(RGB) you get a medium red color(0.5,0.0,0.0)(RGB)..
thank you,

i tried doing that, but i got only the origion picture, without the changed color after thr multiply.
should i write something special for that???

thank again.
Quote:Original post by Maya86
thank you,

i tried doing that, but i got only the origion picture, without the changed color after thr multiply.
should i write something special for that???

thank again.


Do you happen to have lighting enabled?
no, I dont.

void renderParticle(){
int index;
float x, y ,z;
explosion_list_element* curr_element = explosionList.first;
explosion_list_element* prev_element = curr_element;
glDisable(GL_LIGHTING);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, particleTexture);

while(curr_element != NULL){
curr_element->renderNum++;
curr_element->delay++;
// Loop Through All The curr_element->particles
for (index=0; index < MAX_PARTICLES; index++)
{
// If The curr_element->particle Is Active
if (curr_element->particle[index].active)
{
// Grab Our curr_element->particle X Position
x=curr_element->particle[index].x;
// Grab Our curr_element->particle Y Position
y=curr_element->particle[index].y;
// curr_element->particle Z Pos
z=curr_element->particle[index].z;

// Draw The Particle Using Our RGB Values, Fade The
//Particle Based On It's Life
glColor4f( curr_element->particle[index].r,
curr_element->particle[index].g,
curr_element->particle[index].b,
curr_element->particle[index].life);

printf("%lf %lf %lf\n", curr_element->particle[index].r,
curr_element->particle[index].g,
curr_element->particle[index].b);

// Build Quad From A Triangle Strip
glBegin(GL_TRIANGLE_STRIP);
{
// Top Right
glTexCoord2d(1,1); glVertex3f(curr_element->pos.x + x+0.5f,
curr_element->pos.y + y+0.5f,
curr_element->pos.z + z);
// Top Left
glTexCoord2d(0,1); glVertex3f(curr_element->pos.x + x-0.5f,
curr_element->pos.y + y+0.5f,
curr_element->pos.z + z);
// Bottom Right
glTexCoord2d(1,0); glVertex3f(curr_element->pos.x+ x+0.5f,
curr_element->pos.y + y-0.5f,
curr_element->pos.z + z);
// Bottom Left
glTexCoord2d(0,0); glVertex3f(curr_element->pos.x + x-0.5f,
curr_element->pos.y + y-0.5f,
curr_element->pos.z + z);
}
glEnd();

// Move On The X Axis By X Speed
curr_element->particle[index].x+=curr_element->particle[index].xi/(slowdown*1000);
// Move On The Y Axis By Y Speed
curr_element->particle[index].y+=curr_element->particle[index].yi/(slowdown*1000);
// Move On The Z Axis By Z Speed
curr_element->particle[index].z+=curr_element->particle[index].zi/(slowdown*1000);

// Take Pull On X Axis Into Account
curr_element->particle[index].xi+=curr_element->particle[index].xg;
// Take Pull On Y Axis Into Account
curr_element->particle[index].yi+=curr_element->particle[index].yg;
// Take Pull On Z Axis Into Account
curr_element->particle[index].zi+=curr_element->particle[index].zg;
// Reduce curr_element->particles Life By 'Fade'
curr_element->particle[index].life-=curr_element->particle[index].fade;

// If curr_element->particle Is Burned Out
if (curr_element->particle[index].life<0.0f)
{
// Give It New Life
curr_element->particle[index].life=1.0f;
// Random Fade Value
curr_element->particle[index].fade=float(rand()%100)/1000.0f+0.003f;
// Center On X Axis
curr_element->particle[index].x=0.0f;
// Center On Y Axis
curr_element->particle[index].y=0.0f;
// Center On Z Axis
curr_element->particle[index].z=0.0f;
// X Axis Speed And Direction
curr_element->particle[index].xi=float((rand()%60)-32.0f);
// Y Axis Speed And Direction
curr_element->particle[index].yi=float((rand()%60)-30.0f);
// Z Axis Speed And Direction
curr_element->particle[index].zi=float((rand()%60)-30.0f);
// Select Red From Color Table
curr_element->particle[index].r=colors[curr_element->col][0];
// Select Green From Color Table
curr_element->particle[index].g=colors[curr_element->col][1];
// Select Blue From Color Table
curr_element->particle[index].b=colors[curr_element->col][2];

}
}
}//end for
if (curr_element->delay > 25){
// Reset The Rainbow Color Cycling Delay
curr_element->delay=0;
// Change The curr_element->particle Color
curr_element->col++;


//If the color is greater than 11, we reset it back to zero.
if (curr_element->col > 11){
curr_element->col=0;
}
}

prev_element = curr_element;
curr_element = curr_element->next;
if (prev_element->renderNum == 600){
explosion_delete_element(&explosionList, prev_element);
}

}//end while
glEnable(GL_LIGHTING);
glDisable(GL_TEXTURE_2D);
}
Quote:Original post by http://www.opengl.org/resources/faq/technical/texture.htm

There are many well-meaning texture map demos available on the Web that set the texture environment to GL_DECAL or GL_REPLACE. These environment modes effectively replace the primitive color with the texture color. Because lighting values are calculated before texture mapping (lighting is a per vertex operation, while texture mapping is a per fragment operation), the texture color replaces the colors calculated by lighting. The result is that lighting appears to stop working when texture mapping is enabled.

The default texture environment is GL_MODULATE, which multiplies the texture color by the primitive (or lighting) color. Most applications that use both OpenGL lighting and texture mapping use the GL_MODULATE texture environment.

Look for the following line in your code:

glTexEnv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); /* or GL_REPLACE */

You should change GL_DECAL to GL_MODULATE, or simply delete the line entirely (since GL_MODULATE is the default).
(Emphasis mine.)

The important part is making sure you have glTexEnv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE).

Did that do the trick?
-jouley

P.S.: When posting large amounts of code like this, enclose it in [source] and [/source] tags to format it nicely and make it easy to read.
Thanks,
This is working.
But know the problem is that I need to use 2 types of maping.
The first one is :
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);the regular and the second one is
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

and i have a problem to do that together.
<source>;
void uploadParticleTextures()
{
// Create 1 texture.
glGenTextures(1, &particleTexture);
glBindTexture(GL_TEXTURE_2D, particleTexture);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
FreeImage_GetWidth(particleImage), FreeImage_GetHeight(particleImage),
0, GL_RGB, GL_UNSIGNED_BYTE, FreeImage_GetBits(particleImage));
}

void uploadTextures()
{
uploadSkyBoxTextures();
uploadParticleTextures();
}
</source>
If you need to use both of them, there's no reason why you can't. You just can't be in both DECAL and MODULATE mode at the same time, they are different modes of the same environment. You can pick which one to use on a poly-by-poly basis; simply calling glTexEnvi( ) with one or the other will change the environment mode for everything rendered until you switch it back.

Or did I misunderstand something?

(Also, you're looking for [source]. ;) )
thanks a lot. this is working. :)
thanks a lot. this is working. :)

This topic is closed to new replies.

Advertisement