Author Topic: How to create an Applet  (Read 10969 times)

Offline Scalpweb

  • byte
  • *
  • Posts: 1
    • View Profile
How to create an Applet
« on: November 27, 2008, 04:53:48 pm »
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

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: How to create an Applet
« Reply #1 on: November 27, 2008, 06:06:08 pm »
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:
Code: [Select]
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:
Code: [Select]
<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/

Offline .jayderyu

  • long
  • ***
  • Posts: 116
    • View Profile
Re: How to create an Applet
« Reply #2 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.

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: How to create an Applet
« Reply #3 on: November 29, 2008, 04:48:11 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.

Offline Johnston

  • byte
  • *
  • Posts: 3
    • View Profile
Re: How to create an Applet
« Reply #4 on: November 15, 2011, 07:53:00 am »
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);
}
}

Offline sushobhit

  • long
  • ***
  • Posts: 109
  • future is now
    • View Profile
    • ANDROID APPS
Re: How to create an Applet
« Reply #5 on: March 27, 2014, 08:15:22 am »
kewl

Offline atreyu64

  • byte
  • *
  • Posts: 44
    • View Profile
Re: How to create an Applet
« Reply #6 on: August 05, 2015, 11:58:52 am »
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 !

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: How to create an Applet
« Reply #7 on: August 05, 2015, 03:14:36 pm »
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?

Offline atreyu64

  • byte
  • *
  • Posts: 44
    • View Profile
Re: How to create an Applet
« Reply #8 on: August 05, 2015, 03:40:43 pm »
No in my app I use the GLRenderer.
I will try to init the Bloom process differently.

Thanks !

Offline atreyu64

  • byte
  • *
  • Posts: 44
    • View Profile
Re: How to create an Applet
« Reply #9 on: August 05, 2015, 11:51:08 pm »
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 :
Code: [Select]
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 ?) :

Code: [Select]
      // 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 ?

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: How to create an Applet
« Reply #10 on: August 08, 2015, 06:03:04 pm »
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).

Offline atreyu64

  • byte
  • *
  • Posts: 44
    • View Profile
Re: How to create an Applet
« Reply #11 on: August 11, 2015, 03:33:09 pm »
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 !

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: How to create an Applet
« Reply #12 on: August 11, 2015, 09:48:18 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...