New Website With Full Tutorials

Started by Chman, August 19, 2003, 18:05:04

Previous topic - Next topic

Chman

[Copied from JavaGaming.org]

Hi,

So i've juste opened a new website where you can find tutorials (full tutorials, like Nehe's ones). Only three are available for the moment (writting a tutorial is long and hard task so...), but you can alwais visit the old website to find others ports (they won't work with last version of LWJGL...).

Whereas the website can be seen in french or english, tutorial are only written in french for the moment, cause traducting french to english is not one of my favorite task, so don't blame me for that please   But if someone is proud enough to traduct them... Anyway, source code comments are in english of course.

Tutorials are for Lwjgl, but you will find Jogl and GL4Java ports at the end of each one.

Oh, the link is http://chman-area.tuxfamily.org ! If you have some suggestions about this website...

++
Chman

Morgrog

Nice layout! I'm one of those minimalist guys myself ;)

If you ever need help translating stuff I can help you out (French Canuckian here)

I'll add this site to my bookmarks for sure!

Keep up the good work!

Chman

If you want to traduct the tutorials, you're welcome ! Because I don't think I'm proud enough to do it myself... I've made so many translations last month (for personnal project) that I can't imagine me doing another ! And my english is not perfect so... I don't want to make incomprehensible tutorials :D

So if you're volunteer, just do what you want and send it to me (it will be added to the site, of course !)...

Thanks again !

++
Chman

princec


whome

[resuse the current topic]

http://www.javagaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=LWJGL;action=display;num=1047037254

I had problems running cham examples with Matrox G400 card. I managed to isolate few problems and posted detail on given link at java.net forum.

andrewc

The new site looks good.

I initially had some trouble running the demos, though, because of the display mode they were trying to use. The code chooses the details of an available mode to create the window, but doesn't actually change to that mode. It was expecting 24bpp, and I have it set to 16bpp. No go. The old 0.6 examples were similar. Anyone with a decent computer wouldn't notice. :)

PlanetMongo

RainingDay demo
Okay, I was testing out my latest lwjgl download here at work and compiled RainingDay demo.  I got it to compile once I remembered to set my -classpath and -extdirs settings (extdirs seems to have replaced -D, btw), with no errors.  However, trying to 'java RainingDay.class' or just using Ctrl-2 in TextPad gets a:
Exception in thread "main" java.lang.NoClassDefFoundError: RainingDay

Any ideas?
ife sucks, kill yourself.

PlanetMongo

It seems to be classpath related.  These desktop machines here have some weird security settings that just make things difficult sometimes.  For instance, while Textpad installs and detects my Java installation, Eclipse does not, no matter what kind of coaxing I try.  :(  I'll download all the demos and tutorials and try and get them working at home, as well.  On the matrox and the Geforce machine (the GeForce machine is probably what I'll focus on, eh?)
ife sucks, kill yourself.

whome

Most likely you forgot to put "." path to classpath setting, so java.exe could not find the class from the current folder.

Here is my dosprompt IDE settings for lwjgl testings.  Change {root} to point your favourite subfolder structure. This applies to all demos and tutorials.

c:\root\lwjgl\lib\<here is lwjgl.dll and .jar files>
c:\root\lwjgl\RainingDay\RainingDay.class
c:\root\lwjgl\RainingDay\RainingDay.java
c:\root\lwjgl\RainingDay\data\<demo .jpg files>
c:\root\lwjgl\RainingDay\c.bat
c:\root\lwjgl\RainingDay\go.bat


c.bat to compile project
SET cp=..\lib\lwjgl.jar
SET lib=..\lib
SET cp=%cp%;.
c:\j2sdk1.4.2\bin\javac.exe -classpath %cp% RainingDay.java
pause


go.bat to run project
SET cp=..\lib\lwjgl.jar
SET lib=..\lib
SET cp=%cp%;.
c:\j2sdk1.4.2\bin\java.exe -classpath %cp% -Djava.library.path=%lib% RainingDay
pause


NOTE
I don't recommend a global classpath variable in environment settings. It only creates unnecessary library problems when running apps. I prefer to construct per-application classpath value in a startup script. It is like creating a taylored system32 folder for each application.

