Problem with GL_SMOOTH

Hello,

       I am facing a problem with GL_SMOOTH shade model and polygon mode GL_LINE.

       The problem is that when i render polygon data using 
                                       
                                   m_gl.glShadeModel(GL.GL_FLAT);

        it works fine but if i render same data using 

                                m_gl.glShadeModel(GL.GL_SMOOTH);
       it does not appears on the screen. I mean, i am not able to draw anything on the screen.
      I have set polygon mode like this
           m_gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE); for wireframe display of objects.

     if i set polygon mode like this
         m_gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL); it works fine for all cases.


     What could be a problem?, i am very frustrated about this problem.
    Any help would be appreciated.

Thanks In Advance

Is that the only line of code that you change?
Can you give an example of code where your’e facing that problem?

Are you saying that nothing shows up when you have the polygon mode set to GL_LINE AND shade mode set to GL_SMOOTH

or

if GL_SMOOTH is set, nothing shows up regardless of whether or not polygon mode is GL_LINE or GL_FILL?

Hello,

    Second one is correct,

     
             if GL_SMOOTH is set, nothing shows up regardless of whether or not polygon mode is GL_LINE or GL_FILL?

Regards

Hey,

Are you using lights in your code? And are you using materials and/or normals? And if not how are you setting the color?
I tried setting my shademodel to GL_SMOOTH and it works perfectly in my case.

You can read more about opengl and lights here --> http://www.opengl.org/resources/faq/technical/lights.htm

Hello,

        I am using both material and Lights in my code. The problem is that same data render in different ways when i use GL_FLAT  and GL_SMOOTH. 

      For Example, if i render using  GL_SMOOTH, it will render correct but if i use GL_FLAT, it ploats some vertex at different location. It completly change shape and size of the object.

Regards

Try to disable light and material, see if that changes anything (except the light and material of course).

Hello,

       I tried it but not gettting any success. I think that light and material could not be a problem because if i disable light and material, it renders in black color.

       I could not understand why it changes position of the vertex when i change shade model?

Regards

Maybe, you could show your init and display code…
It’s very strange that vertices move when you change shade model?

