Hi. I am newbie of 3D graphics programming and now working on some tutorials.
I have a lot to question, but I'll do a few of them.
The first one is, as mentioned above, the shading method.
I think the gouraud shading works fine, but when I switch it to flat shading, it renders like this:
and here is the code.
@Override
public void onDrawFrame(GL10 gl) {
cube.rotateY(m_cam.convertDEGAngleIntoFOV(0.5f));
buffer.clear(colBackground);
m_world.renderScene(buffer);
m_world.draw(buffer);
buffer.display();
}
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
if(buffer == null) {
Util.LOGD("make framebuffer");
m_world = new World();
m_cam = m_world.getCamera();
m_light = new Light(m_world);
m_light.setIntensity(250, 250, 250);
m_light.setPosition(new SimpleVector(50, -50, 50));
m_world.setAmbientLight(0, 0, 0);
Texture t = new Texture(100, 100, new RGBColor(0, 0xff, 0, 0x7f));
TextureManager.getInstance().addTexture("test", t);
TextureManager.getInstance().addTexture("bottom", new Texture(100, 100, RGBColor.BLUE));
cube = Primitives.getBox(10, 1);
cube.setShadingMode(Object3D.SHADING_FAKED_FLAT);
cube.setEnvmapped(true);
cube.calcTextureWrap();
cube.translate(0, -10, 0);
cube.setTexture("test");
cube.strip();
cube.build();
m_world.addObject(cube);
m_bottomPlane = Primitives.getPlane(20, 300);
m_bottomPlane.translate(SimpleVector.ORIGIN);
m_bottomPlane.setSpecularLighting(true);
m_bottomPlane.calcTextureWrap();
m_bottomPlane.rotateX((float)Math.PI/2f);
m_bottomPlane.setTexture("bottom");
m_bottomPlane.build();
m_world.addObject(m_bottomPlane);
m_cam.setPosition(20, -20, 20);
m_cam.lookAt(cube.getTransformedCenter());
}
if(buffer != null)
buffer.dispose();
buffer = new FrameBuffer(gl, width, height);
MemoryHelper.compact();
}
Can anybody check the code it's right? I wonder it's on my device-specific issue. (I use HTC sensation with ICS)
And the second question is..
I'd like to accomplish a cartoonish rendering. For example, I think it can be simply done to a cube(in the code above) by boldening the edges. But I have no idea of implementing it. Moreover, I even do not know how to draw a line in 3D space. Can I get a hint of that?
Thanks for listening me and sorry for my poor english.