Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Color problem when blending two pipeline

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2005
    Location
    China
    Posts
    19

    Color problem when blending two pipeline

    I am going to write a perfraglighting shader with wireframe covering on mesh surface.
    I blend programable pipeline and original pipeline of OpenGL in my code, showed as follow:

    glNewList(CallList[2],GL_COMPILE);
    glUseProgram(MyShader::Prog);//launch Shader
    glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
    glEnable(GL_POLYGON_OFFSET_FILL);
    glPolygonOffset(1.0,1.0);
    glCallList(CallList[0]);//Using point array list
    glDisable(GL_POLYGON_OFFSET_FILL);
    glDisable(GL_LIGHTING);
    glUseProgram(0);//shut down the shader
    glColor3f(0.0,0.0,0.0);//Setup the line color
    glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
    glCallList(CallList[1]);//Draw Wireframe with
    //OpenGL inside pipeline in glvertex3f mode
    glEnable(GL_LIGHTING);
    glUseProgram(MyShader::Prog);
    glEndList();

    And in my frag shader, I use following code to produce the final color:
    gl_FragColor = gl_FrontLightModelProduct + Iamb + Idiff + Ispec;

    Everything is ok when I just use programable pipeline without adding original pipeline to my scene, but when I switch the rendering state to wireframe on solide surface, the color of whole object turn to be the color set by glColor(x,x,x) which is the real reason to this problem I think. Originally, I just set color blue to each vertex in vertex array, and wanna use black to line out the wireframe of the mesh.

    I wanna ask are there any drawbacks in my code, and how to manage the correct color state in rendering pipeline.

    thanks~

  2. #2
    Junior Member Newbie
    Join Date
    Sep 2005
    Location
    China
    Posts
    19

    Re: Color problem when blending two pipeline

    Finally, I get it.
    Ah, I have tried a lot of methods, and finally find that I missed some important function in my code.
    The correct one should be
    Code :
     	glNewList(CallList[2],GL_COMPILE);;
    		glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);				
    		glEnable(GL_POLYGON_OFFSET_FILL);
    		glPolygonOffset(1.0,1.0);	
    		glCallList(CallList[0]);
    		glDisable(GL_POLYGON_OFFSET_FILL);	
    		glDisable(GL_LIGHTING);
    		glPushMatrix();//!!!
    		glPushAttrib(GL_CURRENT_BIT);//!!!
    		glUseProgram(0);
    		glColor3f(0.0,0.0,0.0);
    		glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);	
    		glCallList(CallList[1]);
    		glPopAttrib();//!!!
    		glPopMatrix();//!!!
    		glEnable(GL_LIGHTING);
    		glUseProgram(MyShader::Prog);
    	glEndList();

    Good job~

Posting Permissions

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