PlanetMongo

I ran tutorial 1 through babelfish and then made some rough corrections for the sake of some clarity.  I figure this might be better than nothing and some of us may be able to make it even clearer.  Open Source tutorials?  ;)



:: Introduction

  We will learn how to create a basic application using Lwjgl, Jogl or GL4Java. Each part will relate to the use of a library, therefore deferring you directly to that corresponding library that you seek. Nevertheless, tutorials will be written only by using Lwjgl, because it is the library which I use more, and frankly, rewriting a tutorial 3 times is no small task, especially when the code is practically the same one from one library to another! This is why you will find at the bottom of each page 3 seperate links pointing to 3 different versions of the source code for each library.

  Note: these tutorials are not addressed to absolute beginners in java. A minimum of knowledge is necessary (classes, inheritence, method, operators, are the bare minimum).


:: Light Weight Java Game Library

  This library is very recent, as evidenced by its "alpha" status! But rest assured, that does not prevent it from being very successful, even practically finished! As I write these lines, version Alpha 0.7 is being released, therefore some of the code here may not work with the new version. In case this happens, contact me and I will update the tutorials. Let's begin!

  First of all, it is necessary to obtain all of the files in order to use Lwjgl:

[CODE SNIPPED]

  No import of the traditional Java libraries? And well not! The strength of Lwjgl is to be completely independent of the internal libraries such as AWT or SWING. It allows a speed increase compared to the other OpenGL libraries, but the only disadvantage is that it is not possible to encapsulate an OpenGL window in an object AWT/SWING.
  The first import is the total import of Lwjgl. It is in org.lwjgl that one will find the primary classes such as Display or DispayMode. The second relates to the controllers (keyboards, mouse, joystick) and the last is primarily for binding OpenGL (which contains also the class Window). Unless you do not wish to use controllers, they are the 3 primary imports. There are still some others, but we will discover them in future tutorials. Let's concentrate on the aggregate variables used to define in our class Lwjgl01 :

public DisplayMode mode;
public boolean fullscreen = false;
   DisplayMode represents the view, i.e. the resolution, the number of bits by pixels etc... This variable is essential. As for the last, it will enable us to pass from a windowed mode to a full-screen mode at the press of a key.

  Note: all the members and methods of this class will be defined as public in order to be able to re-use it in our future tutorials (which will keep us from having to recode it over and over).
  Let us see our constructor (class Lwjgl01):

public Lwjgl01()
{
  init_lwjgl(800, 600, 16);
  main_loop();
  cleanup();
}
  Little clarification, indeed... The 3 functions called here are very important. The first initializes the screen, OpenGL and the controllers, the second represents the main function in which the running of your program (drawing, interactions, etc) will be performed, and the last is used to clean up memory before exiting. Let's analyze the first function, init_lwjgl() :

[CODE SNIPPED]

  First you obtain a list of all the mode resolutions supported by the screen:

DisplayMode[ ] modes = Display.getAvailableDisplayModes();
  Using a loop, you then look for the desired mode. This method can appear rather heavy, but it's the best method to use if you want to avoid bugs (as selecting a non-supported video mode would crash the machine).

  The mode being set, we should now create the window which will hold everything else. One proceeds in this way:

Window.create("Lwjgl Test", 50,50,mode.width,mode.height,mode.bpp,0,8,0);
  The first parameter is the title of the window (that which will be posted in the title bar when you are in windowed mode). The next defines the position related to the environment in which the application is launched and the resolution of the window. Regarding the last 4 , it defines (in order):

  · Minimum of bits per pixel.
  · Minimum of bits per pixel in the "buffer alpha".
  · Minimum of bits per pixel in the "depth buffer".
  · Minimum of bits per pixel in the "stencil buffer".

  In general, it is not necessary to give these parameters, therefore use 0 as the value. The only thing remaining is to call our initialization function of OpenGL and to create the keyboard to provide a minimum of interactivity (which will be limited, for this tutorial, to the use of key ESCAPE to leave the program:)). Now let's look at our function init_gl().

