How to create an Applet

Started by Scalpweb, November 27, 2008, 04:53:48 PM

Previous topic - Next topic

Scalpweb

Hello,

First, excuse me for my english, I'm a french developper. ^^

I just find out the jpct 3D engine, and I want to create a basic applet : I just want to create a scene where I can see a 3DSmax object. I want to use hardware rendering (OpnGl).

But, unfortunatelly, I can't find any tutorial or exemple for this... So, for exemple, if I want to convert the "fps" demo in a Applet, how can I do that ?

Thanks,
Scalp

paulscode

I have a simple applet that should help you get started.  It demonstrates how to load and set up 3DS models, how to use hardware rendering in an applet, and how to switch between hardware and software rendering modes on the fly.

Here is a link to the source code:
http://www.paulscode.com/demos/jpct/jPCTGears/jPCTGearsSource.zip

To use hardware rendering in an applet, you must load it with the lwjgl applet loader, which you can download from:
http://www.lwjgl.org


Here are some instructions for using the applet loader, in case you have problems figuring out how to make it work:

You must place the following files (plus your program jar) somewhere online:
jpct.jar
lzma.jar
lwjgl_util_applet.jar
lwjgl.jar.pack.lzma
lwjgl_util.jar.pack.lzma
jinput.jar.pack.lzma
res.jar.lzma
windows_natives.jar.lzma
linux_natives.jar.lzma
macosx_natives.jar.lzma
solaris_natives.jar.lzma

Plus the two loader image files (in this example I am using paulscodelogo.png and paulscodeprogress.gif)

Next you need to create an html file to load the applet.  Here is the html I used in the gears demo example:
<html><body>
    <applet code="org.lwjgl.util.applet.AppletLoader"
        archive="http://www.paulscode.com/libs/lwjgl/JARs/lwjgl_util_applet.jar,
            http://www.paulscode.com/libs/lwjgl/JARs/lzma.jar"
            codebase="." width="640" height="480">
            <param name="al_title" value="jPCTGears">
            <param name="al_main" value="jPCTGears">
            <param name="al_logo" value="http://www.paulscode.com/libs/lwjgl/paulscodelogo.png">
            <param name="al_progressbar" value="http://www.paulscode.com/libs/lwjgl/paulscodeprogress.gif">
            <param name="al_jars"
            value="http://www.paulscode.com/demos/jpct/jPCTGears/jPCTGears.jar,
            http://www.paulscode.com/libs/jpct/jpct.jar,
            http://www.paulscode.com/libs/lwjgl/JARs/lwjgl.jar.pack.lzma,
            http://www.paulscode.com/libs/lwjgl/JARs/jinput.jar.pack.lzma,
            http://www.paulscode.com/libs/lwjgl/JARs/lwjgl_util.jar.pack.lzma,
            http://www.paulscode.com/libs/lwjgl/JARs/res.jar.lzma">
            <param name="al_windows" value="http://www.paulscode.com/libs/lwjgl/JARs/windows_natives.jar.lzma">
            <param name="al_linux" value="http://www.paulscode.com/libs/lwjgl/JARs/linux_natives.jar.lzma">
            <param name="al_mac" value="http://www.paulscode.com/libs/lwjgl/JARs/macosx_natives.jar.lzma">
            <param name="al_solaris" value="http://www.paulscode.com/libs/lwjgl/JARs/solaris_natives.jar.lzma">
            <param name="al_version" value="1.0">
    </applet>
</body></html>


Just substitute your own files and class names.

Create a text file named ".htaccess".
If you are running Windows, it will complain, because that is not a valid filename, according to Bill.  You'll have to name it something like ".htaccess.txt", then rename it later after uploading it.

Edit the file you created, with notepad or other text editor.  Add the line:
AddType application/x-lzma .lzma

Save your file, and FTP it to wherever lwjgl_util_applet.jar and lzma.jar are located.  If necessary, rename your file ".htaccess" (remove the ".txt" extension)
Make sure you are allowed to use .htaccess before doing this!  Some of the things that .htaccess is able to do can compromise a server configuration.  For this reason, some web hosting companies may require them to be set up by an admin, so don't get in trouble.  You should CHMOD your .htaccess file to 644 (RW-R--R--) to prevent people from messing with it


That's it.  Let me know if you need any further clarification.

And for reference, here is a link to the working gears demo applet:
http://www.paulscode.com/demos/jpct/jPCTGears/

.jayderyu

hey Paul. I think you should put together a comprehensive jpct + applets post|tutorial. Then ask Egon for it to be stickied.

paulscode

