Results 1 to 2 of 2

Thread: Rendering a texture grayscale using multi-texturing

  1. #1
    Junior Member
    Join Date
    May 2009
    Posts
    2

    Rendering a texture grayscale using multi-texturing

    Hello, I'm trying to render a texture as grayscale but the second texture unit operation is not being performed. Perhaps there are other issues. I've based this code off of:
    http://www.opengl.org/discussion_boa...&Number=235673

    Here is my version for the IPhone:
    Code :
    	//Set up OpenGL states
    	glDisable(GL_DITHER);
            glEnableClientState(GL_VERTEX_ARRAY);
    	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    	glEnable(GL_BLEND);
    	glEnable(GL_DEPTH_TEST);
    	glEnable(GL_TEXTURE_2D);
    	glBlendFunc(GL_SRC_ALPHA, GL_ONE);
     
    	glActiveTexture(GL_TEXTURE0);
    	glEnable(GL_TEXTURE_2D);
    	glBindTexture(GL_TEXTURE_2D, tx1);
    	glTexCoordPointer(2, GL_FLOAT, 0, textureCoords);
     
    	// Now that the texture colors have been moved up into the pseudo signed range (+0.5)
    	// We can dot them with the luminances
    	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
    	glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_ADD);
     
    	GLfloat offset[4] = { 0.5f, 0.5f, 0.5f, 1.0f };
    	glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, offset);
    	glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_CONSTANT);
    	glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
     
    	glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_TEXTURE0);
    	glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
     
     
    	// Now dot those values with the luminances (adjusted for the dot3 equation)
    	glActiveTexture(GL_TEXTURE1);
    	glEnable(GL_TEXTURE_2D);
    	glBindTexture(GL_TEXTURE_2D, grayMultiplier);
    	glTexCoordPointer(2, GL_FLOAT, 0, textureCoords);
     
    	glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE ); 
    	glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_DOT3_RGB );
     
    	// Combination equation, previous value dot3 with the luminance texture
    	glTexEnvi( GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS );
    	glTexEnvi( GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PREVIOUS );
    	glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR );
    	glTexEnvi( GL_TEXTURE_ENV, GL_SRC1_RGB, GL_TEXTURE1 );
    	glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR );
     
    	glVertexPointer(3, GL_FLOAT, 0, vertices);
    	glDrawArrays(GL_TRIANGLES, 0, vertexCount);
     
    	// Disable this texture unit
    	glDisable(GL_TEXTURE_2D);
     
    	glDisable(GL_BLEND);
    	glDisable(GL_DEPTH_TEST);
    	glDisable(GL_TEXTURE_2D);
    	glDisableClientState(GL_VERTEX_ARRAY);
    	glDisableClientState(GL_TEXTURE_COORD_ARRAY);

    Any ideas? Thanks in advance!

    Shane

  2. #2
    Junior Member
    Join Date
    May 2009
    Posts
    2

    Re: Rendering a texture grayscale using multi-texturing

    Hello,

    I found the problem. On lines like this:
    Code :
       glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_TEXTURE0);

    I was using the wrong constant, GL_TEXTURE0, instead of GL_TEXTURE. That mistake disabled the rendering pipeline.

    Shane

Similar Threads

  1. Replies: 4
    Last Post: 03-16-2011, 02:20 AM
  2. questions of rendering to texture
    By pset_chris in forum OpenGL ES 1.X - fixed function hardware
    Replies: 0
    Last Post: 10-20-2009, 12:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •