package com.jengine.kevinchwong;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.GraphicsEnvironment;
import java.awt.RenderingHints;
import java.awt.geom.AffineTransform;
import java.awt.geom.Ellipse2D;
import com.threed.jpct.*;
import javax.swing.*;
public class SoftwareRenderTest {
private World world;
private FrameBuffer buffer;
private Object3D box;
private JFrame frame;
public static void main(String[] args) throws Exception {
new SoftwareRenderTest().loop();
}
public SoftwareRenderTest() throws Exception {
frame=new JFrame("Hello world");
frame.setSize(800, 600);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
world = new World();
world.setAmbientLight(0, 255, 0);
TextureManager.getInstance().addTexture("box", new Texture("res/textures/box.jpg"));
box = Primitives.getBox(13f, 2f);
box.setTexture("box");
box.setEnvmapped(Object3D.ENVMAP_ENABLED);
box.build();
world.addObject(box);
world.getCamera().setPosition(50, -50, -5);
world.getCamera().lookAt(box.getTransformedCenter());
}
private void loop() throws Exception {
buffer = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_NORMAL);
while (frame.isShowing()) {
box.rotateY(0.01f);
buffer.clear(java.awt.Color.BLUE);
world.renderScene(buffer);
world.draw(buffer);
buffer.update();
//GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
// ge.getAllFonts();
RenderingHints rh =
new RenderingHints(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
rh.put(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
Graphics2D g2d = (Graphics2D) buffer.getGraphics();
g2d.setFont(new Font("Serif", Font.PLAIN, 13));
//g2d.setFont(new Font("Franklin Gothic Medium", Font.PLAIN, 33));
g2d.drawString("??Most relationships seem so transitory", 20, 130);
g2d.drawString("They're all good but not the permanent one", 20, 160);
g2d.drawString("Who doesn't long for someone to hold", 20, 190);
g2d.drawString("Who knows how to love you without being told", 20, 220);
g2d.drawString("Somebody tell me why I'm on my own", 20, 250);
g2d.drawString("If there's a soulmate for everyone", 20, 280);
Ellipse2D e = new Ellipse2D.Double(0, 0, 80, 130);
g2d.setStroke(new BasicStroke(1));
g2d.setColor(Color.gray);
for (double deg = 0; deg < 360; deg += 5) {
AffineTransform at =
AffineTransform.getTranslateInstance(400,300);
at.rotate(Math.toRadians(deg));
g2d.draw(at.createTransformedShape(e));
}
buffer.display(frame.getGraphics());
Thread.sleep(10);
}
buffer.disableRenderer(IRenderer.RENDERER_OPENGL);
buffer.dispose();
frame.dispose();
System.exit(0);
}
}
Friday, January 31, 2014
Software Rendering with JPCT and java2d together
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment