Code example for GL10

Methods: glColor4f, glDisable, glLoadIdentity, glMaterialfv, glMaterialx, glMatrixMode, glMultMatrixf, glPopMatrix, glPushMatrix, glTranslatef

0
			gl.glDisable(GL10.GL_LIGHT0+gnLights);
	} 
 
	public void drawShapeNode(GL10 gl, SceneGraph sg, ShapeNode shape, int drawMode)
	{ 
		gl.glPushMatrix ();
 
		///////////////////////////////// 
		//	Appearance(Material) 
		///////////////////////////////// 
 
		float color[] = new float[4];
		color[3] = 1.0f;
 
		AppearanceNode			appearance = shape.getAppearanceNodes();
		MaterialNode			material = null;
		ImageTextureNode		imgTexture = null;
		TextureTransformNode	texTransform = null;
 
		boolean				bEnableTexture = false;
 
		if (appearance != null) {
 
			// Texture Transform 
			texTransform = appearance.getTextureTransformNodes();
			if (texTransform != null) {
				float texCenter[] = new float[2];
				float texScale[] = new float[2];
				float texTranslation[] = new float[2];
				float texRotation;
 
				gl.glMatrixMode(GL10.GL_TEXTURE);
				gl.glLoadIdentity();
 
				texTransform.getTranslation(texTranslation);
				gl.glTranslatef(texTranslation[0], texTranslation[1], 0.0f);
 
				texTransform.getCenter(texCenter);
				gl.glTranslatef(texCenter[0], texCenter[1], 0.0f);
 
				texRotation = texTransform.getRotation();
				gl.glRotatef(0.0f, 0.0f, 1.0f, texRotation);
 
				texTransform.getScale(texScale);
				gl.glScalef(texScale[0], texScale[1], 1.0f);
 
				gl.glTranslatef(-texCenter[0], -texCenter[1], 0.0f);
			} 
			else { 
				gl.glMatrixMode(GL10.GL_TEXTURE);
				gl.glLoadIdentity();
				gl.glTranslatef(0.0f, 0.0f, 1.0f);
			} 
 
			gl.glMatrixMode(GL10.GL_MODELVIEW);
 
			// Texture 
			imgTexture = appearance.getImageTextureNodes();
			if (imgTexture != null && drawMode == OGL_RENDERING_TEXTURE) {
 
				/* 
				int width = imgTexture.getWidth(); 
				int height = imgTexture.getHeight(); 
				RGBAColor32 *color = imgTexture.getImage(); 
 
				if (0 < width && 0 < height && color != null)  
					bEnableTexture = true; 
 
				if (bEnableTexture == true) { 
					if (imgTexture.hasTransparencyColor() == true) { 
						gl.glEnable(GL10.GL_BLEND); 
						gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); 
					} 
					else 
						gl.glDisable(GL10.GL_BLEND); 
 
					gl.glPixelStorei(GL10.GL_UNPACK_ALIGNMENT, 1); 
					gl.glBindTexture(GL10.GL_TEXTURE_2D, imgTexture.getTextureName()); 
 
					gl.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_MODULATE); 
 
					gl.glEnable(GL10.GL_TEXTURE_2D); 
 
					gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); 
					gl.glColorMaterial(GL10.GL_FRONT_AND_BACK, GL10.GL_AMBIENT_AND_DIFFUSE); 
					gl.glEnable(GL10.GL_COLOR_MATERIAL); 
				} 
				else { 
					gl.glDisable(GL10.GL_TEXTURE_2D); 
					gl.glDisable(GL10.GL_COLOR_MATERIAL); 
				} 
				*/ 
			} 
			else { 
				gl.glDisable(GL10.GL_TEXTURE_2D);
				gl.glDisable(GL10.GL_COLOR_MATERIAL);
			} 
 
			// Material 
			material = appearance.getMaterialNodes();
			if (material != null) {
				float	ambientIntesity = material.getAmbientIntensity();
 
				material.getDiffuseColor(color);
				gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_DIFFUSE, color, 0);
 
				material.getSpecularColor(color);
				gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_SPECULAR, color, 0);
 
				material.getEmissiveColor(color);
				gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_EMISSION, color, 0);
 
				material.getDiffuseColor(color);
				color[0] *= ambientIntesity; 
				color[1] *= ambientIntesity; 
				color[2] *= ambientIntesity; 
				gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_AMBIENT, color, 0);
 
				gl.glMaterialx(GL10.GL_FRONT, GL10.GL_SHININESS, (int)(material.getShininess()*128.0));
			} 
 
		} 
		 
		if (appearance == null || material == null) {
			color[0] = 0.8f; color[1] = 0.8f; color[2] = 0.8f;
			gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_DIFFUSE, color, 0);
			color[0] = 0.0f; color[1] = 0.0f; color[2] = 0.0f;
			gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_SPECULAR, color, 0);
			gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_EMISSION, color, 0);
			color[0] = 0.8f*0.2f; color[1] = 0.8f*0.2f; color[2] = 0.8f*0.2f;
			gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_AMBIENT, color, 0);
			gl.glMaterialx(GL10.GL_FRONT_AND_BACK, GL10.GL_SHININESS, (int)(0.2*128.0));
		} 
 
		if (appearance == null || imgTexture == null || drawMode != OGL_RENDERING_TEXTURE) {
			gl.glDisable(GL10.GL_TEXTURE_2D);
			gl.glDisable(GL10.GL_BLEND);
		} 
 
		///////////////////////////////// 
		//	Transform  
		///////////////////////////////// 
 
		float m4[] = new float[16];
		shape.getTransformMatrix(m4);
		gl.glMultMatrixf(m4, 0);
 
		gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
 
		///////////////////////////////// 
		//	Geometry3D 
		///////////////////////////////// 
 
		Geometry3DNode gnode = shape.getGeometry3D();
		if (gnode != null) {
			GeometryNodeObject.draw(gl, gnode);
		} 
 
		/* 
		ShapeNode selectedShapeNode = sg.getSelectedShapeNode(); 
		if (gnode != null  && selectedShapeNode == shape) { 
			float	bboxCenter[] = new float[3]; 
			float	bboxSize[] = new float[3]; 
			gnode.getBoundingBoxCenter(bboxCenter); 
			gnode.getBoundingBoxSize(bboxSize); 
 
			gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); 
			gl.glDisable(GL10.GL_LIGHTING); 
	//		gl.glDisable(GL10.GL_COLOR_MATERIAL); 
			gl.glDisable(GL10.GL_TEXTURE_2D); 
			gl.glDisable(GL10.GL_BLEND); 
 
			gl.glBegin(GL10.GL_LINES); 
			 
			int x, y, z; 
			for (x=0; x<2; x++) { 
				for (y=0; y<2; y++) { 
					float point[] = new float[3]; 
					point[0] = (x==0) ? bboxCenter[0] - bboxSize[0] : bboxCenter[0] + bboxSize[0]; 
					point[1] = (y==0) ? bboxCenter[1] - bboxSize[1] : bboxCenter[1] + bboxSize[1]; 
					point[2] = bboxCenter[2] - bboxSize[2]; 
					gl.glVertex3fv(point); 
					point[2] = bboxCenter[2] + bboxSize[2]; 
					gl.glVertex3fv(point); 
				} 
			} 
			for (x=0; x<2; x++) { 
				for (z=0; z<2; z++) { 
					float point[] = new float[3]; 
					point[0] = (x==0) ? bboxCenter[0] - bboxSize[0] : bboxCenter[0] + bboxSize[0]; 
					point[1] = bboxCenter[1] - bboxSize[1]; 
					point[2] = (z==0) ? bboxCenter[2] - bboxSize[2] : bboxCenter[2] + bboxSize[2]; 
					gl.glVertex3fv(point); 
					point[1] = bboxCenter[1] + bboxSize[1]; 
					gl.glVertex3fv(point); 
				} 
			} 
			for (y=0; y<2; y++) { 
				for (z=0; z<2; z++) { 
					float point[] = new float[3]; 
					point[0] = bboxCenter[0] - bboxSize[0]; 
					point[1] = (y==0) ? bboxCenter[1] - bboxSize[1] : bboxCenter[1] + bboxSize[1]; 
					point[2] = (z==0) ? bboxCenter[2] - bboxSize[2] : bboxCenter[2] + bboxSize[2]; 
					gl.glVertex3fv(point); 
					point[0] = bboxCenter[0] + bboxSize[0]; 
					gl.glVertex3fv(point); 
				} 
			} 
			gl.glEnd(); 
 
			gl.glEnable(GL10.GL_LIGHTING); 
	//		gl.glEnable(GL10.GL_COLOR_MATERIAL); 
			gl.glEnable(GL10.GL_TEXTURE_2D); 
			gl.glEnable(GL10.GL_BLEND); 
		} 
		*/ 
		 
		gl.glPopMatrix();
	} 
 
 
	public void drawNode(GL10 gl, SceneGraph sceneGraph, Node firstNode, int drawMode) 
	{