Results 1 to 2 of 2

Thread: problem with glTexGen

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2004
    Location
    Vicksburg MS
    Posts
    12

    problem with glTexGen

    IM trying to use glTexGen to apply a 1D texture to a DEM based on the height of each pixel.

    The function that creates the textures is

    Code :
     void DisplayWindow::create_land_texture(unsigned long res, 
    		unsigned char start_red, unsigned char start_green, unsigned char start_blue,
    		unsigned char stop_red,  unsigned char stop_green,  unsigned char stop_blue)
    {
    	// resize the buffer to make a 1d texure of the correct size
    	land_texture.resize(3*res);
     
    	unsigned long pos = 0;
    	double w1, w2;
     
    	typedef unsigned char byte;
     
    	for(unsigned long i = 0; i < res; ++i )
    	{
    		// get the weight factors
    		w2 = double(i) / (res-i);
    		w1 = 1.0 - w2;
     
    		land_texture[pos++] = byte(w1*start_red) + byte(w2*stop_red);
    		land_texture[pos++] = byte(w1*start_green) + byte(w2*stop_green);
    		land_texture[pos++] = byte(w1*start_blue) + byte(w2*stop_blue);
     
    	}
     
    	//check to see if there is allready a texture
    	if ( land_text == 0 )
    	{
    		glGenTextures(1,&amp;land_text);
    	}
     
    	glBindTexture(GL_TEXTURE_1D,land_text);
     
     
    	//create the new texture
    	glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    	glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    	glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    	glTexImage1D(GL_TEXTURE_1D,0,GL_RGB,res,0,GL_RGB,GL_UNSIGNED_BYTE,&amp;land_texture[0]);
    }
    The display code was like this
    Code :
      	//draw other objects	
    if ( draw_surface &amp;&amp; flood_model.NumLandSurfaces())
    		{
    			if ( use_land_texture )
    			{
    				if ( make_land_texture )
    				{
    					this->create_land_texture(1024,
    						255,0,0,
    						255,255,0);
    					make_land_texture = false;
    				}
     
    				float length = flood_model.ZMax();
    				float scale = 1.0f / length;
    				float params[4] = {0,0,scale,0};
     
    				glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR);
    				glTexGenfv(GL_S,GL_OBJECT_PLANE,params);
     
    				//glMatrixMode(GL_TEXTURE);
    				//glLoadIdentity();
    				//glTranslatef(-flood_model.ZMin() / length, 0 , 0); 
    				//glMatrixMode(GL_MODELVIEW);
     
     
    			}
     
    			if ( flood_model.LandNormals(0) ) glEnable(GL_LIGHTING);
     
    			if ( use_land_texture )
    			{
    				glBindTexture(GL_TEXTURE_1D,land_text);
    				glEnable(GL_TEXTURE_GEN_S);
    				glEnable(GL_TEXTURE_1D);
    				glColor3f(1.0f,1.0f,1.0f);
    			}
    			else
    			{
    				glColor3f(.7f,.7f,.7f);
    			}
     
    			for( unsigned long i = 0; i < flood_model.NumLandSurfaces(); ++i )
    			{
    				#ifdef _DEBUG_
    				std::cerr << "Drawing land surface\n";
    				#endif	
     
    				flood_model.DrawLandSurface(i,max_display_size);
    			}
     
    			if ( use_land_texture )
    			{
    				glDisable(GL_TEXTURE_GEN_S);
    				glDisable(GL_TEXTURE_1D);
    			}
     
    			if ( flood_model.LandNormals(0) ) glDisable(GL_LIGHTING);
    		}
    The resulting color mapping was inccorect so i tried to generate texture coordinates with the x coordinates. I changed scale to 1 / flood_model.XMax() and changed the params to {0,0,scale,0}. since all teh value of x in the model are between 0 and flood_model.XMax() the value of S should be between 0 and 1. However when i deisplayed the model i hade stips along the xvalues as if the texture had wrapped. In addition the strips were of varing width.

    Anyone see what i missed.

  2. #2
    Senior Member Regular Contributor
    Join Date
    Jan 2004
    Posts
    314

    Re: problem with glTexGen

    OK, I admit it:
    1. I haven't read all that code
    2. I wonder why you would use X or Z as the source of the texture coordinate instead of Y (but then again, maybe that's because I didn't read all that code)

    Usually (unless you rotate the camera), Y points upward, so that should be the source of the texgen.

Similar Threads

  1. Replies: 3
    Last Post: 01-24-2007, 02:48 PM
  2. glTexGen problem
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 07-31-2003, 01:22 PM
  3. glTexGen
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 05-07-2001, 07:28 AM
  4. glTexGen
    By HFAFiend in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 04-01-2001, 01:41 PM
  5. glTexGen*() ????????
    By SaF in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 03-11-2001, 02:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean