Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - newjavadev

Pages: [1]
1
Support / Re: help loading an md2 model in a java applet
« on: September 04, 2011, 05:57:22 am »
Maybe I'm just retarded? Or just a retarded beginner, but why the hell doesn't this work then?

Code: [Select]
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JApplet;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.IRenderer;
import com.threed.jpct.Loader;
import com.threed.jpct.Object3D;
import com.threed.jpct.World;

public class applettest extends JApplet implements Runnable
{
private static final long serialVersionUID = 1L;

private FrameBuffer buffer = null;
private World world = null;
private boolean loop = true;
private Object3D thing;
Canvas myCanvas;

public void init()
{
world = new World();
World.setDefaultThread( Thread.currentThread() );

thing = Loader.loadMD2("body.md2", 1);
thing.build();
world.addObject(thing);

buffer = new FrameBuffer( 600, 800, FrameBuffer.SAMPLINGMODE_HARDWARE_ONLY );
buffer.disableRenderer( IRenderer.RENDERER_SOFTWARE );
myCanvas = buffer.enableGLCanvasRenderer();

add( myCanvas, BorderLayout.CENTER);
myCanvas.setVisible( true );

new Thread(this).start();
}

@Override
public void paint( Graphics g )
{
buffer.clear(Color.black);

world.renderScene( buffer );
world.draw( buffer );
buffer.update();

buffer.displayGLOnly();
myCanvas.repaint();
}


@Override
public void run()
{
while (loop)
{
repaint();
try{
Thread.sleep(10);
}catch(Exception e){}
}
}
}

Error I receive:
Loading file body.md2
[ Sat Sep 03 20:55:00 PDT 2011 ] - ERROR: Couldn't read file body.md2
[ Sat Sep 03 20:55:00 PDT 2011 ] - ERROR: Not a valid MD2-file!
Magic number: -1
Version: -1
Skin width: -1
Skin height: -1
Frame size: -1
Number of skins: -1
Number of Vertices: -1
Number of Texture coordinates: -1
Number of triangles: -1
Number of GL-commands: -1
Number of Frames: -1
java.lang.NegativeArraySizeException
   at com.threed.jpct.Loader.loadMD2(Unknown Source)
   at com.threed.jpct.Loader.loadMD2(Unknown Source)
   at applettest.init(applettest.java:27)
   at sun.applet.AppletPanel.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)

The freakin model is there, so why is it having problems loading it? Thanks again for the help guys. :)

2
Support / Re: help loading an md2 model in a java applet
« on: September 03, 2011, 04:08:31 am »
oh, i'm sorry my grammar isn't very good

what i'm trying to do is render an md2 model in a java applet on my website. now after reading all of your excellent tutorials and examples, i have managed to do the following:
load an md2 model via java application
load a 3d box via java applet (your example)

what i want is to be able to get my program i found that loads a md2 model in a java application turned into loading a md2 model via java applet.

basically, i want to know how to transform the code below so it will work as a java applet instead of an application. because when i try to tinker it, it gives me a ton of different errors i don't understand how to fix. :-(

Code: [Select]
import com.threed.jpct.*;
import javax.swing.*;
public class lawltest {
    private String[] textures = {"body"};
    private String thingName = "body";
    private int thingScale = 1;
    private World world;
    private FrameBuffer buffer;
    private Object3D thing;
    private TextureManager tm = TextureManager.getInstance();

    public static void main(String[] args) throws Exception {
        new lawltest().loop();
    }

    public lawltest() throws Exception {
        world = new World();
        world.setAmbientLight(150, 150, 150);
        for (int i = 0; i < textures.length; ++i) {
            tm.addTexture(textures[i] + ".png", new Texture("res/" + textures[i] + ".png"));
        }
        TextureInfo ti=new TextureInfo(tm.getTextureID(textures[0] + ".png"));
        thing = loadModel("res/" + thingName + ".md2", thingScale);
        thing.setTexture(ti);
       
        world.addObject(thing);
        world.getCamera().moveCamera(Camera.CAMERA_MOVEOUT,100);
        world.getCamera().lookAt(thing.getTransformedCenter());
    }

    private void loop() throws Exception {
        buffer = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_GL_AA_2X);
        buffer.enableRenderer(IRenderer.RENDERER_OPENGL);
        buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
        while (!org.lwjgl.opengl.Display.isCloseRequested()) {
            buffer.clear(java.awt.Color.BLUE);
            world.renderScene( buffer );
            world.draw( buffer );
            buffer.update();
            buffer.displayGLOnly();
            thing.rotateY(0.02f);
            thing.rotateX(0.01f);
           
            Thread.sleep(10);
        }
        buffer.dispose();
        System.exit(0);
    }

    private Object3D loadModel(String filename, float scale) {
        Object3D temp = Loader.loadMD2(filename, scale);
        temp.build();
        return temp;
    }
}

3
Support / help loading an md2 model in a java applet
« on: September 02, 2011, 02:40:28 pm »
hi, i'm not an entirely new java coder, but i'm fairly new to using jpct.

i pretty much understand how to use the Object3D, and i'm pretty good at just editing code however i can't get around to loading an object via java applet. :(

help is very appreciated, thank you so much.

btw i already know how to load lwjgl applets on my web and stuff like that, i just need a basic java code to load a md2 model because i'm stumped. i'm not very good yet, but i learn off tutorials and help! haha  thanks again in advance.

Pages: [1]