Quote from: .jayderyu on November 29, 2008, 12:54:34 AM
hey Paul. I think you should put together a comprehensive jpct + applets post|tutorial. Then ask Egon for it to be stickied.
This thread would work fine for that.

Johnston

U can use Eclipse as IDE it's a good IDE and u can found more than java editor. u can also write the java applet in a bloc note and name the file the same name as the class in(extension .java)
and then compile this file using javac to have the compiled (extension .class)
which u can run using java program
exp:
suppose the name of the first file is myclass.java
u can in command line in the fiolder containing this file write :
javac myclass.java
u will have myclass.class
u can use java to run it if it' defined as application (using main method):
java myclass.class
if ur file is an applet (using paint method) :
u will create a html page that contains the class created by javac using the applet tag as bellow :

<APPLET code="myclass.class" width="500" height="200">
myfirst applet
</APPLET>

here bellow an applet structure:


import java.applet.*;
import java.awt.*;

public class myclass extends Applet
{
public void paint(Graphics g)
{
g.drawString("Hi to all !!!", 30, 30);
}
}

sushobhit


atreyu64

Hi, I have a problem with my applet.

It works quite good but the lightning is different than the java version of my app : ambient light is at maximum (it should'nt) and I can't see specular lighting anymore.
Also, Bloom processor crashes, I get this message while trying to initialize it :
Quote"Warning: unable to initialize post processing textures due to: no opengl context found in the current thread"

I have disabled software renderer just after enabling canvas OpenGL renderer, so it should work exactly the same as the java version, right ?

Any idea of what's happening ?


Thanks in advance, cheers !

EgonOlsen

The bloom issue might be a threading problem. Try to implement an IPaintListener in do the initialization in one of it's methods instead. About the lighting...I'm not sure. Are you using the AWTGLRenderer in your application as well?

atreyu64

No in my app I use the GLRenderer.
I will try to init the Bloom process differently.

Thanks !

atreyu64

I tried to init bloom processor through an IPaintListener and I don't get the warning message anymore.

However, I now get an error during the rendering of the bloom :
Exception in thread "AWT-EventQueue-1" java.lang.RuntimeException: No OpenGL context found in the current thread.
   at org.lwjgl.opengl.GLContext.getCapabilities(GLContext.java:124)
   at org.lwjgl.opengl.GL11.glBindTexture(GL11.java:651)
   at com.threed.jpct.procs.BloomGLProcessor.snapshot(BloomGLProcessor.java:362)


Here is basically what I do in my loop (remember the bloomProc.setDelayed(true) method you kindly introduced for me ?) :

      // First render the actual world to fill the zbuffer and let the
      // processor take a snapshot of the result
      world.renderScene(fb);
      if(enableSkyBox)
         skybox.render(world, fb);
      pictoWorld.renderScene(fb);
     
      // draw first world :
      world.draw(fb);
     
      if(displayNeons && nbNeons > 0) {
         bloomProcessor.snapshot(); ///////////////////////////// bug here

         // Then render the line world and apply the blur...but only to the
         // back buffer of the processor because it's delayed.
         // Make sure to clear the color but not the depth buffer.
         fb.clearColorBufferOnly(Color.BLACK);
         bloomWorld.renderScene(fb);
         bloomWorld.draw(fb);
         fb.runPostProcessors();

         // Now combine the snapshot with the blurred image.
         bloomProcessor.render();
      }
     
      // then draw picto world :
      pictoWorld.draw(fb);
     
      fb.update();
     
      blitting();
     
      fb.displayGLOnly();



What am I doing wrong ?

EgonOlsen

The BloomGLProcessor is meant to be executed in the rendering thread. In case of the AWTGLRenderer, this is the awt event dispatch thread. To ensure this, you can put it into the finishedPainting()-method of the IPaintListener. However, this will not work with the way in which you create the scene...I'm not sure how to solve this ATM. The thing is, that all the draw()-commands are writing into a command buffer when using the AWTGLRenderer, and not executed directly but during the next repaint.
The easiest way might be to use the GLRenderer in the applet instead. That is possible somehow IIRC. Maybe the LWJGL-site has more information (but make sure to look for stuff about LWJGL 2.x, not 3.x).

atreyu64

Ok, I see...
Well I will disable the bloom effect in my applet for now, not a big deal.

What about the specular light not showing ? Any idea ?

Thanks, cheers !

EgonOlsen

Quote from: atreyu64 on August 11, 2015, 03:33:09 PM
What about the specular light not showing ? Any idea ?
No, actually I don't. It should work. Can you create a test case that shows this problem? Non-applet version prefered, if possible...