[CODE SNIPPED]

  GLCaps is a very interesting class which simply allows us to check the presence of an extension or a function on the 3d chart. Simple, but useful! To be able to use an extention or function, it is necessary to determine the extensions available by making a simple call of the function determineAvailableExtensions(). Let's set this function aside for now, it will be useful to us in the future.

  Initialiser OpenGL returns in fact to choose a prospect and to define basic parameters. In our case, we will create a world in 3d, therefore we need prospect. How to make? First of all, selectionner is needed the matrix of projection:

GL.glMatrixMode(GL.GL_PROJECTION);
  This sets to zero before reinitializing.

GL.glLoadIdentity();
  Then one defines our prospect:

GLU.gluPerspective(45.0f, (float)mode.width/(float)mode.height, 1.0f, 150.0f);
  The first parameter is the angle of vision (it's up to you to find what's appropriate to you). The second represents the ratio width/height. It is important to convert the 2 values into floats before doing any calculations.  If not, the result will be off if the initial types are ints.  As for the two last values, it acts of the point of vision of nearest and most distant. Nothing will be drawn beyond these points.

  Note: Always put value 1.0 in vision angle as a minimum, if not you will see some artifact bugs graphic and other flutters. Also, unless your scene is not very heavy in polygons or unless your computer is a real workhorse, it is important to not put too high of values as a maximum in vision.
  To finish with our 3d calculation, we call matrix GL_MODEL_VIEW, which means that all proceeding 2D/3D calculations will be done in this matrix and not in our matrix of calculations (without what there would be no more 3d calculation and the result with the screen would be very odd!). Don't worry if this starter code is still fuzzy to you, just copy/paste the code for now and you will understand the lessons progressively. :)

  Now we get to the basic parameters from OpenGL. For the moment, only one parameter is necessary, the others do not interest us in this lesson:

GL.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
  Very explicit, this method makes it possible to change the color owing to lack of OpenGL (the color which will be placed in the place of quickly, in other words places not having any polygon).

  To complete the initialization of OpenGL, one will use the GLCaps class previously created to check the presence of the WGL_EXT_swap_control extension.. What is it used for? To activate or deactivate the vSync. Hmm... And what is it? The vSync makes it possible to adapt the number of frames drawn per second with the refresh rate of the screen. For example, with a refresh rate of 60Hz and the activated vSync, your framerate will reach a maximum of approximately 60 frames/second.

  Note: activate/dactivate vSync is not possible under Windows, this is why it is important to test the presence of the extension before using it.  Without doing that the program would crash under linux (for example).
  OpenGL is now initialized and our window too. What remains to be done? To draw of course! The drawing in question is made through loop, or hand loop... Do you remember our function main_loop() in the constructor of our class? Here:

public void main_loop()
{
  while(!Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)
     && !Window.isCloseRequested())
  {
     if(!Window.isMinimized())
     {
          // Check keyboard input
        process_keyboard();
          // Render opengl scene
        render();
          // Update window graphics
        Window.update();
          // Swap Opengl Buffers
        Window.paint();
     }
  }
}
  Some explanations are needed. First, the loop is a while loop which will continue as long as ESCAPE has not been pressed or that the window has not been closed. Good, nothing complicated. Thus, if the window is not minimized, one gets the keyboard events (process_keyboard), one calculates a frame of the scene(render), one refreshes the window (Window.update()) and one draws the screen (Window.paint()). Isn't this simple? Especially that some is the program, this method will generally arise in this form. There's nothing left to do but examine 3 methods. Let us start with keyboard management:
 
public void process_keyboard()
{
  Keyboard.poll();

    // Toggle fullscreen/windowed mode
  if(Keyboard.isKeyDown(Keyboard.KEY_F1))
  {
     try
     {
             // Destroy the keyboard
        Keyboard.destroy();
          // Destroy GL window instance
        Window.destroy();

        if(fullscreen)
        {             Display.resetDisplayMode();
           Window.create("Lwjgl Test", 50, 50, mode.width, mode.height,
                         mode.bpp, 0, 8, 0);
           fullscreen = false;
        }
        else
        {
           Display.setDisplayMode(mode);
           Window.create("Lwjgl Test", mode.bpp, 0, 8, 0);
           fullscreen = true;
        }

       
          // Re-init OpenGL
        init_gl();
          // Re-Create the keyboard
        Keyboard.create();
     }
     catch(Exception e)
     {
        e.printStackTrace();
     }
  }
}
  First thing done, Keyboard.poll()! This function makes it possible "to turn over" the keyboard, and thus to recover the events which interest us. To test if a key was pressed, the same action is always performed:
 