Hello,

         Initialization Code
        =============================================================
	// Initialize rendering context
	m_gl.glEnable(GL.GL_CULL_FACE);
	m_gl.glEnable(GL.GL_DEPTH_TEST);
	m_gl.glShadeModel(GL.GL_SMOOTH);
	m_gl.glDepthFunc(GL.GL_LESS);
	m_gl.glClearDepth(1);
	m_gl.glClearColor(0, 0, 0, 0);

	// Alpha
	m_gl.glDisable(GL.GL_BLEND);
	m_gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);

	// Lights
	for (int Jcount = GL.GL_LIGHT0; Jcount <= GL.GL_LIGHT7; Jcount++) {
		m_gl.glDisable(Jcount);
	}

	m_gl.glEnable(GL.GL_LIGHTING);
	m_gl.glFrontFace(GL.GL_CW);
	m_gl.glLightModeli(GL.GL_LIGHT_MODEL_LOCAL_VIEWER, 1);

	m_DebugFontHeight = 16;
	if (m_DeviceContext == null) {
	}

	m_Texturing = false;
	m_GenerateTexCoords = false;
	m_EnvMapOn = false;
	m_NormalizeNormals = false;

	m_ViewMatrix.setIdentity();
	m_WorldMatrix.setIdentity();

	endRendererContext();

	setActive(true);
	setRendererType("OpenGL");
	setRendererSubType("");
	return QEDResponseCode.Q3D_RENDERER_OK;

       rendering code
     ---------------------------------------------------------------------------------------

	try{
		if (m_Texturing && m_EnvMapOn && normals != null) {
			CQ3DMatrix worldview = new CQ3DMatrix();
			worldview.mul(m_ViewMatrix, m_WorldMatrix);
			for (int i = 0, face = 0; i < nbIndex; i += 3, face++) {
				CQ3DVector normal = new CQ3DVector();

				normal.assign(normals[face]);
				normal.transformNoTrans(worldview);

				if (m_NormalizeNormals) {
					normal.normalize(); // Maybe a scale ???
				}

				float UV[] = new float[2];

				UV[0] = normal.m_Vector.x * 0.5f + 0.5f;
				UV[1] = normal.m_Vector.y * 0.5f + 0.5f;

				float norm[] = new float[3];
				norm[0] = normals[face].x;
				norm[1] = normals[face].y;
				norm[2] = normals[face].z;

				m_gl.glBegin(GL.GL_TRIANGLES);
				m_gl.glNormal3fv(norm, 0);
				m_gl.glTexCoord3fv(UV, 0);
				norm[0] = vertices[faces[face + faceindex].a].pos.x;
				norm[1] = 0;
				norm[2] = 0;
				m_gl.glVertex3fv(norm, 0);
				norm[0] = vertices[faces[face + faceindex].b].pos.x;
				m_gl.glVertex3fv(norm, 0);
				norm[0] = vertices[faces[face + faceindex].c].pos.x;
				m_gl.glVertex3fv(norm, 0);
				m_gl.glEnd();
			}
			return QEDResponseCode.Q3D_RENDERER_OK;
		}

		SQ3DVERTEX[] Vertices = prepareVertices(vertices, nbVertices);
		m_gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
		
		//FloatBuffer buffer = BufferUtil.newFloatBuffer(Vertices.length * 2);
		FloatBuffer buffer = getFloatBuffer((int)nbVertices*2,1);
		
		if (m_Texturing && !m_GenerateTexCoords) {
			m_gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY);
			for (int Icount = 0; Icount < nbVertices; Icount++) {
				buffer.put(Vertices[Icount].u);
				buffer.put(Vertices[Icount].v);
			}
			buffer.rewind();
			m_gl.glTexCoordPointer(2, GL.GL_FLOAT, 0, buffer);
		} else {
			m_gl.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY);
		}
		
		//buffer = BufferUtil.newFloatBuffer(Vertices.length * 3);
		buffer = getFloatBuffer((int)nbVertices*3,2);
		
		for (int Icount = 0; Icount < nbVertices; Icount++) {
			buffer.put(Vertices[Icount].pos.x);
			buffer.put(Vertices[Icount].pos.y);
			buffer.put(Vertices[Icount].pos.z);
		}
		buffer.rewind();
		m_gl.glVertexPointer(3, GL.GL_FLOAT, 0, buffer);
		
		if (normals == null){
			m_gl.glEnableClientState(GL.GL_NORMAL_ARRAY);			
			
			//buffer = BufferUtil.newFloatBuffer(Vertices.length*3);
			buffer = getFloatBuffer((int)nbVertices*3,3);
			
			for (int Icount = 0; Icount < nbVertices; Icount++) {
				buffer.put(Vertices[Icount].normal.x);
				buffer.put(Vertices[Icount].normal.y);
				buffer.put(Vertices[Icount].normal.z);
			}
			buffer.rewind();
			m_gl.glNormalPointer(GL.GL_FLOAT, 0, buffer);

			//ShortBuffer shBuf = BufferUtil.newShortBuffer(faces.length * 3);
			ShortBuffer shBuf = getShortBuffer(faces.length * 3);
			for (int Icount = faceindex; Icount < faces.length; Icount++) {
				shBuf.put((short) faces[Icount].a);
				shBuf.put((short) faces[Icount].b);
				shBuf.put((short) faces[Icount].c);
			}
			shBuf.rewind();

			m_gl.glDrawElements(GL.GL_TRIANGLES, (int) nbIndex,GL.GL_UNSIGNED_SHORT, shBuf);
			m_gl.glDisableClientState(GL.GL_NORMAL_ARRAY);
		} else {
			m_gl.glDisableClientState(GL.GL_NORMAL_ARRAY);
			m_gl.glBegin(GL.GL_TRIANGLES);
			for (int i = 0, face = 0; i < nbIndex; i += 3) {
				buffer.put(0, normals[face].x);
				buffer.put(1, normals[face].y);
				buffer.put(2, normals[face].z);
				m_gl.glNormal3fv(buffer);
				m_gl.glArrayElement(faces[face + faceindex].a);
				m_gl.glArrayElement(faces[face + faceindex].b);
				m_gl.glArrayElement(faces[face + faceindex].c);
				face++;
			}
			m_gl.glEnd();
			m_gl.glEnableClientState(GL.GL_NORMAL_ARRAY);
		}

		m_gl.glDisableClientState(GL.GL_VERTEX_ARRAY);

		if (m_Texturing && !m_GenerateTexCoords) {
			m_gl.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY);
		}
	}
	catch(NullPointerException e){
		logger.error("Vertices object =" + vertices);
		logger.error("Normals object =" + normals);
		logger.error("Faces object =" + faces); 
	}
	return QEDResponseCode.Q3D_RENDERER_OK;


    Renderer state method code

	switch ((int) state) 
	{
		case QEDConstantCode.Q3DRENDERSTATE_ZTESTENABLE: 
		{
			if (value > 0){
				m_gl.glEnable(GL.GL_DEPTH_TEST);
			}
			else{
				m_gl.glDisable(GL.GL_DEPTH_TEST);
			}
		}
		break;
		case QEDConstantCode.Q3DRENDERSTATE_ZWRITEENABLE: 
		{
			if (value > 0)
				m_gl.glDepthMask(true);
			else
				m_gl.glDepthMask(false);
		}
		break;
		case QEDConstantCode.Q3DRENDERSTATE_COLORWRITEENABLE: 
		{
			if (value > 0)
				m_gl.glColorMask(true, true, true, true);
			else
				m_gl.glColorMask(false, false, false, false);
		}
		break;

case QEDConstantCode.Q3DRENDERSTATE_FILLMODE:
{
switch ((int) value)
{
case QEDConstantCode.Q3DFILL_WIREFRAME:
m_gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE);
m_gl.glDisable(GL.GL_POLYGON_SMOOTH);
break;
case QEDConstantCode.Q3DFILL_SOLID:
m_gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL);
break;
}
}
break;
case QEDConstantCode.Q3DRENDERSTATE_SHADEMODE:
{
switch ((int) value)
{
case QEDConstantCode.Q3DSHADE_FLAT:
{
m_gl.glShadeModel(GL.GL_FLAT);
}
break;
case QEDConstantCode.Q3DSHADE_GOURAUD:
{
m_gl.glShadeModel(GL.GL_SMOOTH);
}
break;
}
}
break;

