glTexCoord2f and pure color polygon rendering

I met a problem in makeing a simple 2d graphic engine with opengl.

That is:
I need to render a bitmap with a brightness property. It means, the brightness of the bitmap may be changed at any time while the programme running.
So, i try to draw a white blend rectangle on the same place with the bitmap to achieve my goal.
I wrote down something like this:

glBegin(GL_QUAD);
//part1 , x,y,z means some float numbers.
glTexCoord2f(x,y);glVertex3f( left , top , 0 );
glTexCoord2f(x,y);glVertex3f( left , bottom , 0 );
glTexCoord2f(x,y);glVertex3f( right , bottom , 0 );
glTexCoord2f(x,y);glVertex3f( right , top , 0 );

//part 2 : draw a white rectangle
glColor4f(1.0f , 1.0f , 1.0f , blend);
glVertex3f( left , top , 0 );
glVertex3f( left , bottom , 0 );
glVertex3f( right , bottom , 0 );
glVertex3f( right , top , 0 );
glEnd();

Obviously, it failed. Becuause in part 2, 4 vertexs has been texture mapped same as the last vertex in part 1.

Here is the question, how can i remove the texture binding or mapping?
I’ve seeken a way out, that is disable GL_TEXUTRE_2d before part2 , and enable it after draw the white rect. It works, but sounds stupid and low efficient.

So, any one can give me some other advices ?

Why do you need two parts?

By default, GL_TEXTURE_ENV_MODE is set to GL_MODULATE. It will
combine what ever color you set with the texture value.

(you can set it yourself with:
glTexEnv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

Try just:

glBegin(GL_QUAD);
glColor4f(1.0f , 1.0f , 1.0f , blend);
glTexCoord2f(x,y);glVertex3f( left , top , 0 );
glTexCoord2f(x,y);glVertex3f( left , bottom , 0 );
glTexCoord2f(x,y);glVertex3f( right , bottom , 0 );
glTexCoord2f(x,y);glVertex3f( right , top , 0 );
glEnd();

Really thanks for your reply.

  1. I’ve tried what you’ve said, but I’m sorry it didn’t work.It can make a texture transparent. And I can make the graph darker by adjust parameters in glColor4f(x,x,x,x).But I coulndn’t make it brighter.

  2. I’ve found some posted about contrast and brightness, they told me to combine an exist texture with a white quad to achieve brightness, so I worte a piece of code like what i’ve posted in my thread.

  3. I think the problem is same as : how can I draw a pure color(like white or red or…)rectangle after rendered a texture mapped object on the screen with out call glEnd() and disable GL_TEXUTRE_2d ?

At last, thanks for your reply again…

But I coulndn’t make it brighter.

Then try GL_ADD rather than GL_MODULATE. What blend function are you using that makes things “brighter”?

  1. I think the problem is same as : how can I draw a pure color(like white or red or…)rectangle after rendered a texture mapped object on the screen with out call glEnd() and disable GL_TEXUTRE_2d ?

You don’t.

I used : glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

And I’ve tryied GL_ADD. It’s the effect what I want.

But I’m now really interesting about my last question. That is how can I render a pure color(no texture mapped) rectangle after rendered a bitmap ?

But I’m now really interesting about my last question. That is how can I render a pure color(no texture mapped) rectangle after rendered a bitmap ?

What part of “You don’t” didn’t you understand? I thought it was pretty clear myself :wink:

Try using GL_COMBINE with a GL_RGB_SCALE of 2 or 4, then ramping down the colours so that your normal brightness is 0.5 or 0.25. The code would look something like this (assuming 4):

glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);
glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PREVIOUS);
glTexEnvf (GL_TEXTURE_ENV, GL_RGB_SCALE, 4);

glBegin (GL_QUADS);
glColor3f (brightness / 4, brightness / 4, brightness / 4);
glTexCoord2f (x, y); glVertex3f (left, top, 0);
glTexCoord2f (x, y); glVertex3f (left, bottom, 0);
glTexCoord2f (x, y); glVertex3f (right, bottom, 0);
glTexCoord2f (x, y); glVertex3f (right, top, 0);
glEnd ();

// restore defaults!!!
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexEnvf (GL_TEXTURE_ENV, GL_RGB_SCALE, 1);

I spent many hours in learning aboutr GL_COMBINE.
And I think it is really what I need.
Thank you for you advise.

Sorry for misunderstood last time, I think I’ve get the point this time.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.