if(Keyboard.isKeyDown(Keyboard.KEY_F1))
{
  ...
}
  You will find the identifier of each key of the keyboard in the official documentation of LWJGL. The code which follows allows the  switching between the full screen and windowed modes. Not need to explain it to you, I think that the code is easily comprehended... Let us speak about our function of returned, that where all left it drawings will occur:

public void render()
{
  GL.glClear(GL.GL_COLOR_BUFFER_BIT);
  GL.glLoadIdentity();
}
  Indeed, it is very short! It is normal, since nothing in this tutorial is drawn... Nevertheless, there are 2 important functions. The first makes it possible to erase the preset buffers (GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT, GL_ACCUM_BUFFER_BIT), which is of primary importance, if not the drawing of the following image will be done over the current image without erasing it! Thus there will be a rather unpleasant superposition effect and which will quickly make the scene unrecognizable. For the moment, only the buffer of color is unobtrusive because the others are not used. It will come... It is then necessary to set to zero the principal matrix (GL_MODELVIEW) while calling GL.glLoadIdentity(), without that the future transformations will be completely distorted. Here is for our return function (very empty, it should be acknowledged...)! The last method is the method cleanup(), which allows in fact to empty the mask and the memory used by OpenGL when the user wishes to leave the application.
 
public final void cleanup()
{
  Keyboard.destroy();
  Window.destroy();
}
Once again very explicit:) One is satisfied to destroy the keyboard THEN the window... To finish up this tutorial, it is of course necessary to have a main function as shown here:

public static void main(String args[])
{
  Lwjgl01 f = new Lwjgl01();
}

There's nothing to explain except to initialize the instance of the application. Nothing else! If you still do not understand this tutorial, keep learning and you will learn gradually as you go (that's how I learned)... And if you have questions or any other problems, you can contact me:)
ife sucks, kill yourself.

Morgrog

gah, sorry I didn't have time to translate your stuff chman but it looks like my good intentions can be replaced by a very small web app ;)

Keep up the good work guys!

EricTheRed

[Erm, hello. I've lurked for quite a while, but mention of translation dragged me out of my little hidey-hole. Though I'll probably go back again.]

Would anybody be interested if I translated some of the remaining tutorials by hand? While Babel Fish does a decent job, it still leaves something to be desired. Though my French isn't necessarily perfect*, I still think I could write a good tutorial translation. I won't go ahead, however, unless there's some genuine interest from the community. So, anybody?

- Eric

* Neither is my English, for that matter, despite speaking it all my life...

PlanetMongo

Go for it man.  :)  I know zero about french, except for baguette's, which are tasty.  :P  Babelfish will make you pull out your hair when trying to make something make sense, and you can see I left most of the babelized sentence structures intact.  Wow, it's pretty clumsy, but it's manageable.
ife sucks, kill yourself.

PlanetMongo

Just a heads up, chman posted english translations (courtesy babelfish) for his tutorials on his site... I tried my best to clean it up, but you know.. I'm still new at this whole 3D thing and may have gotten a few things wrong.  However, I must say that I think I learned quite a bit more about OpenGL by doing this instead of sitting around reading them.. Not to mention HTML (I actually hand-edited the source.. yikes..)
ife sucks, kill yourself.

EricTheRed

That being said, however, I'm still working away at creating "real" translations for all the tutorials. I'm not a trained translator by any stretch of the imagination, so it takes me quite a bit of time to translate and edit everything. Also vying for time is this so-called "school", so things are progressing slower than I'd anticipated. Regardless, I hope to have all the "proper" translations up by the end of October at the very latest. So, now you'll have an acompanying first to my translation of the second tutorial :P.

- Eric