Jump to content
  • Advertisement
Sign in to follow this  
OpenGL_Guru

OpenGL Using GL_BLEND for Texture Coordinates. **EDIT--solved(i think)..

This topic is 4876 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

i hope that i can explain my problem without writing too much. basically i am drawing a QUAD using GL_TRIANGLE_STRIPS - which is in a display list. each point of the quad(i.e., x, y z point) has an attribute, lets say a depth. the depth is then sent to a color function that determines what color the point will be based on that particular depth value in relation to the min and max depth over the course of the whole quad. this min and max value has already been calculated. Now, the coloring is done not by using glColor but by using texture coordinates -- i made a color ramp in Photoshop. here is some sample code. main.cpp ===========
 glPushMatrix();
   glColor4f(1, 1, 1, 1);
   glDisable(GL_LIGHTING);
   glEnable(GL_BLEND);
   if(wireframe)
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
   if(dem)
    foobar->draw();
   glEnable(GL_LIGHTING);
   glDisable(GL_BLEND);
  glPopMatrix();



draw function in class. ========================
void class::draw(GLuint &mylist)
{
 int index;
  
 mylist = glGenLists(1);
 glNewList(mylist, GL_COMPILE);
 
 for(int i = 0; i < yplane-1; i++)
  {
    glBegin(GL_TRIANGLE_STRIP);
	for(int j = 0; j < xplane; j++)
 	 {
       index = i*xplane+j;


	   if(mySection[index].points[0].sal == -99.0)
	    glTexCoord1f(getColor(mySection[index].points[0].sal));
	   else
		{ (tex_quad_color == 1) ? glTexCoord1f(getColor(mySection[index].points[0].sal)):
	     (tex_quad_color == 2) ? glTexCoord1f(getColor(mySection[index].points[0].temp)) : glTexCoord1f(getColor(mySection[index].points[0].vel));}
		 glVertex3f(plane[index].x, plane[index].y, plane[index].z);
	
	       
	   index += xplane; 
       	 
	    if(mySection[index].points[0].sal == -99.0)
	     glTexCoord1f(getColor(mySection[index].points[0].sal));
	   else 
		 {
		 (tex_quad_color == 1) ? glTexCoord1f(getColor(mySection[index].points[0].sal)):
	     (tex_quad_color == 2) ? glTexCoord1f(getColor(mySection[index].points[0].temp)) : glTexCoord1f(getColor(mySection[index].points[0].vel));}
	     glVertex3f(plane[index].x, plane[index].y, plane[index].z);
		
	 }

	glEnd();

  }

  glEndList();

}



getColor function ==================
float GDEM::getColor(float num)
{
 float tex_result;

 (tex_quad_color == 1) ? tex_result = (num - max_sal)/(max_sal - min_sal) :
 (tex_quad_color == 2) ? tex_result = (num - max_temp)/(max_temp - min_temp) : tex_result = (num - max_vel)/(max_vel - min_vel);
 
 if(tex_result < 0)
  tex_result*=-1;
   
   if(num == -99.0)
    tex_result = 1.0;

  temp_color = tex_result;
 
  return tex_result;
}



dont worry about some of those variables. just rest assured that it does work and it does what i need it to do. :) what i would like to do, in my draw function is to be able to add some code when a certain point does indeed equal to -99. this number has no meaning other than the fact its a flag i dont want to simply get the texture coordinate but also do a blend on the texture coordinate, i.e. transparency. since in my main i have the whole texture has opaque, and the fact the push and pop matrix does not work inside a glbegin/end, how would i make certain points of my strip more transparent than others? doing a simple glColor4f(1, 1, 1, 0.5) along with the enable and disabling of blend does not work, been there, tried that. if you would happen to have any input it would be much appreicated and some rating++ along your way. thanks in advance! [Edited by - OpenGL_Guru on June 14, 2005 8:22:48 AM]

Share this post


Link to post
Share on other sites
Advertisement
Dude, you seriously need to change your name. [razz]

If you just need a section to be more transparent than others, set the vertex colour at each vert and reduce the alpha when you need it to be more transparent. If you don't want any additional effect from the vertex colours set the rest to white.

If thats not good enough you're going to have to describe in better detail what exactly you're after and why that doesn't work...

Share this post


Link to post
Share on other sites
well i have tried what you have said, that is for each vert just make that vert completely transparent or completely opaque but that does not work..well i should say it doesnt work how i had hoped it would.

is there something unique about making texture assignments transparent? just trying different ways of doing things so please dont chastise me b/c i might not be as fluent in GL as you.

and i picked my name cos it was one of very few that wasnt taken that i could think of the time.. and in time anyway i will become a guru :) remember we all are beginners at one time or another.

Share this post


Link to post
Share on other sites
Quote:
Original post by OpenGL_Guru
well i have tried what you have said, that is for each vert just make that vert completely transparent or completely opaque but that does not work..well i should say it doesnt work how i had hoped it would.

So, uh, how does it work? Or rather, what doesn't work right with that method?

Quote:
is there something unique about making texture assignments transparent?

Unless you've messed with the default state, textures are modulated (multiplied) by the vertex colour. And remember that vertex colours are interpolated across a triangle's surface. If you want specific (whole) triangles transparent without the interpolation you'll have to duplicate vertices (or use a second mask texture and tinker with its coords).

Share this post


Link to post
Share on other sites
well the problem i was having was that going from land to water for my texture color when there is a sudden drop off, you would get a band of colors as the texture went from one end to the other. so i was trying to do a blending on the the texture coordinates if there was a water value(-99). however even with this blending you still get the band of colors even though they arent as visible.
that was my reasoning behind this thread. maybe i didnt spell it out clear enough.

anyway what i did was, was to look ahead and see if the next value was going to be a water value(-99)..if so save the last texture color. then use that same color in that value. what you get is a constant blending of one color instead of the color bands in the texture. so problem solved... i think.. there are still some areas where it doesnt quite work. i might have to insert a little more logic/checking to make sure i can get the blending between all vertices.

anyway thanks for your insight/help.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!