case QEDConstantCode.Q3DRENDERSTATE_SPECULARENABLE: {}
break;
case QEDConstantCode.Q3DRENDERSTATE_AMBIENT:
{
float tab[] = new float[4];

			tab[0] = ((float) ((value >> 16) & 0xFF)) / 255.0f;
			tab[1] = ((float) ((value >> 8) & 0xFF)) / 255.0f;
			tab[2] = ((float) ((value) & 0xFF)) / 255.0f;
			tab[3] = ((float) ((value >> 24) & 0xFF)) / 255.0f;

			m_gl.glEnable(GL.GL_LIGHTING);
			m_gl.glLightModelfv(GL.GL_LIGHT_MODEL_AMBIENT, FloatBuffer.wrap(tab));
		}
		break;
		case QEDConstantCode.Q3DRENDERSTATE_CULLMODE: 
		{
			switch ((int) value) 
			{
				case QEDConstantCode.Q3DCULL_NONE: 
				{
					m_gl.glDisable(GL.GL_CULL_FACE);
				}
				break;
				case QEDConstantCode.Q3DCULL_CCW: 
				{
					m_gl.glFrontFace(GL.GL_CW);
					m_gl.glCullFace(GL.GL_BACK);
					m_gl.glEnable(GL.GL_CULL_FACE);
				}
				break;
				case QEDConstantCode.Q3DCULL_CW: 
				{
					m_gl.glFrontFace(GL.GL_CCW);
					m_gl.glCullFace(GL.GL_BACK);
					m_gl.glEnable(GL.GL_CULL_FACE);
				}
				break;
			}
		}
			break;
		case QEDConstantCode.Q3DRENDERSTATE_TWOSIDED: 
		{
			m_gl.glLightModeli(GL.GL_LIGHT_MODEL_TWO_SIDE, (int) value);
		}
		break;
		case QEDConstantCode.Q3DRENDERSTATE_LIGHTING: 
		{
			if (value > 0){
				m_gl.glEnable(GL.GL_LIGHTING);
			}
			else{
				m_gl.glDisable(GL.GL_LIGHTING);
			}
		}
		break;
		case QEDConstantCode.Q3DRENDERSTATE_COLORVERTEX: {}
		break;
		case QEDConstantCode.Q3DRENDERSTATE_NORMALIZENORMALS: 
		{
			if (value > 0) {
				m_gl.glEnable(GL.GL_NORMALIZE);
				m_NormalizeNormals = true;
			} else {
				m_gl.glDisable(GL.GL_NORMALIZE);
				m_NormalizeNormals = false;
			}
		}
		break;
		case QEDConstantCode.Q3DRENDERSTATE_ALPHABLENDENABLE: 
		{
			if (value > 0) {
				m_gl.glEnable(GL.GL_BLEND);
				m_gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
				m_gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE,GL.GL_MODULATE);
			}else{
				m_gl.glDisable(GL.GL_BLEND);
				m_gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE,GL.GL_MODULATE);
			}
		} 
		break;
	}

Regards

mmmh…, okay…
I see why you didn’t post your code earlier.
This goes way beyond my knowledge of Jogl or OpenGL, I fear someone else will have to help you.
Sorry

Hello,

      Ok, no problem. Thank Very Much You for your kind help.

Regards

Try making a simple test case without all of the additional work thrown in that you have right now. If there’s still a problem then it could be something wrong with your drivers.

Hello lhkbob,

         I have tried using the small program but again same. I could not understand why same data plot differently when i use GL_LINE,  GL_FILL and GL_SMOOTH. I keep same data for both cases but for one case it ploat correctly and for other it changes position of the some vertex.

Regards